<commit_before>// Copyright 2016 Intel Corporation. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "xwalk/runtime/browser/xwalk_content_settings.h"

#include <string>

#include "base/base_paths.h"
#include "base/files/file_util.h"
#include "base/path_service.h"
#include "base/prefs/pref_filter.h"
#include "base/prefs/pref_service_factory.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "content/public/browser/browser_thread.h"
#include "url/gurl.h"
#include "xwalk/runtime/common/xwalk_paths.h"

namespace xwalk {

// static
XWalkContentSettings* XWalkContentSettings::GetInstance() {
  return Singleton<XWalkContentSettings>::get();
}

base::FilePath XWalkContentSettings::GetPrefFilePathFromPath(
    const base::FilePath& path) {
  return path.Append(FILE_PATH_LITERAL("Preferences"));
}

XWalkContentSettings::XWalkContentSettings() {
}

XWalkContentSettings::~XWalkContentSettings() {
}

void XWalkContentSettings::Init() {
  // This line is needed so content-settings works as it should. I even
  // found that line in the tests.
  ContentSettingsPattern::SetNonWildcardDomainNonPortScheme("chrome-extension");
  base::FilePath xwalk_data_dir;
  CHECK(PathService::Get(xwalk::DIR_DATA_PATH, &xwalk_data_dir));
  sequenced_task_runner_ = JsonPrefStore::GetTaskRunnerForFile(
      xwalk_data_dir, content::BrowserThread::GetBlockingPool());

  pref_store_ = new JsonPrefStore(GetPrefFilePathFromPath(xwalk_data_dir),
      sequenced_task_runner_.get(),
      scoped_ptr<PrefFilter>());

  // The name is misleading, we do not sync anything.
  pref_registry_ = new user_prefs::PrefRegistrySyncable();
  base::PrefServiceFactory pref_service_factory;
  pref_service_factory.set_user_prefs(pref_store_);

  pref_service_ = pref_service_factory.Create(pref_registry_.get());

  HostContentSettingsMap::RegisterProfilePrefs(pref_registry_.get());
  host_content_settings_map_ =
      new HostContentSettingsMap(pref_service_.get(), false);<commit_msg>[Linux][Windows] Save permissions for applications launched with the manifest.<commit_after>// Copyright 2016 Intel Corporation. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "xwalk/runtime/browser/xwalk_content_settings.h"

#include <string>

#include "base/base_paths.h"
#include "base/files/file_util.h"
#include "base/path_service.h"
#include "base/prefs/pref_filter.h"
#include "base/prefs/pref_service_factory.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "content/public/browser/browser_thread.h"
#include "url/gurl.h"
#include "xwalk/runtime/common/xwalk_paths.h"

namespace xwalk {

// static
XWalkContentSettings* XWalkContentSettings::GetInstance() {
  return Singleton<XWalkContentSettings>::get();
}

base::FilePath XWalkContentSettings::GetPrefFilePathFromPath(
    const base::FilePath& path) {
  return path.Append(FILE_PATH_LITERAL("Preferences"));
}

XWalkContentSettings::XWalkContentSettings() {
}

XWalkContentSettings::~XWalkContentSettings() {
}

void XWalkContentSettings::Init() {
  ContentSettingsPattern::SetNonWildcardDomainNonPortScheme("app");
  base::FilePath xwalk_data_dir;
  CHECK(PathService::Get(xwalk::DIR_DATA_PATH, &xwalk_data_dir));
  sequenced_task_runner_ = JsonPrefStore::GetTaskRunnerForFile(
      xwalk_data_dir, content::BrowserThread::GetBlockingPool());

  pref_store_ = new JsonPrefStore(GetPrefFilePathFromPath(xwalk_data_dir),
      sequenced_task_runner_.get(),
      scoped_ptr<PrefFilter>());

  // The name is misleading, we do not sync anything.
  pref_registry_ = new user_prefs::PrefRegistrySyncable();
  base::PrefServiceFactory pref_service_factory;
  pref_service_factory.set_user_prefs(pref_store_);

  pref_service_ = pref_service_factory.Create(pref_registry_.get());

  HostContentSettingsMap::RegisterProfilePrefs(pref_registry_.get());
  host_content_settings_map_ =
      new HostContentSettingsMap(pref_service_.get(), false);
{'fraction_non_alphanumeric': 0.11105663152733514, 'fraction_numerical': 0.001961265015935278, 'mean_word_length': 6.756653992395437, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6803461', 'n_tokens_mistral': 1272, 'n_tokens_neox': 1255, 'n_words': 231}