Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: chrome/browser/prefs/chrome_pref_service_factory.cc

Issue 2745563005: Pref service: add support for tracked prefs. (Closed)
Patch Set: deflake tests Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <chrome/browser/prefs/chrome_command_line_pref_store.h> 5 #include <chrome/browser/prefs/chrome_command_line_pref_store.h>
6 #include "chrome/browser/prefs/chrome_pref_service_factory.h" 6 #include "chrome/browser/prefs/chrome_pref_service_factory.h"
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <string> 10 #include <string>
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 #include "components/search_engines/search_engines_pref_names.h" 51 #include "components/search_engines/search_engines_pref_names.h"
52 #include "components/signin/core/common/signin_pref_names.h" 52 #include "components/signin/core/common/signin_pref_names.h"
53 #include "components/sync/base/model_type.h" 53 #include "components/sync/base/model_type.h"
54 #include "components/sync/base/pref_names.h" 54 #include "components/sync/base/pref_names.h"
55 #include "components/sync_preferences/pref_model_associator.h" 55 #include "components/sync_preferences/pref_model_associator.h"
56 #include "components/sync_preferences/pref_service_syncable.h" 56 #include "components/sync_preferences/pref_service_syncable.h"
57 #include "components/sync_preferences/pref_service_syncable_factory.h" 57 #include "components/sync_preferences/pref_service_syncable_factory.h"
58 #include "content/public/browser/browser_context.h" 58 #include "content/public/browser/browser_context.h"
59 #include "content/public/browser/browser_thread.h" 59 #include "content/public/browser/browser_thread.h"
60 #include "extensions/features/features.h" 60 #include "extensions/features/features.h"
61 #include "mojo/public/cpp/bindings/strong_binding.h"
61 #include "rlz/features/features.h" 62 #include "rlz/features/features.h"
62 #include "services/preferences/public/cpp/tracked/configuration.h" 63 #include "services/preferences/public/cpp/tracked/configuration.h"
63 #include "services/preferences/public/cpp/tracked/pref_names.h" 64 #include "services/preferences/public/cpp/tracked/pref_names.h"
64 #include "sql/error_delegate_util.h" 65 #include "sql/error_delegate_util.h"
65 #include "ui/base/resource/resource_bundle.h" 66 #include "ui/base/resource/resource_bundle.h"
66 67
67 #if BUILDFLAG(ENABLE_EXTENSIONS) 68 #if BUILDFLAG(ENABLE_EXTENSIONS)
68 #include "extensions/browser/pref_names.h" 69 #include "extensions/browser/pref_names.h"
69 #endif 70 #endif
70 71
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 rlz_lib::GetMachineId(&legacy_device_id); 350 rlz_lib::GetMachineId(&legacy_device_id);
350 351
351 UMA_HISTOGRAM_BOOLEAN("Settings.LegacyMachineIdGenerationSuccess", 352 UMA_HISTOGRAM_BOOLEAN("Settings.LegacyMachineIdGenerationSuccess",
352 !legacy_device_id.empty()); 353 !legacy_device_id.empty());
353 #endif 354 #endif
354 std::string seed; 355 std::string seed;
355 #if defined(GOOGLE_CHROME_BUILD) 356 #if defined(GOOGLE_CHROME_BUILD)
356 seed = ResourceBundle::GetSharedInstance().GetRawDataResource( 357 seed = ResourceBundle::GetSharedInstance().GetRawDataResource(
357 IDR_PREF_HASH_SEED_BIN).as_string(); 358 IDR_PREF_HASH_SEED_BIN).as_string();
358 #endif 359 #endif
359 return base::MakeUnique<ProfilePrefStoreManager>( 360 return base::MakeUnique<ProfilePrefStoreManager>(profile_path, seed,
360 profile_path, GetTrackingConfiguration(), kTrackedPrefsReportingIDsCount, 361 legacy_device_id);
361 seed, legacy_device_id, g_browser_process->local_state());
362 } 362 }
363 363
364 void PrepareFactory(sync_preferences::PrefServiceSyncableFactory* factory, 364 void PrepareFactory(sync_preferences::PrefServiceSyncableFactory* factory,
365 const base::FilePath& pref_filename, 365 const base::FilePath& pref_filename,
366 policy::PolicyService* policy_service, 366 policy::PolicyService* policy_service,
367 SupervisedUserSettingsService* supervised_user_settings, 367 SupervisedUserSettingsService* supervised_user_settings,
368 scoped_refptr<PersistentPrefStore> user_pref_store, 368 scoped_refptr<PersistentPrefStore> user_pref_store,
369 const scoped_refptr<PrefStore>& extension_prefs, 369 const scoped_refptr<PrefStore>& extension_prefs,
370 bool async) { 370 bool async) {
371 policy::BrowserPolicyConnector* policy_connector = 371 policy::BrowserPolicyConnector* policy_connector =
(...skipping 13 matching lines...) Expand all
385 factory->set_async(async); 385 factory->set_async(async);
386 factory->set_extension_prefs(extension_prefs); 386 factory->set_extension_prefs(extension_prefs);
387 factory->set_command_line_prefs(make_scoped_refptr( 387 factory->set_command_line_prefs(make_scoped_refptr(
388 new ChromeCommandLinePrefStore(base::CommandLine::ForCurrentProcess()))); 388 new ChromeCommandLinePrefStore(base::CommandLine::ForCurrentProcess())));
389 factory->set_read_error_callback(base::Bind(&HandleReadError, pref_filename)); 389 factory->set_read_error_callback(base::Bind(&HandleReadError, pref_filename));
390 factory->set_user_prefs(user_pref_store); 390 factory->set_user_prefs(user_pref_store);
391 factory->SetPrefModelAssociatorClient( 391 factory->SetPrefModelAssociatorClient(
392 ChromePrefModelAssociatorClient::GetInstance()); 392 ChromePrefModelAssociatorClient::GetInstance());
393 } 393 }
394 394
395 class ResetOnLoadObserverImpl : public prefs::mojom::ResetOnLoadObserver {
396 public:
397 explicit ResetOnLoadObserverImpl(const base::FilePath& profile_path)
398 : profile_path_(profile_path) {}
399
400 void OnResetOnLoad() override {
401 // A StartSyncFlare used to kick sync early in case of a reset event. This
402 // is done since sync may bring back the user's server value post-reset
403 // which could potentially cause a "settings flash" between the factory
404 // default and the re-instantiated server value. Starting sync ASAP
405 // minimizes the window before the server value is re-instantiated (this
406 // window can otherwise be as long as 10 seconds by default).
407 sync_start_util::GetFlareForSyncableService(profile_path_)
408 .Run(syncer::PREFERENCES);
409 }
410
411 private:
412 const base::FilePath profile_path_;
413
414 DISALLOW_COPY_AND_ASSIGN(ResetOnLoadObserverImpl);
415 };
416
395 } // namespace 417 } // namespace
396 418
397 namespace chrome_prefs { 419 namespace chrome_prefs {
398 420
399 namespace internals { 421 namespace internals {
400 422
401 // Group modifications should be reflected in first_run_browsertest.cc and 423 // Group modifications should be reflected in first_run_browsertest.cc and
402 // pref_hash_browsertest.cc. 424 // pref_hash_browsertest.cc.
403 const char kSettingsEnforcementTrialName[] = "SettingsEnforcement"; 425 const char kSettingsEnforcementTrialName[] = "SettingsEnforcement";
404 const char kSettingsEnforcementGroupNoEnforcement[] = "no_enforcement"; 426 const char kSettingsEnforcementGroupNoEnforcement[] = "no_enforcement";
(...skipping 16 matching lines...) Expand all
421 NULL, // supervised_user_settings 443 NULL, // supervised_user_settings
422 new JsonPrefStore(pref_filename, pref_io_task_runner, 444 new JsonPrefStore(pref_filename, pref_io_task_runner,
423 std::unique_ptr<PrefFilter>()), 445 std::unique_ptr<PrefFilter>()),
424 NULL, // extension_prefs 446 NULL, // extension_prefs
425 async); 447 async);
426 return factory.Create(pref_registry.get()); 448 return factory.Create(pref_registry.get());
427 } 449 }
428 450
429 std::unique_ptr<sync_preferences::PrefServiceSyncable> CreateProfilePrefs( 451 std::unique_ptr<sync_preferences::PrefServiceSyncable> CreateProfilePrefs(
430 const base::FilePath& profile_path, 452 const base::FilePath& profile_path,
431 base::SequencedTaskRunner* pref_io_task_runner, 453 prefs::mojom::TrackedPreferenceValidationDelegatePtr validation_delegate,
432 prefs::mojom::TrackedPreferenceValidationDelegate* validation_delegate,
433 policy::PolicyService* policy_service, 454 policy::PolicyService* policy_service,
434 SupervisedUserSettingsService* supervised_user_settings, 455 SupervisedUserSettingsService* supervised_user_settings,
435 const scoped_refptr<PrefStore>& extension_prefs, 456 const scoped_refptr<PrefStore>& extension_prefs,
436 const scoped_refptr<user_prefs::PrefRegistrySyncable>& pref_registry, 457 const scoped_refptr<user_prefs::PrefRegistrySyncable>& pref_registry,
437 bool async, 458 bool async,
438 service_manager::Connector* connector) { 459 service_manager::Connector* connector) {
439 TRACE_EVENT0("browser", "chrome_prefs::CreateProfilePrefs"); 460 TRACE_EVENT0("browser", "chrome_prefs::CreateProfilePrefs");
440 SCOPED_UMA_HISTOGRAM_TIMER("PrefService.CreateProfilePrefsTime"); 461 SCOPED_UMA_HISTOGRAM_TIMER("PrefService.CreateProfilePrefsTime");
441 462
442 // A StartSyncFlare used to kick sync early in case of a reset event. This is 463 prefs::mojom::ResetOnLoadObserverPtr reset_on_load_observer;
443 // done since sync may bring back the user's server value post-reset which 464 mojo::MakeStrongBinding(
444 // could potentially cause a "settings flash" between the factory default and 465 base::MakeUnique<ResetOnLoadObserverImpl>(profile_path),
445 // the re-instantiated server value. Starting sync ASAP minimizes the window 466 mojo::MakeRequest(&reset_on_load_observer));
446 // before the server value is re-instantiated (this window can otherwise be
447 // as long as 10 seconds by default).
448 const base::Closure start_sync_flare_for_prefs =
449 base::Bind(sync_start_util::GetFlareForSyncableService(profile_path),
450 syncer::PREFERENCES);
451
452 sync_preferences::PrefServiceSyncableFactory factory; 467 sync_preferences::PrefServiceSyncableFactory factory;
453 scoped_refptr<PersistentPrefStore> user_pref_store( 468 scoped_refptr<PersistentPrefStore> user_pref_store(
454 CreateProfilePrefStoreManager(profile_path) 469 CreateProfilePrefStoreManager(profile_path)
455 ->CreateProfilePrefStore( 470 ->CreateProfilePrefStore(
456 pref_io_task_runner, start_sync_flare_for_prefs, 471 GetTrackingConfiguration(), kTrackedPrefsReportingIDsCount,
457 validation_delegate, connector, pref_registry)); 472 content::BrowserThread::GetBlockingPool(),
473 std::move(reset_on_load_observer), std::move(validation_delegate),
474 connector, pref_registry));
458 PrepareFactory(&factory, profile_path, policy_service, 475 PrepareFactory(&factory, profile_path, policy_service,
459 supervised_user_settings, user_pref_store, extension_prefs, 476 supervised_user_settings, user_pref_store, extension_prefs,
460 async); 477 async);
461 std::unique_ptr<sync_preferences::PrefServiceSyncable> pref_service = 478 std::unique_ptr<sync_preferences::PrefServiceSyncable> pref_service =
462 factory.CreateSyncable(pref_registry.get(), connector); 479 factory.CreateSyncable(pref_registry.get(), connector);
463 480
464 return pref_service; 481 return pref_service;
465 } 482 }
466 483
467 void DisableDomainCheckForTesting() { 484 void DisableDomainCheckForTesting() {
468 #if defined(OS_WIN) 485 #if defined(OS_WIN)
469 g_disable_domain_check_for_testing = true; 486 g_disable_domain_check_for_testing = true;
470 #endif // OS_WIN 487 #endif // OS_WIN
471 } 488 }
472 489
473 bool InitializePrefsFromMasterPrefs( 490 bool InitializePrefsFromMasterPrefs(
474 const base::FilePath& profile_path, 491 const base::FilePath& profile_path,
475 std::unique_ptr<base::DictionaryValue> master_prefs) { 492 std::unique_ptr<base::DictionaryValue> master_prefs) {
476 return CreateProfilePrefStoreManager(profile_path) 493 return CreateProfilePrefStoreManager(profile_path)
477 ->InitializePrefsFromMasterPrefs(std::move(master_prefs)); 494 ->InitializePrefsFromMasterPrefs(GetTrackingConfiguration(),
495 kTrackedPrefsReportingIDsCount,
496 std::move(master_prefs));
478 } 497 }
479 498
480 base::Time GetResetTime(Profile* profile) { 499 base::Time GetResetTime(Profile* profile) {
481 return ProfilePrefStoreManager::GetResetTime(profile->GetPrefs()); 500 return ProfilePrefStoreManager::GetResetTime(profile->GetPrefs());
482 } 501 }
483 502
484 void ClearResetTime(Profile* profile) { 503 void ClearResetTime(Profile* profile) {
485 ProfilePrefStoreManager::ClearResetTime(profile->GetPrefs()); 504 ProfilePrefStoreManager::ClearResetTime(profile->GetPrefs());
486 } 505 }
487 506
488 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { 507 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
489 ProfilePrefStoreManager::RegisterProfilePrefs(registry); 508 ProfilePrefStoreManager::RegisterProfilePrefs(registry);
490 } 509 }
491 510
492 } // namespace chrome_prefs 511 } // namespace chrome_prefs
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698