Chromium Code Reviews| 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_pref_service_factory.h" | 5 #include "chrome/browser/prefs/chrome_pref_service_factory.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/debug/trace_event.h" | 12 #include "base/debug/trace_event.h" |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/metrics/field_trial.h" | 14 #include "base/metrics/field_trial.h" |
| 15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 16 #include "base/prefs/default_pref_store.h" | 16 #include "base/prefs/default_pref_store.h" |
| 17 #include "base/prefs/json_pref_store.h" | 17 #include "base/prefs/json_pref_store.h" |
| 18 #include "base/prefs/pref_filter.h" | 18 #include "base/prefs/pref_filter.h" |
| 19 #include "base/prefs/pref_notifier_impl.h" | 19 #include "base/prefs/pref_notifier_impl.h" |
| 20 #include "base/prefs/pref_registry.h" | 20 #include "base/prefs/pref_registry.h" |
| 21 #include "base/prefs/pref_registry_simple.h" | 21 #include "base/prefs/pref_registry_simple.h" |
| 22 #include "base/prefs/pref_service.h" | 22 #include "base/prefs/pref_service.h" |
| 23 #include "base/prefs/pref_store.h" | 23 #include "base/prefs/pref_store.h" |
| 24 #include "base/prefs/pref_value_store.h" | 24 #include "base/prefs/pref_value_store.h" |
| 25 #include "base/strings/string_util.h" | |
| 25 #include "base/threading/sequenced_worker_pool.h" | 26 #include "base/threading/sequenced_worker_pool.h" |
| 26 #include "base/time/time.h" | 27 #include "base/time/time.h" |
| 27 #include "chrome/browser/browser_process.h" | 28 #include "chrome/browser/browser_process.h" |
| 28 #include "chrome/browser/prefs/command_line_pref_store.h" | 29 #include "chrome/browser/prefs/command_line_pref_store.h" |
| 29 #include "chrome/browser/prefs/pref_hash_filter.h" | 30 #include "chrome/browser/prefs/pref_hash_filter.h" |
| 30 #include "chrome/browser/prefs/pref_model_associator.h" | 31 #include "chrome/browser/prefs/pref_model_associator.h" |
| 31 #include "chrome/browser/prefs/pref_service_syncable.h" | 32 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 32 #include "chrome/browser/prefs/pref_service_syncable_factory.h" | 33 #include "chrome/browser/prefs/pref_service_syncable_factory.h" |
| 33 #include "chrome/browser/prefs/profile_pref_store_manager.h" | 34 #include "chrome/browser/prefs/profile_pref_store_manager.h" |
| 34 #include "chrome/browser/profiles/file_path_verifier_win.h" | 35 #include "chrome/browser/profiles/file_path_verifier_win.h" |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 398 | 399 |
| 399 factory->set_async(async); | 400 factory->set_async(async); |
| 400 factory->set_extension_prefs(extension_prefs); | 401 factory->set_extension_prefs(extension_prefs); |
| 401 factory->set_command_line_prefs( | 402 factory->set_command_line_prefs( |
| 402 make_scoped_refptr( | 403 make_scoped_refptr( |
| 403 new CommandLinePrefStore(CommandLine::ForCurrentProcess()))); | 404 new CommandLinePrefStore(CommandLine::ForCurrentProcess()))); |
| 404 factory->set_read_error_callback(base::Bind(&HandleReadError)); | 405 factory->set_read_error_callback(base::Bind(&HandleReadError)); |
| 405 factory->set_user_prefs(user_pref_store); | 406 factory->set_user_prefs(user_pref_store); |
| 406 } | 407 } |
| 407 | 408 |
| 409 class BrowserUIPrefsMigrationObserver : public PrefStore::Observer { | |
|
gab
2014/09/08 21:29:25
I think this should live in its own file:
1) to a
gab
2014/09/08 21:29:25
Add a meta comment explaining the purpose of this
dgrogan
2014/09/09 03:15:43
Moved to its own file.
dgrogan
2014/09/09 03:15:43
Done.
| |
| 410 public: | |
| 411 explicit BrowserUIPrefsMigrationObserver( | |
| 412 scoped_refptr<PersistentPrefStore> pref_store) | |
| 413 : pref_store_(pref_store) {} | |
| 414 virtual void OnPrefValueChanged(const std::string& key) OVERRIDE {} | |
| 415 virtual void OnInitializationCompleted(bool succeeded) OVERRIDE; | |
| 416 private: | |
|
gab
2014/09/08 21:29:25
space above.
dgrogan
2014/09/09 03:15:43
Done.
| |
| 417 scoped_refptr<PersistentPrefStore> pref_store_; | |
| 418 }; | |
|
gab
2014/09/08 21:29:25
DISALLOW_COPY_AND_ASSIGN above.
dgrogan
2014/09/09 03:15:43
Done.
| |
| 419 | |
| 420 void BrowserUIPrefsMigrationObserver::OnInitializationCompleted( | |
| 421 bool succeeded) { | |
| 422 pref_store_->RemoveObserver(this); | |
| 423 scoped_ptr<BrowserUIPrefsMigrationObserver> self_deleter(this); | |
| 424 if (!succeeded) | |
| 425 return; | |
| 426 | |
| 427 base::Value* browser_value = NULL; | |
| 428 if (!pref_store_->GetMutableValue("browser", &browser_value)) { | |
| 429 return; | |
| 430 } | |
| 431 base::DictionaryValue* browser_dict = NULL; | |
| 432 if (!browser_value->GetAsDictionary(&browser_dict)) | |
| 433 return; | |
| 434 | |
| 435 // Don't bother scanning "browser" if the migration already occurred. | |
| 436 if (browser_dict->HasKey(prefs::kAppWindowPlacement)) | |
| 437 return; | |
| 438 | |
| 439 // Get a set of keys in the dictionary. This must be done separately from the | |
| 440 // migration because the migration modifies the dictionary being iterated. | |
| 441 std::set<std::string> keys_to_check; | |
| 442 for (base::DictionaryValue::Iterator it(*browser_dict); !it.IsAtEnd(); | |
| 443 it.Advance()) { | |
| 444 keys_to_check.insert(it.key()); | |
| 445 } | |
| 446 | |
| 447 scoped_ptr<base::DictionaryValue> app_window_placement; | |
|
gab
2014/09/08 21:29:25
Add a comment about how those pref used to look li
dgrogan
2014/09/09 03:15:43
Done.
| |
| 448 const std::string search_for = | |
| 449 std::string(prefs::kBrowserWindowPlacement) + "_"; | |
| 450 for (std::set<std::string>::const_iterator it = keys_to_check.begin(); | |
| 451 it != keys_to_check.end(); | |
| 452 ++it) { | |
| 453 std::string full_key("browser." + *it); | |
| 454 if (StartsWithASCII(full_key, search_for, true /* case_sensitive */)) { | |
| 455 if (full_key == prefs::kBrowserWindowPlacementPopup) | |
| 456 continue; | |
| 457 scoped_ptr<base::Value> single_app_placement_dict; | |
| 458 bool found = browser_dict->Remove(*it, &single_app_placement_dict); | |
| 459 DCHECK(found); | |
| 460 std::string new_key(full_key.substr(search_for.length())); | |
| 461 if (!app_window_placement) | |
| 462 app_window_placement.reset(new base::DictionaryValue); | |
| 463 app_window_placement->Set(new_key, single_app_placement_dict.release()); | |
| 464 } | |
| 465 } | |
| 466 if (app_window_placement) { | |
| 467 pref_store_->SetValue(prefs::kAppWindowPlacement, | |
| 468 app_window_placement.release()); | |
| 469 } | |
| 470 } | |
| 471 | |
| 408 } // namespace | 472 } // namespace |
| 409 | 473 |
| 410 namespace chrome_prefs { | 474 namespace chrome_prefs { |
| 411 | 475 |
| 412 namespace internals { | 476 namespace internals { |
| 413 | 477 |
| 414 // Group modifications should be reflected in first_run_browsertest.cc and | 478 // Group modifications should be reflected in first_run_browsertest.cc and |
| 415 // pref_hash_browsertest.cc. | 479 // pref_hash_browsertest.cc. |
| 416 const char kSettingsEnforcementTrialName[] = "SettingsEnforcement"; | 480 const char kSettingsEnforcementTrialName[] = "SettingsEnforcement"; |
| 417 const char kSettingsEnforcementGroupNoEnforcement[] = "no_enforcement"; | 481 const char kSettingsEnforcementGroupNoEnforcement[] = "no_enforcement"; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 456 // done since sync may bring back the user's server value post-reset which | 520 // done since sync may bring back the user's server value post-reset which |
| 457 // could potentially cause a "settings flash" between the factory default and | 521 // could potentially cause a "settings flash" between the factory default and |
| 458 // the re-instantiated server value. Starting sync ASAP minimizes the window | 522 // the re-instantiated server value. Starting sync ASAP minimizes the window |
| 459 // before the server value is re-instantiated (this window can otherwise be | 523 // before the server value is re-instantiated (this window can otherwise be |
| 460 // as long as 10 seconds by default). | 524 // as long as 10 seconds by default). |
| 461 const base::Closure start_sync_flare_for_prefs = | 525 const base::Closure start_sync_flare_for_prefs = |
| 462 base::Bind(sync_start_util::GetFlareForSyncableService(profile_path), | 526 base::Bind(sync_start_util::GetFlareForSyncableService(profile_path), |
| 463 syncer::PREFERENCES); | 527 syncer::PREFERENCES); |
| 464 | 528 |
| 465 PrefServiceSyncableFactory factory; | 529 PrefServiceSyncableFactory factory; |
| 530 scoped_refptr<PersistentPrefStore> user_pref_store( | |
| 531 CreateProfilePrefStoreManager(profile_path) | |
| 532 ->CreateProfilePrefStore(pref_io_task_runner, | |
| 533 start_sync_flare_for_prefs, | |
| 534 validation_delegate)); | |
| 535 user_pref_store->AddObserver( | |
| 536 new BrowserUIPrefsMigrationObserver(user_pref_store)); | |
|
gab
2014/09/08 21:29:25
Add a comment above that the BrowserUIPrefsMigrati
dgrogan
2014/09/09 03:15:43
Done.
| |
| 466 PrepareFactory(&factory, | 537 PrepareFactory(&factory, |
| 467 policy_service, | 538 policy_service, |
| 468 supervised_user_settings, | 539 supervised_user_settings, |
| 469 scoped_refptr<PersistentPrefStore>( | 540 user_pref_store, |
| 470 CreateProfilePrefStoreManager(profile_path) | |
| 471 ->CreateProfilePrefStore(pref_io_task_runner, | |
| 472 start_sync_flare_for_prefs, | |
| 473 validation_delegate)), | |
| 474 extension_prefs, | 541 extension_prefs, |
| 475 async); | 542 async); |
| 476 scoped_ptr<PrefServiceSyncable> pref_service = | 543 scoped_ptr<PrefServiceSyncable> pref_service = |
| 477 factory.CreateSyncable(pref_registry.get()); | 544 factory.CreateSyncable(pref_registry.get()); |
| 478 | 545 |
| 479 ConfigureDefaultSearchPrefMigrationToDictionaryValue(pref_service.get()); | 546 ConfigureDefaultSearchPrefMigrationToDictionaryValue(pref_service.get()); |
| 480 | 547 |
| 481 return pref_service.Pass(); | 548 return pref_service.Pass(); |
| 482 } | 549 } |
| 483 | 550 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 517 | 584 |
| 518 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { | 585 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { |
| 519 ProfilePrefStoreManager::RegisterProfilePrefs(registry); | 586 ProfilePrefStoreManager::RegisterProfilePrefs(registry); |
| 520 } | 587 } |
| 521 | 588 |
| 522 void RegisterPrefs(PrefRegistrySimple* registry) { | 589 void RegisterPrefs(PrefRegistrySimple* registry) { |
| 523 ProfilePrefStoreManager::RegisterPrefs(registry); | 590 ProfilePrefStoreManager::RegisterPrefs(registry); |
| 524 } | 591 } |
| 525 | 592 |
| 526 } // namespace chrome_prefs | 593 } // namespace chrome_prefs |
| OLD | NEW |