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" | |
62 #include "rlz/features/features.h" | 61 #include "rlz/features/features.h" |
63 #include "services/preferences/public/cpp/tracked/configuration.h" | 62 #include "services/preferences/public/cpp/tracked/configuration.h" |
64 #include "services/preferences/public/cpp/tracked/pref_names.h" | 63 #include "services/preferences/public/cpp/tracked/pref_names.h" |
65 #include "sql/error_delegate_util.h" | 64 #include "sql/error_delegate_util.h" |
66 #include "ui/base/resource/resource_bundle.h" | 65 #include "ui/base/resource/resource_bundle.h" |
67 | 66 |
68 #if BUILDFLAG(ENABLE_EXTENSIONS) | 67 #if BUILDFLAG(ENABLE_EXTENSIONS) |
69 #include "extensions/browser/pref_names.h" | 68 #include "extensions/browser/pref_names.h" |
70 #endif | 69 #endif |
71 | 70 |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 rlz_lib::GetMachineId(&legacy_device_id); | 349 rlz_lib::GetMachineId(&legacy_device_id); |
351 | 350 |
352 UMA_HISTOGRAM_BOOLEAN("Settings.LegacyMachineIdGenerationSuccess", | 351 UMA_HISTOGRAM_BOOLEAN("Settings.LegacyMachineIdGenerationSuccess", |
353 !legacy_device_id.empty()); | 352 !legacy_device_id.empty()); |
354 #endif | 353 #endif |
355 std::string seed; | 354 std::string seed; |
356 #if defined(GOOGLE_CHROME_BUILD) | 355 #if defined(GOOGLE_CHROME_BUILD) |
357 seed = ResourceBundle::GetSharedInstance().GetRawDataResource( | 356 seed = ResourceBundle::GetSharedInstance().GetRawDataResource( |
358 IDR_PREF_HASH_SEED_BIN).as_string(); | 357 IDR_PREF_HASH_SEED_BIN).as_string(); |
359 #endif | 358 #endif |
360 return base::MakeUnique<ProfilePrefStoreManager>(profile_path, seed, | 359 return base::MakeUnique<ProfilePrefStoreManager>( |
361 legacy_device_id); | 360 profile_path, GetTrackingConfiguration(), kTrackedPrefsReportingIDsCount, |
| 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 Loading... |
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 | |
417 } // namespace | 395 } // namespace |
418 | 396 |
419 namespace chrome_prefs { | 397 namespace chrome_prefs { |
420 | 398 |
421 namespace internals { | 399 namespace internals { |
422 | 400 |
423 // Group modifications should be reflected in first_run_browsertest.cc and | 401 // Group modifications should be reflected in first_run_browsertest.cc and |
424 // pref_hash_browsertest.cc. | 402 // pref_hash_browsertest.cc. |
425 const char kSettingsEnforcementTrialName[] = "SettingsEnforcement"; | 403 const char kSettingsEnforcementTrialName[] = "SettingsEnforcement"; |
426 const char kSettingsEnforcementGroupNoEnforcement[] = "no_enforcement"; | 404 const char kSettingsEnforcementGroupNoEnforcement[] = "no_enforcement"; |
(...skipping 16 matching lines...) Expand all Loading... |
443 NULL, // supervised_user_settings | 421 NULL, // supervised_user_settings |
444 new JsonPrefStore(pref_filename, pref_io_task_runner, | 422 new JsonPrefStore(pref_filename, pref_io_task_runner, |
445 std::unique_ptr<PrefFilter>()), | 423 std::unique_ptr<PrefFilter>()), |
446 NULL, // extension_prefs | 424 NULL, // extension_prefs |
447 async); | 425 async); |
448 return factory.Create(pref_registry.get()); | 426 return factory.Create(pref_registry.get()); |
449 } | 427 } |
450 | 428 |
451 std::unique_ptr<sync_preferences::PrefServiceSyncable> CreateProfilePrefs( | 429 std::unique_ptr<sync_preferences::PrefServiceSyncable> CreateProfilePrefs( |
452 const base::FilePath& profile_path, | 430 const base::FilePath& profile_path, |
453 prefs::mojom::TrackedPreferenceValidationDelegatePtr validation_delegate, | 431 base::SequencedTaskRunner* pref_io_task_runner, |
| 432 prefs::mojom::TrackedPreferenceValidationDelegate* validation_delegate, |
454 policy::PolicyService* policy_service, | 433 policy::PolicyService* policy_service, |
455 SupervisedUserSettingsService* supervised_user_settings, | 434 SupervisedUserSettingsService* supervised_user_settings, |
456 const scoped_refptr<PrefStore>& extension_prefs, | 435 const scoped_refptr<PrefStore>& extension_prefs, |
457 const scoped_refptr<user_prefs::PrefRegistrySyncable>& pref_registry, | 436 const scoped_refptr<user_prefs::PrefRegistrySyncable>& pref_registry, |
458 bool async, | 437 bool async, |
459 service_manager::Connector* connector) { | 438 service_manager::Connector* connector) { |
460 TRACE_EVENT0("browser", "chrome_prefs::CreateProfilePrefs"); | 439 TRACE_EVENT0("browser", "chrome_prefs::CreateProfilePrefs"); |
461 SCOPED_UMA_HISTOGRAM_TIMER("PrefService.CreateProfilePrefsTime"); | 440 SCOPED_UMA_HISTOGRAM_TIMER("PrefService.CreateProfilePrefsTime"); |
462 | 441 |
463 prefs::mojom::ResetOnLoadObserverPtr reset_on_load_observer; | 442 // A StartSyncFlare used to kick sync early in case of a reset event. This is |
464 mojo::MakeStrongBinding( | 443 // done since sync may bring back the user's server value post-reset which |
465 base::MakeUnique<ResetOnLoadObserverImpl>(profile_path), | 444 // could potentially cause a "settings flash" between the factory default and |
466 mojo::MakeRequest(&reset_on_load_observer)); | 445 // the re-instantiated server value. Starting sync ASAP minimizes the window |
| 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 |
467 sync_preferences::PrefServiceSyncableFactory factory; | 452 sync_preferences::PrefServiceSyncableFactory factory; |
468 scoped_refptr<PersistentPrefStore> user_pref_store( | 453 scoped_refptr<PersistentPrefStore> user_pref_store( |
469 CreateProfilePrefStoreManager(profile_path) | 454 CreateProfilePrefStoreManager(profile_path) |
470 ->CreateProfilePrefStore( | 455 ->CreateProfilePrefStore( |
471 GetTrackingConfiguration(), kTrackedPrefsReportingIDsCount, | 456 pref_io_task_runner, start_sync_flare_for_prefs, |
472 content::BrowserThread::GetBlockingPool(), | 457 validation_delegate, connector, pref_registry)); |
473 std::move(reset_on_load_observer), std::move(validation_delegate), | |
474 connector, pref_registry)); | |
475 PrepareFactory(&factory, profile_path, policy_service, | 458 PrepareFactory(&factory, profile_path, policy_service, |
476 supervised_user_settings, user_pref_store, extension_prefs, | 459 supervised_user_settings, user_pref_store, extension_prefs, |
477 async); | 460 async); |
478 std::unique_ptr<sync_preferences::PrefServiceSyncable> pref_service = | 461 std::unique_ptr<sync_preferences::PrefServiceSyncable> pref_service = |
479 factory.CreateSyncable(pref_registry.get(), connector); | 462 factory.CreateSyncable(pref_registry.get(), connector); |
480 | 463 |
481 return pref_service; | 464 return pref_service; |
482 } | 465 } |
483 | 466 |
484 void DisableDomainCheckForTesting() { | 467 void DisableDomainCheckForTesting() { |
485 #if defined(OS_WIN) | 468 #if defined(OS_WIN) |
486 g_disable_domain_check_for_testing = true; | 469 g_disable_domain_check_for_testing = true; |
487 #endif // OS_WIN | 470 #endif // OS_WIN |
488 } | 471 } |
489 | 472 |
490 bool InitializePrefsFromMasterPrefs( | 473 bool InitializePrefsFromMasterPrefs( |
491 const base::FilePath& profile_path, | 474 const base::FilePath& profile_path, |
492 std::unique_ptr<base::DictionaryValue> master_prefs) { | 475 std::unique_ptr<base::DictionaryValue> master_prefs) { |
493 return CreateProfilePrefStoreManager(profile_path) | 476 return CreateProfilePrefStoreManager(profile_path) |
494 ->InitializePrefsFromMasterPrefs(GetTrackingConfiguration(), | 477 ->InitializePrefsFromMasterPrefs(std::move(master_prefs)); |
495 kTrackedPrefsReportingIDsCount, | |
496 std::move(master_prefs)); | |
497 } | 478 } |
498 | 479 |
499 base::Time GetResetTime(Profile* profile) { | 480 base::Time GetResetTime(Profile* profile) { |
500 return ProfilePrefStoreManager::GetResetTime(profile->GetPrefs()); | 481 return ProfilePrefStoreManager::GetResetTime(profile->GetPrefs()); |
501 } | 482 } |
502 | 483 |
503 void ClearResetTime(Profile* profile) { | 484 void ClearResetTime(Profile* profile) { |
504 ProfilePrefStoreManager::ClearResetTime(profile->GetPrefs()); | 485 ProfilePrefStoreManager::ClearResetTime(profile->GetPrefs()); |
505 } | 486 } |
506 | 487 |
507 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { | 488 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { |
508 ProfilePrefStoreManager::RegisterProfilePrefs(registry); | 489 ProfilePrefStoreManager::RegisterProfilePrefs(registry); |
509 } | 490 } |
510 | 491 |
511 } // namespace chrome_prefs | 492 } // namespace chrome_prefs |
OLD | NEW |