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

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: Temporary hack to fix regression in unit tests 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/in_memory_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.
(...skipping 15 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 InMemoryPrefStore* default_store = new InMemoryPrefStore(); 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 profile); 57 profile);
59 extension = new ExtensionPrefStore(profile, PrefNotifier::EXTENSION_STORE); 58 extension = new InMemoryPrefStore();
60 command_line = new CommandLinePrefStore(CommandLine::ForCurrentProcess()); 59 command_line = new CommandLinePrefStore(CommandLine::ForCurrentProcess());
61 recommended = 60 recommended =
62 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore(); 61 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore();
62 } else {
63 // TODO(battre) This is a temporary hack to make the unit tests pass.
64 // need to think more whether this is correct.
65 extension = new InMemoryPrefStore();
63 } 66 }
64 return new PrefValueStore(managed, device_management, extension, 67 return new PrefValueStore(managed, device_management, extension,
65 command_line, user, recommended, default_store, 68 command_line, user, recommended, default_store,
66 profile); 69 profile);
67 } 70 }
68 71
69 PrefValueStore::~PrefValueStore() {} 72 PrefValueStore::~PrefValueStore() {}
70 73
71 bool PrefValueStore::GetValue(const std::string& name, 74 bool PrefValueStore::GetValue(const std::string& name,
72 Value** out_value) const { 75 Value** out_value) const {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 150
148 bool PrefValueStore::PrefHasChanged(const char* path, 151 bool PrefValueStore::PrefHasChanged(const char* path,
149 PrefNotifier::PrefStoreType new_store) { 152 PrefNotifier::PrefStoreType new_store) {
150 DCHECK(new_store != PrefNotifier::INVALID_STORE); 153 DCHECK(new_store != PrefNotifier::INVALID_STORE);
151 // Replying that the pref has changed may cause problems, but it's the safer 154 // Replying that the pref has changed may cause problems, but it's the safer
152 // choice. 155 // choice.
153 if (new_store == PrefNotifier::INVALID_STORE) 156 if (new_store == PrefNotifier::INVALID_STORE)
154 return true; 157 return true;
155 158
156 PrefNotifier::PrefStoreType controller = ControllingPrefStoreForPref(path); 159 PrefNotifier::PrefStoreType controller = ControllingPrefStoreForPref(path);
157 DCHECK(controller != PrefNotifier::INVALID_STORE); 160 DCHECK(controller != PrefNotifier::INVALID_STORE)
161 << "Invalid controller for path " << path;
158 if (controller == PrefNotifier::INVALID_STORE) 162 if (controller == PrefNotifier::INVALID_STORE)
159 return true; 163 return true;
160 164
161 // If the pref is controlled by a higher-priority store, its effective value 165 // If the pref is controlled by a higher-priority store, its effective value
162 // cannot have changed. 166 // cannot have changed.
163 if (controller < new_store) 167 if (controller < new_store)
164 return false; 168 return false;
165 169
166 // Otherwise, we take the pref store's word that something changed. 170 // Otherwise, we take the pref store's word that something changed.
167 return true; 171 return true;
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 if ((PrefValueInManagedPlatformStore(*i) || 460 if ((PrefValueInManagedPlatformStore(*i) ||
457 PrefValueInDeviceManagementStore(*i)) && 461 PrefValueInDeviceManagementStore(*i)) &&
458 PrefValueInStoreRange(*i, 462 PrefValueInStoreRange(*i,
459 PrefNotifier::COMMAND_LINE_STORE, 463 PrefNotifier::COMMAND_LINE_STORE,
460 PrefNotifier::USER_STORE)) 464 PrefNotifier::USER_STORE))
461 return true; 465 return true;
462 } 466 }
463 return false; 467 return false;
464 } 468 }
465 469
470 PrefStore* PrefValueStore::GetExtensionPrefStore() {
471 return pref_stores_[PrefNotifier::EXTENSION_STORE].get();
472 }
473
466 PrefValueStore::PrefValueStore(PrefStore* managed_platform_prefs, 474 PrefValueStore::PrefValueStore(PrefStore* managed_platform_prefs,
467 PrefStore* device_management_prefs, 475 PrefStore* device_management_prefs,
468 PrefStore* extension_prefs, 476 PrefStore* extension_prefs,
469 PrefStore* command_line_prefs, 477 PrefStore* command_line_prefs,
470 PrefStore* user_prefs, 478 PrefStore* user_prefs,
471 PrefStore* recommended_prefs, 479 PrefStore* recommended_prefs,
472 PrefStore* default_prefs, 480 PrefStore* default_prefs,
473 Profile* profile) 481 Profile* profile)
474 : profile_(profile) { 482 : profile_(profile) {
475 // NULL default pref store is usually bad, but may be OK for some unit tests. 483 // NULL default pref store is usually bad, but may be OK for some unit tests.
476 if (!default_prefs) 484 if (!default_prefs)
477 LOG(WARNING) << "default pref store is null"; 485 LOG(WARNING) << "default pref store is null";
478 pref_stores_[PrefNotifier::MANAGED_PLATFORM_STORE].reset( 486 pref_stores_[PrefNotifier::MANAGED_PLATFORM_STORE].reset(
479 managed_platform_prefs); 487 managed_platform_prefs);
480 pref_stores_[PrefNotifier::DEVICE_MANAGEMENT_STORE].reset( 488 pref_stores_[PrefNotifier::DEVICE_MANAGEMENT_STORE].reset(
481 device_management_prefs); 489 device_management_prefs);
482 pref_stores_[PrefNotifier::EXTENSION_STORE].reset(extension_prefs); 490 pref_stores_[PrefNotifier::EXTENSION_STORE].reset(extension_prefs);
483 pref_stores_[PrefNotifier::COMMAND_LINE_STORE].reset(command_line_prefs); 491 pref_stores_[PrefNotifier::COMMAND_LINE_STORE].reset(command_line_prefs);
484 pref_stores_[PrefNotifier::USER_STORE].reset(user_prefs); 492 pref_stores_[PrefNotifier::USER_STORE].reset(user_prefs);
485 pref_stores_[PrefNotifier::RECOMMENDED_STORE].reset(recommended_prefs); 493 pref_stores_[PrefNotifier::RECOMMENDED_STORE].reset(recommended_prefs);
486 pref_stores_[PrefNotifier::DEFAULT_STORE].reset(default_prefs); 494 pref_stores_[PrefNotifier::DEFAULT_STORE].reset(default_prefs);
487 } 495 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698