OLD | NEW |
---|---|
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 Loading... | |
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 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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>( |
360 profile_path, GetTrackingConfiguration(), kTrackedPrefsReportingIDsCount, | 361 profile_path, GetTrackingConfiguration(), kTrackedPrefsReportingIDsCount, |
361 seed, legacy_device_id, g_browser_process->local_state()); | 362 seed, legacy_device_id); |
362 } | 363 } |
363 | 364 |
364 void PrepareFactory(sync_preferences::PrefServiceSyncableFactory* factory, | 365 void PrepareFactory(sync_preferences::PrefServiceSyncableFactory* factory, |
365 const base::FilePath& pref_filename, | 366 const base::FilePath& pref_filename, |
366 policy::PolicyService* policy_service, | 367 policy::PolicyService* policy_service, |
367 SupervisedUserSettingsService* supervised_user_settings, | 368 SupervisedUserSettingsService* supervised_user_settings, |
368 scoped_refptr<PersistentPrefStore> user_pref_store, | 369 scoped_refptr<PersistentPrefStore> user_pref_store, |
369 const scoped_refptr<PrefStore>& extension_prefs, | 370 const scoped_refptr<PrefStore>& extension_prefs, |
370 bool async) { | 371 bool async) { |
371 policy::BrowserPolicyConnector* policy_connector = | 372 policy::BrowserPolicyConnector* policy_connector = |
(...skipping 13 matching lines...) Expand all Loading... | |
385 factory->set_async(async); | 386 factory->set_async(async); |
386 factory->set_extension_prefs(extension_prefs); | 387 factory->set_extension_prefs(extension_prefs); |
387 factory->set_command_line_prefs(make_scoped_refptr( | 388 factory->set_command_line_prefs(make_scoped_refptr( |
388 new ChromeCommandLinePrefStore(base::CommandLine::ForCurrentProcess()))); | 389 new ChromeCommandLinePrefStore(base::CommandLine::ForCurrentProcess()))); |
389 factory->set_read_error_callback(base::Bind(&HandleReadError, pref_filename)); | 390 factory->set_read_error_callback(base::Bind(&HandleReadError, pref_filename)); |
390 factory->set_user_prefs(user_pref_store); | 391 factory->set_user_prefs(user_pref_store); |
391 factory->SetPrefModelAssociatorClient( | 392 factory->SetPrefModelAssociatorClient( |
392 ChromePrefModelAssociatorClient::GetInstance()); | 393 ChromePrefModelAssociatorClient::GetInstance()); |
393 } | 394 } |
394 | 395 |
396 class ResetOnLoadObserverImpl : public prefs::mojom::ResetOnLoadObserver { | |
397 public: | |
398 explicit ResetOnLoadObserverImpl(const base::FilePath& profile_path) | |
399 : profile_path_(profile_path) {} | |
400 | |
401 void OnResetOnLoad() override { | |
402 // A StartSyncFlare used to kick sync early in case of a reset event. This | |
403 // is done since sync may bring back the user's server value post-reset | |
404 // which could potentially cause a "settings flash" between the factory | |
405 // default and the re-instantiated server value. Starting sync ASAP | |
406 // minimizes the window before the server value is re-instantiated (this | |
407 // window can otherwise be as long as 10 seconds by default). | |
408 sync_start_util::GetFlareForSyncableService(profile_path_) | |
409 .Run(syncer::PREFERENCES); | |
410 } | |
411 | |
412 private: | |
413 const base::FilePath profile_path_; | |
414 | |
415 DISALLOW_COPY_AND_ASSIGN(ResetOnLoadObserverImpl); | |
416 }; | |
417 | |
395 } // namespace | 418 } // namespace |
396 | 419 |
397 namespace chrome_prefs { | 420 namespace chrome_prefs { |
398 | 421 |
399 namespace internals { | 422 namespace internals { |
400 | 423 |
401 // Group modifications should be reflected in first_run_browsertest.cc and | 424 // Group modifications should be reflected in first_run_browsertest.cc and |
402 // pref_hash_browsertest.cc. | 425 // pref_hash_browsertest.cc. |
403 const char kSettingsEnforcementTrialName[] = "SettingsEnforcement"; | 426 const char kSettingsEnforcementTrialName[] = "SettingsEnforcement"; |
404 const char kSettingsEnforcementGroupNoEnforcement[] = "no_enforcement"; | 427 const char kSettingsEnforcementGroupNoEnforcement[] = "no_enforcement"; |
(...skipping 16 matching lines...) Expand all Loading... | |
421 NULL, // supervised_user_settings | 444 NULL, // supervised_user_settings |
422 new JsonPrefStore(pref_filename, pref_io_task_runner, | 445 new JsonPrefStore(pref_filename, pref_io_task_runner, |
423 std::unique_ptr<PrefFilter>()), | 446 std::unique_ptr<PrefFilter>()), |
424 NULL, // extension_prefs | 447 NULL, // extension_prefs |
425 async); | 448 async); |
426 return factory.Create(pref_registry.get()); | 449 return factory.Create(pref_registry.get()); |
427 } | 450 } |
428 | 451 |
429 std::unique_ptr<sync_preferences::PrefServiceSyncable> CreateProfilePrefs( | 452 std::unique_ptr<sync_preferences::PrefServiceSyncable> CreateProfilePrefs( |
430 const base::FilePath& profile_path, | 453 const base::FilePath& profile_path, |
431 base::SequencedTaskRunner* pref_io_task_runner, | 454 prefs::mojom::TrackedPreferenceValidationDelegatePtr validation_delegate, |
432 prefs::mojom::TrackedPreferenceValidationDelegate* validation_delegate, | |
433 policy::PolicyService* policy_service, | 455 policy::PolicyService* policy_service, |
434 SupervisedUserSettingsService* supervised_user_settings, | 456 SupervisedUserSettingsService* supervised_user_settings, |
435 const scoped_refptr<PrefStore>& extension_prefs, | 457 const scoped_refptr<PrefStore>& extension_prefs, |
436 const scoped_refptr<user_prefs::PrefRegistrySyncable>& pref_registry, | 458 const scoped_refptr<user_prefs::PrefRegistrySyncable>& pref_registry, |
437 bool async, | 459 bool async, |
438 service_manager::Connector* connector) { | 460 service_manager::Connector* connector) { |
439 TRACE_EVENT0("browser", "chrome_prefs::CreateProfilePrefs"); | 461 TRACE_EVENT0("browser", "chrome_prefs::CreateProfilePrefs"); |
440 SCOPED_UMA_HISTOGRAM_TIMER("PrefService.CreateProfilePrefsTime"); | 462 SCOPED_UMA_HISTOGRAM_TIMER("PrefService.CreateProfilePrefsTime"); |
441 | 463 |
442 // A StartSyncFlare used to kick sync early in case of a reset event. This is | 464 prefs::mojom::ResetOnLoadObserverPtr reset_on_load_observer; |
443 // done since sync may bring back the user's server value post-reset which | 465 mojo::MakeStrongBinding( |
444 // could potentially cause a "settings flash" between the factory default and | 466 base::MakeUnique<ResetOnLoadObserverImpl>(profile_path), |
445 // the re-instantiated server value. Starting sync ASAP minimizes the window | 467 mojo::MakeRequest(&reset_on_load_observer)); |
gab
2017/04/03 16:11:17
General Mojo question (since I can't find document
Sam McNally
2017/04/04 03:24:49
There are docs for this now: https://chromium.goog
gab
2017/04/04 20:59:51
Awesome, thanks!
PS: Guess this is easy now as th
Sam McNally
2017/04/05 00:44:30
Probably something like how it was managed before:
| |
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; | 468 sync_preferences::PrefServiceSyncableFactory factory; |
453 scoped_refptr<PersistentPrefStore> user_pref_store( | 469 scoped_refptr<PersistentPrefStore> user_pref_store( |
454 CreateProfilePrefStoreManager(profile_path) | 470 CreateProfilePrefStoreManager(profile_path) |
455 ->CreateProfilePrefStore( | 471 ->CreateProfilePrefStore(content::BrowserThread::GetBlockingPool(), |
456 pref_io_task_runner, start_sync_flare_for_prefs, | 472 std::move(reset_on_load_observer), |
457 validation_delegate, connector, pref_registry)); | 473 std::move(validation_delegate), connector, |
474 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() { |
(...skipping 15 matching lines...) Expand all Loading... | |
483 | 500 |
484 void ClearResetTime(Profile* profile) { | 501 void ClearResetTime(Profile* profile) { |
485 ProfilePrefStoreManager::ClearResetTime(profile->GetPrefs()); | 502 ProfilePrefStoreManager::ClearResetTime(profile->GetPrefs()); |
486 } | 503 } |
487 | 504 |
488 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { | 505 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { |
489 ProfilePrefStoreManager::RegisterProfilePrefs(registry); | 506 ProfilePrefStoreManager::RegisterProfilePrefs(registry); |
490 } | 507 } |
491 | 508 |
492 } // namespace chrome_prefs | 509 } // namespace chrome_prefs |
OLD | NEW |