From e54ff59b455df03c48e088850a43447b781930aa Mon Sep 17 00:00:00 2001 From: derekjchow Date: Tue, 5 Jan 2016 17:05:50 -0800 Subject: Revert "[Chromecast] Move PrefServiceHelper to chromecast/base." This reverts commit c40e4d77214c8506a36c7c6974099f1181004fdd. Revert "[Chromecast] Add //base:prefs as dependency of //chromecast/base" This reverts commit 5ef2431f4ead49f0d34f3b6b1ddb35c559daa6f8. BUG= Review URL: https://codereview.chromium.org/1564593002 Cr-Commit-Position: refs/heads/master@{#367733} --- chromecast/base/BUILD.gn | 7 -- chromecast/base/pref_service_helper.cc | 85 ------------------------ chromecast/base/pref_service_helper.h | 40 ----------- chromecast/base/pref_service_helper_simple.cc | 13 ---- chromecast/browser/BUILD.gn | 3 + chromecast/browser/cast_browser_main_parts.cc | 5 +- chromecast/browser/pref_service_helper.cc | 84 +++++++++++++++++++++++ chromecast/browser/pref_service_helper.h | 43 ++++++++++++ chromecast/browser/pref_service_helper_simple.cc | 17 +++++ chromecast/chromecast.gyp | 10 +-- 10 files changed, 152 insertions(+), 155 deletions(-) delete mode 100644 chromecast/base/pref_service_helper.cc delete mode 100644 chromecast/base/pref_service_helper.h delete mode 100644 chromecast/base/pref_service_helper_simple.cc create mode 100644 chromecast/browser/pref_service_helper.cc create mode 100644 chromecast/browser/pref_service_helper.h create mode 100644 chromecast/browser/pref_service_helper_simple.cc (limited to 'chromecast') diff --git a/chromecast/base/BUILD.gn b/chromecast/base/BUILD.gn index c56cebe..81c20ff 100644 --- a/chromecast/base/BUILD.gn +++ b/chromecast/base/BUILD.gn @@ -29,8 +29,6 @@ source_set("base") { "path_utils.h", "pref_names.cc", "pref_names.h", - "pref_service_helper.cc", - "pref_service_helper.h", "process_utils.cc", "process_utils.h", "serializers.cc", @@ -41,10 +39,6 @@ source_set("base") { "task_runner_impl.h", ] - if (chromecast_branding == "public") { - sources += [ "pref_service_helper_simple.cc" ] - } - public_deps = [ "//chromecast/base/metrics", "//chromecast/public", @@ -52,7 +46,6 @@ source_set("base") { deps = [ "//base", - "//base:prefs", ] } diff --git a/chromecast/base/pref_service_helper.cc b/chromecast/base/pref_service_helper.cc deleted file mode 100644 index ea5fbfc..0000000 --- a/chromecast/base/pref_service_helper.cc +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chromecast/base/pref_service_helper.h" - -#include - -#include "base/files/file_path.h" -#include "base/files/file_util.h" -#include "base/logging.h" -#include "base/memory/ref_counted.h" -#include "base/path_service.h" -#include "base/prefs/json_pref_store.h" -#include "base/prefs/pref_registry_simple.h" -#include "base/prefs/pref_service_factory.h" -#include "base/prefs/pref_store.h" -#include "base/threading/sequenced_worker_pool.h" -#include "chromecast/base/cast_paths.h" -#include "chromecast/base/pref_names.h" - -namespace chromecast { - -namespace { - -void UserPrefsLoadError(PersistentPrefStore::PrefReadError* error_val, - PersistentPrefStore::PrefReadError error) { - DCHECK(error_val); - *error_val = error; -} - -base::FilePath GetConfigPath() { - base::FilePath config_path; - CHECK(PathService::Get(FILE_CAST_CONFIG, &config_path)); - return config_path; -} - -} // namespace - -// static -scoped_ptr PrefServiceHelper::CreatePrefService( - PrefRegistrySimple* registry, - base::SequencedWorkerPool* worker_pool) { - DCHECK(registry); - DCHECK(worker_pool); - - const base::FilePath config_path(GetConfigPath()); - VLOG(1) << "Loading config from " << config_path.value(); - - registry->RegisterBooleanPref(prefs::kEnableRemoteDebugging, false); - registry->RegisterBooleanPref(prefs::kMetricsIsNewClientID, false); - // Opt-in stats default to true to handle two different cases: - // 1) Any crashes or UMA logs are recorded prior to setup completing - // successfully (even though we can't send them yet). Unless the user - // ends up actually opting out, we don't want to lose this data once - // we get network connectivity and are able to send it. If the user - // opts out, nothing further will be sent (honoring the user's setting). - // 2) Dogfood users (see dogfood agreement). - registry->RegisterBooleanPref(prefs::kOptInStats, true); - - RegisterPlatformPrefs(registry); - - base::PrefServiceFactory prefServiceFactory; - scoped_refptr task_runner = - JsonPrefStore::GetTaskRunnerForFile(config_path, worker_pool); - prefServiceFactory.SetUserPrefsFile(config_path, task_runner.get()); - prefServiceFactory.set_async(false); - - PersistentPrefStore::PrefReadError prefs_read_error = - PersistentPrefStore::PREF_READ_ERROR_NONE; - prefServiceFactory.set_read_error_callback( - base::Bind(&UserPrefsLoadError, &prefs_read_error)); - - scoped_ptr pref_service(prefServiceFactory.Create(registry)); - if (prefs_read_error != PersistentPrefStore::PREF_READ_ERROR_NONE) { - LOG(ERROR) << "Cannot initialize chromecast config: " - << config_path.value() - << ", pref_error=" << prefs_read_error; - } - - OnPrefsLoaded(pref_service.get()); - return pref_service; -} - -} // namespace chromecast diff --git a/chromecast/base/pref_service_helper.h b/chromecast/base/pref_service_helper.h deleted file mode 100644 index 03c4f48..0000000 --- a/chromecast/base/pref_service_helper.h +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// -// Helper to initialize PrefService for cast shell. - -#ifndef CHROMECAST_BASE_PREF_SERVICE_HELPER_H_ -#define CHROMECAST_BASE_PREF_SERVICE_HELPER_H_ - -#include "base/memory/scoped_ptr.h" -#include "base/prefs/pref_service.h" - -class PrefRegistrySimple; - -namespace base { -class SequencedWorkerPool; -} // namespace base - -namespace chromecast { - -// It uses JsonPrefStore internally and/so the format of config file is same to -// that of JsonPrefStore. -class PrefServiceHelper { - public: - // Loads configs from config file. Returns true if successful. - static scoped_ptr CreatePrefService( - PrefRegistrySimple* registry, - base::SequencedWorkerPool* worker_pool); - - private: - // Registers any needed preferences for the current platform. - static void RegisterPlatformPrefs(PrefRegistrySimple* registry); - - // Called after the pref file has been loaded. - static void OnPrefsLoaded(PrefService* pref_service); -}; - -} // namespace chromecast - -#endif // CHROMECAST_BASE_PREF_SERVICE_HELPER_H_ diff --git a/chromecast/base/pref_service_helper_simple.cc b/chromecast/base/pref_service_helper_simple.cc deleted file mode 100644 index f5a495c..0000000 --- a/chromecast/base/pref_service_helper_simple.cc +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chromecast/base/pref_service_helper.h" - -namespace chromecast { - -void PrefServiceHelper::RegisterPlatformPrefs(PrefRegistrySimple* registry) {} - -void PrefServiceHelper::OnPrefsLoaded(PrefService* pref_service) {} - -} // namespace chromecast diff --git a/chromecast/browser/BUILD.gn b/chromecast/browser/BUILD.gn index 3f144d3..a38dab1 100644 --- a/chromecast/browser/BUILD.gn +++ b/chromecast/browser/BUILD.gn @@ -44,6 +44,8 @@ source_set("browser") { "metrics/cast_metrics_service_client.h", "metrics/cast_stability_metrics_provider.cc", "metrics/cast_stability_metrics_provider.h", + "pref_service_helper.cc", + "pref_service_helper.h", "service/cast_service_simple.cc", "service/cast_service_simple.h", "url_request_context_factory.cc", @@ -54,6 +56,7 @@ source_set("browser") { sources += [ "cast_content_browser_client_simple.cc", "cast_network_delegate_simple.cc", + "pref_service_helper_simple.cc", ] } diff --git a/chromecast/browser/cast_browser_main_parts.cc b/chromecast/browser/cast_browser_main_parts.cc index e03542e..a703723 100644 --- a/chromecast/browser/cast_browser_main_parts.cc +++ b/chromecast/browser/cast_browser_main_parts.cc @@ -24,7 +24,6 @@ #include "chromecast/base/chromecast_switches.h" #include "chromecast/base/metrics/cast_metrics_helper.h" #include "chromecast/base/metrics/grouped_histogram.h" -#include "chromecast/base/pref_service_helper.h" #include "chromecast/browser/cast_browser_context.h" #include "chromecast/browser/cast_browser_process.h" #include "chromecast/browser/cast_content_browser_client.h" @@ -32,6 +31,7 @@ #include "chromecast/browser/devtools/remote_debugging_server.h" #include "chromecast/browser/metrics/cast_metrics_prefs.h" #include "chromecast/browser/metrics/cast_metrics_service_client.h" +#include "chromecast/browser/pref_service_helper.h" #include "chromecast/browser/url_request_context_factory.h" #include "chromecast/common/platform_client_auth.h" #include "chromecast/media/base/key_systems_common.h" @@ -342,8 +342,7 @@ void CastBrowserMainParts::PreMainMessageLoopRun() { scoped_refptr pref_registry(new PrefRegistrySimple()); metrics::RegisterPrefs(pref_registry.get()); cast_browser_process_->SetPrefService( - PrefServiceHelper::CreatePrefService( - pref_registry.get(), content::BrowserThread::GetBlockingPool())); + PrefServiceHelper::CreatePrefService(pref_registry.get())); const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); #if defined(OS_ANDROID) diff --git a/chromecast/browser/pref_service_helper.cc b/chromecast/browser/pref_service_helper.cc new file mode 100644 index 0000000..3265efb5 --- /dev/null +++ b/chromecast/browser/pref_service_helper.cc @@ -0,0 +1,84 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chromecast/browser/pref_service_helper.h" + +#include + +#include "base/files/file_path.h" +#include "base/files/file_util.h" +#include "base/logging.h" +#include "base/path_service.h" +#include "base/prefs/json_pref_store.h" +#include "base/prefs/pref_registry_simple.h" +#include "base/prefs/pref_service_factory.h" +#include "base/prefs/pref_store.h" +#include "chromecast/base/cast_paths.h" +#include "chromecast/base/pref_names.h" +#include "content/public/browser/browser_thread.h" + +namespace chromecast { +namespace shell { + +namespace { + +void UserPrefsLoadError(PersistentPrefStore::PrefReadError* error_val, + PersistentPrefStore::PrefReadError error) { + DCHECK(error_val); + *error_val = error; +} + +base::FilePath GetConfigPath() { + base::FilePath config_path; + CHECK(PathService::Get(FILE_CAST_CONFIG, &config_path)); + return config_path; +} + +} // namespace + +// static +scoped_ptr PrefServiceHelper::CreatePrefService( + PrefRegistrySimple* registry) { + const base::FilePath config_path(GetConfigPath()); + VLOG(1) << "Loading config from " << config_path.value(); + + registry->RegisterBooleanPref(prefs::kEnableRemoteDebugging, false); + registry->RegisterBooleanPref(prefs::kMetricsIsNewClientID, false); + // Opt-in stats default to true to handle two different cases: + // 1) Any crashes or UMA logs are recorded prior to setup completing + // successfully (even though we can't send them yet). Unless the user + // ends up actually opting out, we don't want to lose this data once + // we get network connectivity and are able to send it. If the user + // opts out, nothing further will be sent (honoring the user's setting). + // 2) Dogfood users (see dogfood agreement). + registry->RegisterBooleanPref(prefs::kOptInStats, true); + + RegisterPlatformPrefs(registry); + + base::PrefServiceFactory prefServiceFactory; + scoped_refptr task_runner = + JsonPrefStore::GetTaskRunnerForFile( + config_path, + content::BrowserThread::GetBlockingPool()); + prefServiceFactory.SetUserPrefsFile(config_path, task_runner.get()); + prefServiceFactory.set_async(false); + + PersistentPrefStore::PrefReadError prefs_read_error = + PersistentPrefStore::PREF_READ_ERROR_NONE; + prefServiceFactory.set_read_error_callback( + base::Bind(&UserPrefsLoadError, &prefs_read_error)); + + scoped_ptr pref_service(prefServiceFactory.Create(registry)); + if (prefs_read_error != PersistentPrefStore::PREF_READ_ERROR_NONE) { + LOG(ERROR) << "Cannot initialize chromecast config: " + << config_path.value() + << ", pref_error=" << prefs_read_error; + } + + OnPrefsLoaded(pref_service.get()); + return pref_service; +} + +} // namespace shell +} // namespace chromecast diff --git a/chromecast/browser/pref_service_helper.h b/chromecast/browser/pref_service_helper.h new file mode 100644 index 0000000..cf41a92 --- /dev/null +++ b/chromecast/browser/pref_service_helper.h @@ -0,0 +1,43 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// Helper to initialize PrefService for cast shell. + +#ifndef CHROMECAST_BROWSER_PREF_SERVICE_HELPER_H_ +#define CHROMECAST_BROWSER_PREF_SERVICE_HELPER_H_ + +#include + +#include "base/files/file_path.h" +#include "base/memory/ref_counted.h" +#include "base/memory/scoped_ptr.h" +#include "base/prefs/pref_service.h" +#include "base/threading/sequenced_worker_pool.h" +#include "base/threading/thread_checker.h" + +class PrefRegistrySimple; + +namespace chromecast { +namespace shell { + +// It uses JsonPrefStore internally and/so the format of config file is same to +// that of JsonPrefStore. +class PrefServiceHelper { + public: + // Loads configs from config file. Returns true if successful. + static scoped_ptr CreatePrefService( + PrefRegistrySimple* registry); + + private: + // Registers any needed preferences for the current platform. + static void RegisterPlatformPrefs(PrefRegistrySimple* registry); + + // Called after the pref file has been loaded. + static void OnPrefsLoaded(PrefService* pref_service); +}; + +} // namespace shell +} // namespace chromecast + +#endif // CHROMECAST_BROWSER_PREF_SERVICE_HELPER_H_ diff --git a/chromecast/browser/pref_service_helper_simple.cc b/chromecast/browser/pref_service_helper_simple.cc new file mode 100644 index 0000000..0357ca7 --- /dev/null +++ b/chromecast/browser/pref_service_helper_simple.cc @@ -0,0 +1,17 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chromecast/browser/pref_service_helper.h" + +namespace chromecast { +namespace shell { + +void PrefServiceHelper::RegisterPlatformPrefs(PrefRegistrySimple* registry) { +} + +void PrefServiceHelper::OnPrefsLoaded(PrefService* pref_service) { +} + +} // namespace shell +} // namespace chromecast diff --git a/chromecast/chromecast.gyp b/chromecast/chromecast.gyp index 41de474..3a6080e 100644 --- a/chromecast/chromecast.gyp +++ b/chromecast/chromecast.gyp @@ -110,8 +110,6 @@ 'base/path_utils.h', 'base/pref_names.cc', 'base/pref_names.h', - 'base/pref_service_helper.cc', - 'base/pref_service_helper.h', 'base/process_utils.cc', 'base/process_utils.h', 'base/scoped_temp_file.cc', @@ -124,11 +122,6 @@ 'base/task_runner_impl.h', ], 'conditions': [ - ['chromecast_branding=="public"', { - 'sources': [ - 'base/pref_service_helper_simple.cc', - ], - }], ['OS=="android"', { 'dependencies': [ 'cast_jni_headers', @@ -399,6 +392,8 @@ 'browser/metrics/cast_metrics_service_client.h', 'browser/metrics/cast_stability_metrics_provider.cc', 'browser/metrics/cast_stability_metrics_provider.h', + 'browser/pref_service_helper.cc', + 'browser/pref_service_helper.h', 'browser/service/cast_service_simple.cc', 'browser/service/cast_service_simple.h', 'browser/url_request_context_factory.cc', @@ -433,6 +428,7 @@ 'sources': [ 'browser/cast_content_browser_client_simple.cc', 'browser/cast_network_delegate_simple.cc', + 'browser/pref_service_helper_simple.cc', 'common/platform_client_auth_simple.cc', 'renderer/cast_content_renderer_client_simple.cc', ], -- cgit v1.1