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

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: Lint issues and factored out renaming of 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/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();
63 } 62 }
64 return new PrefValueStore(managed, device_management, extension, 63 return new PrefValueStore(managed, device_management, extension,
65 command_line, user, recommended, default_store, 64 command_line, user, recommended, default_store,
66 profile); 65 profile);
67 } 66 }
68 67
69 PrefValueStore::~PrefValueStore() {} 68 PrefValueStore::~PrefValueStore() {}
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 146
148 bool PrefValueStore::PrefHasChanged(const char* path, 147 bool PrefValueStore::PrefHasChanged(const char* path,
149 PrefNotifier::PrefStoreType new_store) { 148 PrefNotifier::PrefStoreType new_store) {
150 DCHECK(new_store != PrefNotifier::INVALID_STORE); 149 DCHECK(new_store != PrefNotifier::INVALID_STORE);
151 // Replying that the pref has changed may cause problems, but it's the safer 150 // Replying that the pref has changed may cause problems, but it's the safer
152 // choice. 151 // choice.
153 if (new_store == PrefNotifier::INVALID_STORE) 152 if (new_store == PrefNotifier::INVALID_STORE)
154 return true; 153 return true;
155 154
156 PrefNotifier::PrefStoreType controller = ControllingPrefStoreForPref(path); 155 PrefNotifier::PrefStoreType controller = ControllingPrefStoreForPref(path);
157 DCHECK(controller != PrefNotifier::INVALID_STORE); 156 DCHECK(controller != PrefNotifier::INVALID_STORE)
157 << "Invalid controller for path " << path;
158 if (controller == PrefNotifier::INVALID_STORE) 158 if (controller == PrefNotifier::INVALID_STORE)
159 return true; 159 return true;
160 160
161 // If the pref is controlled by a higher-priority store, its effective value 161 // If the pref is controlled by a higher-priority store, its effective value
162 // cannot have changed. 162 // cannot have changed.
163 if (controller < new_store) 163 if (controller < new_store)
164 return false; 164 return false;
165 165
166 // Otherwise, we take the pref store's word that something changed. 166 // Otherwise, we take the pref store's word that something changed.
167 return true; 167 return true;
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 if ((PrefValueInManagedPlatformStore(*i) || 456 if ((PrefValueInManagedPlatformStore(*i) ||
457 PrefValueInDeviceManagementStore(*i)) && 457 PrefValueInDeviceManagementStore(*i)) &&
458 PrefValueInStoreRange(*i, 458 PrefValueInStoreRange(*i,
459 PrefNotifier::COMMAND_LINE_STORE, 459 PrefNotifier::COMMAND_LINE_STORE,
460 PrefNotifier::USER_STORE)) 460 PrefNotifier::USER_STORE))
461 return true; 461 return true;
462 } 462 }
463 return false; 463 return false;
464 } 464 }
465 465
466 PrefStore* PrefValueStore::GetExtensionPrefStore() {
467 return pref_stores_[PrefNotifier::EXTENSION_STORE].get();
Mattias Nissler (ping if slow) 2010/11/19 16:52:20 Fix indentation.
battre (please use the other) 2010/11/19 18:00:39 Done.
468 }
469
466 PrefValueStore::PrefValueStore(PrefStore* managed_platform_prefs, 470 PrefValueStore::PrefValueStore(PrefStore* managed_platform_prefs,
467 PrefStore* device_management_prefs, 471 PrefStore* device_management_prefs,
468 PrefStore* extension_prefs, 472 PrefStore* extension_prefs,
469 PrefStore* command_line_prefs, 473 PrefStore* command_line_prefs,
470 PrefStore* user_prefs, 474 PrefStore* user_prefs,
471 PrefStore* recommended_prefs, 475 PrefStore* recommended_prefs,
472 PrefStore* default_prefs, 476 PrefStore* default_prefs,
473 Profile* profile) 477 Profile* profile)
474 : profile_(profile) { 478 : profile_(profile) {
475 // 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.
476 if (!default_prefs) 480 if (!default_prefs)
477 LOG(WARNING) << "default pref store is null"; 481 LOG(WARNING) << "default pref store is null";
478 pref_stores_[PrefNotifier::MANAGED_PLATFORM_STORE].reset( 482 pref_stores_[PrefNotifier::MANAGED_PLATFORM_STORE].reset(
479 managed_platform_prefs); 483 managed_platform_prefs);
480 pref_stores_[PrefNotifier::DEVICE_MANAGEMENT_STORE].reset( 484 pref_stores_[PrefNotifier::DEVICE_MANAGEMENT_STORE].reset(
481 device_management_prefs); 485 device_management_prefs);
482 pref_stores_[PrefNotifier::EXTENSION_STORE].reset(extension_prefs); 486 pref_stores_[PrefNotifier::EXTENSION_STORE].reset(extension_prefs);
483 pref_stores_[PrefNotifier::COMMAND_LINE_STORE].reset(command_line_prefs); 487 pref_stores_[PrefNotifier::COMMAND_LINE_STORE].reset(command_line_prefs);
484 pref_stores_[PrefNotifier::USER_STORE].reset(user_prefs); 488 pref_stores_[PrefNotifier::USER_STORE].reset(user_prefs);
485 pref_stores_[PrefNotifier::RECOMMENDED_STORE].reset(recommended_prefs); 489 pref_stores_[PrefNotifier::RECOMMENDED_STORE].reset(recommended_prefs);
486 pref_stores_[PrefNotifier::DEFAULT_STORE].reset(default_prefs); 490 pref_stores_[PrefNotifier::DEFAULT_STORE].reset(default_prefs);
487 } 491 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698