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

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: Same patch but without stuff that is already included in 5204006 Created 10 years 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
« no previous file with comments | « chrome/browser/prefs/pref_value_store.h ('k') | chrome/browser/profiles/profile_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
45 CommandLinePrefStore* command_line = NULL; 43 CommandLinePrefStore* command_line = NULL;
46 ConfigurationPolicyPrefStore* recommended = NULL; 44 ConfigurationPolicyPrefStore* recommended = NULL;
47 45
48 JsonPrefStore* user = new JsonPrefStore( 46 JsonPrefStore* user = new JsonPrefStore(
49 pref_filename, 47 pref_filename,
50 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); 48 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE));
49 InMemoryPrefStore* extension = new InMemoryPrefStore();
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);
60 command_line = new CommandLinePrefStore(CommandLine::ForCurrentProcess()); 58 command_line = new CommandLinePrefStore(CommandLine::ForCurrentProcess());
61 recommended = 59 recommended =
62 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore(); 60 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore();
63 } 61 }
64 return new PrefValueStore(managed, device_management, extension, 62 return new PrefValueStore(managed, device_management, extension,
65 command_line, user, recommended, default_store, 63 command_line, user, recommended, default_store,
66 profile); 64 profile);
67 } 65 }
68 66
69 PrefValueStore::~PrefValueStore() {} 67 PrefValueStore::~PrefValueStore() {}
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 const std::string name(path); 139 const std::string name(path);
142 bool rv = GetValue(name, &tmp_value); 140 bool rv = GetValue(name, &tmp_value);
143 // Merely registering a pref doesn't count as "having" it: we require a 141 // Merely registering a pref doesn't count as "having" it: we require a
144 // non-default value set. 142 // non-default value set.
145 return rv && !PrefValueFromDefaultStore(path); 143 return rv && !PrefValueFromDefaultStore(path);
146 } 144 }
147 145
148 bool PrefValueStore::PrefHasChanged(const char* path, 146 bool PrefValueStore::PrefHasChanged(const char* path,
149 PrefNotifier::PrefStoreType new_store) { 147 PrefNotifier::PrefStoreType new_store) {
150 DCHECK(new_store != PrefNotifier::INVALID_STORE); 148 DCHECK(new_store != PrefNotifier::INVALID_STORE);
149 // If we get a change notification about an unregistered preference,
150 // discard it silently because there cannot be any listeners.
151 if (pref_types_.find(path) == pref_types_.end())
152 return false;
153
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() const {
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
« no previous file with comments | « chrome/browser/prefs/pref_value_store.h ('k') | chrome/browser/profiles/profile_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698