OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/pref_value_store.h" | 5 #include "chrome/browser/prefs/pref_value_store.h" |
6 | 6 |
7 #include "chrome/browser/browser_thread.h" | 7 #include "chrome/browser/browser_thread.h" |
8 #include "chrome/browser/extensions/extension_pref_store.h" | 8 #include "chrome/browser/extensions/extension_pref_store.h" |
9 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 9 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
10 #include "chrome/browser/prefs/command_line_pref_store.h" | 10 #include "chrome/browser/prefs/command_line_pref_store.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 | 47 |
48 JsonPrefStore* user = new JsonPrefStore( | 48 JsonPrefStore* user = new JsonPrefStore( |
49 pref_filename, | 49 pref_filename, |
50 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); | 50 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); |
51 DefaultPrefStore* default_store = new DefaultPrefStore(); | 51 DefaultPrefStore* default_store = new DefaultPrefStore(); |
52 | 52 |
53 if (!user_only) { | 53 if (!user_only) { |
54 managed = | 54 managed = |
55 ConfigurationPolicyPrefStore::CreateManagedPlatformPolicyPrefStore(); | 55 ConfigurationPolicyPrefStore::CreateManagedPlatformPolicyPrefStore(); |
56 device_management = | 56 device_management = |
57 ConfigurationPolicyPrefStore::CreateDeviceManagementPolicyPrefStore(); | 57 ConfigurationPolicyPrefStore::CreateDeviceManagementPolicyPrefStore( |
| 58 profile); |
58 extension = new ExtensionPrefStore(profile, PrefNotifier::EXTENSION_STORE); | 59 extension = new ExtensionPrefStore(profile, PrefNotifier::EXTENSION_STORE); |
59 command_line = new CommandLinePrefStore(CommandLine::ForCurrentProcess()); | 60 command_line = new CommandLinePrefStore(CommandLine::ForCurrentProcess()); |
60 recommended = | 61 recommended = |
61 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore(); | 62 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore(); |
62 } | 63 } |
63 return new PrefValueStore(managed, device_management, extension, | 64 return new PrefValueStore(managed, device_management, extension, |
64 command_line, user, recommended, default_store); | 65 command_line, user, recommended, default_store, |
| 66 profile); |
65 } | 67 } |
66 | 68 |
67 PrefValueStore::~PrefValueStore() {} | 69 PrefValueStore::~PrefValueStore() {} |
68 | 70 |
69 bool PrefValueStore::GetValue(const std::string& name, | 71 bool PrefValueStore::GetValue(const std::string& name, |
70 Value** out_value) const { | 72 Value** out_value) const { |
71 // Check the |PrefStore|s in order of their priority from highest to lowest | 73 // Check the |PrefStore|s in order of their priority from highest to lowest |
72 // to find the value of the preference described by the given preference name. | 74 // to find the value of the preference described by the given preference name. |
73 for (size_t i = 0; i <= PrefNotifier::PREF_STORE_TYPE_MAX; ++i) { | 75 for (size_t i = 0; i <= PrefNotifier::PREF_STORE_TYPE_MAX; ++i) { |
74 if (GetValueFromStore(name.c_str(), | 76 if (GetValueFromStore(name.c_str(), |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 // Because loading of policy information must happen on the FILE | 423 // Because loading of policy information must happen on the FILE |
422 // thread, it's not possible to just replace the contents of the | 424 // thread, it's not possible to just replace the contents of the |
423 // managed and recommended stores in place due to possible | 425 // managed and recommended stores in place due to possible |
424 // concurrent access from the UI thread. Instead, new stores are | 426 // concurrent access from the UI thread. Instead, new stores are |
425 // created and the refreshed policy read into them. The new stores | 427 // created and the refreshed policy read into them. The new stores |
426 // are swapped with the old from a Task on the UI thread after the | 428 // are swapped with the old from a Task on the UI thread after the |
427 // load is complete. | 429 // load is complete. |
428 PrefStore* new_managed_platform_pref_store( | 430 PrefStore* new_managed_platform_pref_store( |
429 ConfigurationPolicyPrefStore::CreateManagedPlatformPolicyPrefStore()); | 431 ConfigurationPolicyPrefStore::CreateManagedPlatformPolicyPrefStore()); |
430 PrefStore* new_device_management_pref_store( | 432 PrefStore* new_device_management_pref_store( |
431 ConfigurationPolicyPrefStore::CreateDeviceManagementPolicyPrefStore()); | 433 ConfigurationPolicyPrefStore::CreateDeviceManagementPolicyPrefStore( |
| 434 profile_)); |
432 PrefStore* new_recommended_pref_store( | 435 PrefStore* new_recommended_pref_store( |
433 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore()); | 436 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore()); |
434 BrowserThread::ID current_thread_id; | 437 BrowserThread::ID current_thread_id; |
435 CHECK(BrowserThread::GetCurrentThreadIdentifier(¤t_thread_id)); | 438 CHECK(BrowserThread::GetCurrentThreadIdentifier(¤t_thread_id)); |
436 BrowserThread::PostTask( | 439 BrowserThread::PostTask( |
437 BrowserThread::FILE, FROM_HERE, | 440 BrowserThread::FILE, FROM_HERE, |
438 NewRunnableMethod(this, | 441 NewRunnableMethod(this, |
439 &PrefValueStore::RefreshPolicyPrefsOnFileThread, | 442 &PrefValueStore::RefreshPolicyPrefsOnFileThread, |
440 current_thread_id, | 443 current_thread_id, |
441 new_managed_platform_pref_store, | 444 new_managed_platform_pref_store, |
(...skipping 17 matching lines...) Expand all Loading... |
459 } | 462 } |
460 return false; | 463 return false; |
461 } | 464 } |
462 | 465 |
463 PrefValueStore::PrefValueStore(PrefStore* managed_platform_prefs, | 466 PrefValueStore::PrefValueStore(PrefStore* managed_platform_prefs, |
464 PrefStore* device_management_prefs, | 467 PrefStore* device_management_prefs, |
465 PrefStore* extension_prefs, | 468 PrefStore* extension_prefs, |
466 PrefStore* command_line_prefs, | 469 PrefStore* command_line_prefs, |
467 PrefStore* user_prefs, | 470 PrefStore* user_prefs, |
468 PrefStore* recommended_prefs, | 471 PrefStore* recommended_prefs, |
469 PrefStore* default_prefs) { | 472 PrefStore* default_prefs, |
| 473 Profile* profile) |
| 474 : profile_(profile) { |
470 // NULL default pref store is usually bad, but may be OK for some unit tests. | 475 // NULL default pref store is usually bad, but may be OK for some unit tests. |
471 if (!default_prefs) | 476 if (!default_prefs) |
472 LOG(WARNING) << "default pref store is null"; | 477 LOG(WARNING) << "default pref store is null"; |
473 pref_stores_[PrefNotifier::MANAGED_PLATFORM_STORE].reset( | 478 pref_stores_[PrefNotifier::MANAGED_PLATFORM_STORE].reset( |
474 managed_platform_prefs); | 479 managed_platform_prefs); |
475 pref_stores_[PrefNotifier::DEVICE_MANAGEMENT_STORE].reset( | 480 pref_stores_[PrefNotifier::DEVICE_MANAGEMENT_STORE].reset( |
476 device_management_prefs); | 481 device_management_prefs); |
477 pref_stores_[PrefNotifier::EXTENSION_STORE].reset(extension_prefs); | 482 pref_stores_[PrefNotifier::EXTENSION_STORE].reset(extension_prefs); |
478 pref_stores_[PrefNotifier::COMMAND_LINE_STORE].reset(command_line_prefs); | 483 pref_stores_[PrefNotifier::COMMAND_LINE_STORE].reset(command_line_prefs); |
479 pref_stores_[PrefNotifier::USER_STORE].reset(user_prefs); | 484 pref_stores_[PrefNotifier::USER_STORE].reset(user_prefs); |
480 pref_stores_[PrefNotifier::RECOMMENDED_STORE].reset(recommended_prefs); | 485 pref_stores_[PrefNotifier::RECOMMENDED_STORE].reset(recommended_prefs); |
481 pref_stores_[PrefNotifier::DEFAULT_STORE].reset(default_prefs); | 486 pref_stores_[PrefNotifier::DEFAULT_STORE].reset(default_prefs); |
482 } | 487 } |
OLD | NEW |