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" | |
9 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 8 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
10 #include "chrome/browser/prefs/command_line_pref_store.h" | 9 #include "chrome/browser/prefs/command_line_pref_store.h" |
11 #include "chrome/browser/prefs/default_pref_store.h" | 10 #include "chrome/browser/prefs/default_pref_store.h" |
| 11 #include "chrome/common/in_memory_pref_store.h" |
12 #include "chrome/common/json_pref_store.h" | 12 #include "chrome/common/json_pref_store.h" |
13 #include "chrome/common/notification_service.h" | 13 #include "chrome/common/notification_service.h" |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 // Returns true if the actual value is a valid type for the expected type when | 17 // Returns true if the actual value is a valid type for the expected type when |
18 // found in the given store. | 18 // found in the given store. |
19 bool IsValidType(Value::ValueType expected, Value::ValueType actual, | 19 bool IsValidType(Value::ValueType expected, Value::ValueType actual, |
20 PrefNotifier::PrefStoreType store) { | 20 PrefNotifier::PrefStoreType store) { |
21 if (expected == actual) | 21 if (expected == actual) |
(...skipping 12 matching lines...) Expand all Loading... |
34 } // namespace | 34 } // namespace |
35 | 35 |
36 // static | 36 // static |
37 PrefValueStore* PrefValueStore::CreatePrefValueStore( | 37 PrefValueStore* PrefValueStore::CreatePrefValueStore( |
38 const FilePath& pref_filename, | 38 const FilePath& pref_filename, |
39 Profile* profile, | 39 Profile* profile, |
40 bool user_only) { | 40 bool user_only) { |
41 using policy::ConfigurationPolicyPrefStore; | 41 using policy::ConfigurationPolicyPrefStore; |
42 ConfigurationPolicyPrefStore* managed = NULL; | 42 ConfigurationPolicyPrefStore* managed = NULL; |
43 ConfigurationPolicyPrefStore* device_management = NULL; | 43 ConfigurationPolicyPrefStore* device_management = NULL; |
44 ExtensionPrefStore* extension = NULL; | 44 InMemoryPrefStore* extension = NULL; |
45 CommandLinePrefStore* command_line = NULL; | 45 CommandLinePrefStore* command_line = NULL; |
46 ConfigurationPolicyPrefStore* recommended = NULL; | 46 ConfigurationPolicyPrefStore* recommended = NULL; |
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 extension = new ExtensionPrefStore(profile, PrefNotifier::EXTENSION_STORE); | 58 extension = new InMemoryPrefStore; |
59 command_line = new CommandLinePrefStore(CommandLine::ForCurrentProcess()); | 59 command_line = new CommandLinePrefStore(CommandLine::ForCurrentProcess()); |
60 recommended = | 60 recommended = |
61 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore(); | 61 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore(); |
62 } | 62 } |
63 return new PrefValueStore(managed, device_management, extension, | 63 return new PrefValueStore(managed, device_management, extension, |
64 command_line, user, recommended, default_store); | 64 command_line, user, recommended, default_store); |
65 } | 65 } |
66 | 66 |
67 PrefValueStore::~PrefValueStore() {} | 67 PrefValueStore::~PrefValueStore() {} |
68 | 68 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 | 145 |
146 bool PrefValueStore::PrefHasChanged(const char* path, | 146 bool PrefValueStore::PrefHasChanged(const char* path, |
147 PrefNotifier::PrefStoreType new_store) { | 147 PrefNotifier::PrefStoreType new_store) { |
148 DCHECK(new_store != PrefNotifier::INVALID_STORE); | 148 DCHECK(new_store != PrefNotifier::INVALID_STORE); |
149 // Replying that the pref has changed may cause problems, but it's the safer | 149 // Replying that the pref has changed may cause problems, but it's the safer |
150 // choice. | 150 // choice. |
151 if (new_store == PrefNotifier::INVALID_STORE) | 151 if (new_store == PrefNotifier::INVALID_STORE) |
152 return true; | 152 return true; |
153 | 153 |
154 PrefNotifier::PrefStoreType controller = ControllingPrefStoreForPref(path); | 154 PrefNotifier::PrefStoreType controller = ControllingPrefStoreForPref(path); |
155 DCHECK(controller != PrefNotifier::INVALID_STORE); | 155 DCHECK(controller != PrefNotifier::INVALID_STORE) |
| 156 << "Invalid controller for path " << path; |
156 if (controller == PrefNotifier::INVALID_STORE) | 157 if (controller == PrefNotifier::INVALID_STORE) |
157 return true; | 158 return true; |
158 | 159 |
159 // If the pref is controlled by a higher-priority store, its effective value | 160 // If the pref is controlled by a higher-priority store, its effective value |
160 // cannot have changed. | 161 // cannot have changed. |
161 if (controller < new_store) | 162 if (controller < new_store) |
162 return false; | 163 return false; |
163 | 164 |
164 // Otherwise, we take the pref store's word that something changed. | 165 // Otherwise, we take the pref store's word that something changed. |
165 return true; | 166 return true; |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 if ((PrefValueInManagedPlatformStore(*i) || | 454 if ((PrefValueInManagedPlatformStore(*i) || |
454 PrefValueInDeviceManagementStore(*i)) && | 455 PrefValueInDeviceManagementStore(*i)) && |
455 PrefValueInStoreRange(*i, | 456 PrefValueInStoreRange(*i, |
456 PrefNotifier::COMMAND_LINE_STORE, | 457 PrefNotifier::COMMAND_LINE_STORE, |
457 PrefNotifier::USER_STORE)) | 458 PrefNotifier::USER_STORE)) |
458 return true; | 459 return true; |
459 } | 460 } |
460 return false; | 461 return false; |
461 } | 462 } |
462 | 463 |
| 464 void PrefValueStore::ReplaceExtensionPrefStore(PrefStore* extension_prefs) { |
| 465 pref_stores_[PrefNotifier::EXTENSION_STORE].reset(extension_prefs); |
| 466 } |
| 467 |
| 468 PrefStore* PrefValueStore::GetExtensionPrefStore() { |
| 469 return pref_stores_[PrefNotifier::EXTENSION_STORE].get(); |
| 470 } |
| 471 |
463 PrefValueStore::PrefValueStore(PrefStore* managed_platform_prefs, | 472 PrefValueStore::PrefValueStore(PrefStore* managed_platform_prefs, |
464 PrefStore* device_management_prefs, | 473 PrefStore* device_management_prefs, |
465 PrefStore* extension_prefs, | 474 PrefStore* extension_prefs, |
466 PrefStore* command_line_prefs, | 475 PrefStore* command_line_prefs, |
467 PrefStore* user_prefs, | 476 PrefStore* user_prefs, |
468 PrefStore* recommended_prefs, | 477 PrefStore* recommended_prefs, |
469 PrefStore* default_prefs) { | 478 PrefStore* default_prefs) { |
470 // NULL default pref store is usually bad, but may be OK for some unit tests. | 479 // NULL default pref store is usually bad, but may be OK for some unit tests. |
471 if (!default_prefs) | 480 if (!default_prefs) |
472 LOG(WARNING) << "default pref store is null"; | 481 LOG(WARNING) << "default pref store is null"; |
473 pref_stores_[PrefNotifier::MANAGED_PLATFORM_STORE].reset( | 482 pref_stores_[PrefNotifier::MANAGED_PLATFORM_STORE].reset( |
474 managed_platform_prefs); | 483 managed_platform_prefs); |
475 pref_stores_[PrefNotifier::DEVICE_MANAGEMENT_STORE].reset( | 484 pref_stores_[PrefNotifier::DEVICE_MANAGEMENT_STORE].reset( |
476 device_management_prefs); | 485 device_management_prefs); |
477 pref_stores_[PrefNotifier::EXTENSION_STORE].reset(extension_prefs); | 486 pref_stores_[PrefNotifier::EXTENSION_STORE].reset(extension_prefs); |
478 pref_stores_[PrefNotifier::COMMAND_LINE_STORE].reset(command_line_prefs); | 487 pref_stores_[PrefNotifier::COMMAND_LINE_STORE].reset(command_line_prefs); |
479 pref_stores_[PrefNotifier::USER_STORE].reset(user_prefs); | 488 pref_stores_[PrefNotifier::USER_STORE].reset(user_prefs); |
480 pref_stores_[PrefNotifier::RECOMMENDED_STORE].reset(recommended_prefs); | 489 pref_stores_[PrefNotifier::RECOMMENDED_STORE].reset(recommended_prefs); |
481 pref_stores_[PrefNotifier::DEFAULT_STORE].reset(default_prefs); | 490 pref_stores_[PrefNotifier::DEFAULT_STORE].reset(default_prefs); |
482 } | 491 } |
OLD | NEW |