Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Side by Side Diff: chrome/browser/prefs/pref_value_store.cc

Issue 5213002: Fix for Bug 50726 "Save extension list and "winning" prefs from extensions" (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: reuse old DefaultPrefStore as InMemoryPrefStore Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/in_memory_pref_store.h"
12 #include "chrome/common/json_pref_store.h" 11 #include "chrome/common/json_pref_store.h"
13 #include "chrome/common/notification_service.h" 12 #include "chrome/common/notification_service.h"
14 13
15 namespace { 14 namespace {
16 15
17 // Returns true if the actual value is a valid type for the expected type when 16 // Returns true if the actual value is a valid type for the expected type when
18 // found in the given store. 17 // found in the given store.
19 bool IsValidType(Value::ValueType expected, Value::ValueType actual, 18 bool IsValidType(Value::ValueType expected, Value::ValueType actual,
20 PrefNotifier::PrefStoreType store) { 19 PrefNotifier::PrefStoreType store) {
21 if (expected == actual) 20 if (expected == actual)
(...skipping 12 matching lines...) Expand all
34 } // namespace 33 } // namespace
35 34
36 // static 35 // static
37 PrefValueStore* PrefValueStore::CreatePrefValueStore( 36 PrefValueStore* PrefValueStore::CreatePrefValueStore(
38 const FilePath& pref_filename, 37 const FilePath& pref_filename,
39 Profile* profile, 38 Profile* profile,
40 bool user_only) { 39 bool user_only) {
41 using policy::ConfigurationPolicyPrefStore; 40 using policy::ConfigurationPolicyPrefStore;
42 ConfigurationPolicyPrefStore* managed = NULL; 41 ConfigurationPolicyPrefStore* managed = NULL;
43 ConfigurationPolicyPrefStore* device_management = NULL; 42 ConfigurationPolicyPrefStore* device_management = NULL;
44 ExtensionPrefStore* extension = NULL; 43 InMemoryPrefStore* extension = NULL;
45 CommandLinePrefStore* command_line = NULL; 44 CommandLinePrefStore* command_line = NULL;
46 ConfigurationPolicyPrefStore* recommended = NULL; 45 ConfigurationPolicyPrefStore* recommended = NULL;
47 46
48 JsonPrefStore* user = new JsonPrefStore( 47 JsonPrefStore* user = new JsonPrefStore(
49 pref_filename, 48 pref_filename,
50 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); 49 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE));
51 DefaultPrefStore* default_store = new DefaultPrefStore(); 50 InMemoryPrefStore* default_store = new InMemoryPrefStore();
52 51
53 if (!user_only) { 52 if (!user_only) {
54 managed = 53 managed =
55 ConfigurationPolicyPrefStore::CreateManagedPlatformPolicyPrefStore(); 54 ConfigurationPolicyPrefStore::CreateManagedPlatformPolicyPrefStore();
56 device_management = 55 device_management =
57 ConfigurationPolicyPrefStore::CreateDeviceManagementPolicyPrefStore(); 56 ConfigurationPolicyPrefStore::CreateDeviceManagementPolicyPrefStore();
58 extension = new ExtensionPrefStore(profile, PrefNotifier::EXTENSION_STORE); 57 extension = new InMemoryPrefStore;
Mattias Nissler (ping if slow) 2010/11/19 10:47:40 This one has no parens, but the one above has. The
battre (please use the other) 2010/11/19 16:03:18 Done.
59 command_line = new CommandLinePrefStore(CommandLine::ForCurrentProcess()); 58 command_line = new CommandLinePrefStore(CommandLine::ForCurrentProcess());
60 recommended = 59 recommended =
61 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore(); 60 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore();
62 } 61 }
63 return new PrefValueStore(managed, device_management, extension, 62 return new PrefValueStore(managed, device_management, extension,
64 command_line, user, recommended, default_store); 63 command_line, user, recommended, default_store);
65 } 64 }
66 65
67 PrefValueStore::~PrefValueStore() {} 66 PrefValueStore::~PrefValueStore() {}
68 67
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 144
146 bool PrefValueStore::PrefHasChanged(const char* path, 145 bool PrefValueStore::PrefHasChanged(const char* path,
147 PrefNotifier::PrefStoreType new_store) { 146 PrefNotifier::PrefStoreType new_store) {
148 DCHECK(new_store != PrefNotifier::INVALID_STORE); 147 DCHECK(new_store != PrefNotifier::INVALID_STORE);
149 // Replying that the pref has changed may cause problems, but it's the safer 148 // Replying that the pref has changed may cause problems, but it's the safer
150 // choice. 149 // choice.
151 if (new_store == PrefNotifier::INVALID_STORE) 150 if (new_store == PrefNotifier::INVALID_STORE)
152 return true; 151 return true;
153 152
154 PrefNotifier::PrefStoreType controller = ControllingPrefStoreForPref(path); 153 PrefNotifier::PrefStoreType controller = ControllingPrefStoreForPref(path);
155 DCHECK(controller != PrefNotifier::INVALID_STORE); 154 DCHECK(controller != PrefNotifier::INVALID_STORE)
155 << "Invalid controller for path " << path;
156 if (controller == PrefNotifier::INVALID_STORE) 156 if (controller == PrefNotifier::INVALID_STORE)
157 return true; 157 return true;
158 158
159 // If the pref is controlled by a higher-priority store, its effective value 159 // If the pref is controlled by a higher-priority store, its effective value
160 // cannot have changed. 160 // cannot have changed.
161 if (controller < new_store) 161 if (controller < new_store)
162 return false; 162 return false;
163 163
164 // Otherwise, we take the pref store's word that something changed. 164 // Otherwise, we take the pref store's word that something changed.
165 return true; 165 return true;
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 if ((PrefValueInManagedPlatformStore(*i) || 453 if ((PrefValueInManagedPlatformStore(*i) ||
454 PrefValueInDeviceManagementStore(*i)) && 454 PrefValueInDeviceManagementStore(*i)) &&
455 PrefValueInStoreRange(*i, 455 PrefValueInStoreRange(*i,
456 PrefNotifier::COMMAND_LINE_STORE, 456 PrefNotifier::COMMAND_LINE_STORE,
457 PrefNotifier::USER_STORE)) 457 PrefNotifier::USER_STORE))
458 return true; 458 return true;
459 } 459 }
460 return false; 460 return false;
461 } 461 }
462 462
463 void PrefValueStore::ReplaceExtensionPrefStore(PrefStore* extension_prefs) {
464 pref_stores_[PrefNotifier::EXTENSION_STORE].reset(extension_prefs);
465 }
466
467 PrefStore* PrefValueStore::GetExtensionPrefStore() {
468 return pref_stores_[PrefNotifier::EXTENSION_STORE].get();
469 }
470
463 PrefValueStore::PrefValueStore(PrefStore* managed_platform_prefs, 471 PrefValueStore::PrefValueStore(PrefStore* managed_platform_prefs,
464 PrefStore* device_management_prefs, 472 PrefStore* device_management_prefs,
465 PrefStore* extension_prefs, 473 PrefStore* extension_prefs,
466 PrefStore* command_line_prefs, 474 PrefStore* command_line_prefs,
467 PrefStore* user_prefs, 475 PrefStore* user_prefs,
468 PrefStore* recommended_prefs, 476 PrefStore* recommended_prefs,
469 PrefStore* default_prefs) { 477 PrefStore* default_prefs) {
470 // NULL default pref store is usually bad, but may be OK for some unit tests. 478 // NULL default pref store is usually bad, but may be OK for some unit tests.
471 if (!default_prefs) 479 if (!default_prefs)
472 LOG(WARNING) << "default pref store is null"; 480 LOG(WARNING) << "default pref store is null";
473 pref_stores_[PrefNotifier::MANAGED_PLATFORM_STORE].reset( 481 pref_stores_[PrefNotifier::MANAGED_PLATFORM_STORE].reset(
474 managed_platform_prefs); 482 managed_platform_prefs);
475 pref_stores_[PrefNotifier::DEVICE_MANAGEMENT_STORE].reset( 483 pref_stores_[PrefNotifier::DEVICE_MANAGEMENT_STORE].reset(
476 device_management_prefs); 484 device_management_prefs);
477 pref_stores_[PrefNotifier::EXTENSION_STORE].reset(extension_prefs); 485 pref_stores_[PrefNotifier::EXTENSION_STORE].reset(extension_prefs);
478 pref_stores_[PrefNotifier::COMMAND_LINE_STORE].reset(command_line_prefs); 486 pref_stores_[PrefNotifier::COMMAND_LINE_STORE].reset(command_line_prefs);
479 pref_stores_[PrefNotifier::USER_STORE].reset(user_prefs); 487 pref_stores_[PrefNotifier::USER_STORE].reset(user_prefs);
480 pref_stores_[PrefNotifier::RECOMMENDED_STORE].reset(recommended_prefs); 488 pref_stores_[PrefNotifier::RECOMMENDED_STORE].reset(recommended_prefs);
481 pref_stores_[PrefNotifier::DEFAULT_STORE].reset(default_prefs); 489 pref_stores_[PrefNotifier::DEFAULT_STORE].reset(default_prefs);
482 } 490 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698