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

Side by Side Diff: chrome/browser/extensions/extension_prefs.h

Issue 5915004: Introduce incognito preference settings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Continued work from last year Created 9 years, 11 months 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) 2011 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 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_
7 #pragma once 7 #pragma once
8 8
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/linked_ptr.h" 13 #include "base/linked_ptr.h"
14 #include "base/ref_counted.h"
14 #include "base/time.h" 15 #include "base/time.h"
16 #include "chrome/browser/extensions/extension_pref_value_map.h"
15 #include "chrome/browser/prefs/pref_service.h" 17 #include "chrome/browser/prefs/pref_service.h"
16 #include "chrome/common/extensions/extension.h" 18 #include "chrome/common/extensions/extension.h"
17 #include "googleurl/src/gurl.h" 19 #include "googleurl/src/gurl.h"
18 20
19 class ExtensionPrefStore; 21 class ExtensionPrefStore;
20 22
21 // Class for managing global and per-extension preferences. 23 // Class for managing global and per-extension preferences.
22 // 24 //
23 // This class distinguishes the following kinds of preferences: 25 // This class distinguishes the following kinds of preferences:
24 // - global preferences: 26 // - global preferences:
(...skipping 27 matching lines...) Expand all
52 // application. 54 // application.
53 // Do not remove items or re-order this enum as it is used in preferences 55 // Do not remove items or re-order this enum as it is used in preferences
54 // and histograms. 56 // and histograms.
55 enum LaunchType { 57 enum LaunchType {
56 LAUNCH_PINNED, 58 LAUNCH_PINNED,
57 LAUNCH_REGULAR, 59 LAUNCH_REGULAR,
58 LAUNCH_FULLSCREEN, 60 LAUNCH_FULLSCREEN,
59 LAUNCH_WINDOW 61 LAUNCH_WINDOW
60 }; 62 };
61 63
64 // Does not assume ownership of |prefs| and |incognito_prefs|.
62 explicit ExtensionPrefs(PrefService* prefs, 65 explicit ExtensionPrefs(PrefService* prefs,
63 const FilePath& root_dir, 66 const FilePath& root_dir,
64 ExtensionPrefStore* extension_pref_store); 67 ExtensionPrefStore* extension_pref_store,
68 ExtensionPrefStore* incognito_pref_store);
Mattias Nissler (ping if slow) 2011/01/05 12:08:07 Why does this accept the pref stores? It should on
battre 2011/01/05 20:23:08 Done.
65 ~ExtensionPrefs(); 69 ~ExtensionPrefs();
66 70
67 // Returns a copy of the Extensions prefs. 71 // Returns a copy of the Extensions prefs.
68 // TODO(erikkay) Remove this so that external consumers don't need to be 72 // TODO(erikkay) Remove this so that external consumers don't need to be
69 // aware of the internal structure of the preferences. 73 // aware of the internal structure of the preferences.
70 DictionaryValue* CopyCurrentExtensions(); 74 DictionaryValue* CopyCurrentExtensions();
71 75
72 // Returns true if the specified extension has an entry in prefs 76 // Returns true if the specified extension has an entry in prefs
73 // and its killbit is on. 77 // and its killbit is on.
74 bool IsExtensionKilled(const std::string& id); 78 bool IsExtensionKilled(const std::string& id);
(...skipping 20 matching lines...) Expand all
95 void OnExtensionUninstalled(const std::string& extension_id, 99 void OnExtensionUninstalled(const std::string& extension_id,
96 const Extension::Location& location, 100 const Extension::Location& location,
97 bool external_uninstall); 101 bool external_uninstall);
98 102
99 // Returns the state (enabled/disabled) of the given extension. 103 // Returns the state (enabled/disabled) of the given extension.
100 Extension::State GetExtensionState(const std::string& extension_id) const; 104 Extension::State GetExtensionState(const std::string& extension_id) const;
101 105
102 // Called to change the extension's state when it is enabled/disabled. 106 // Called to change the extension's state when it is enabled/disabled.
103 void SetExtensionState(const Extension* extension, Extension::State); 107 void SetExtensionState(const Extension* extension, Extension::State);
104 108
105 // Returns all installed and enabled extensions 109 // Returns all installed extensions
106 void GetEnabledExtensions(ExtensionIdSet* out) const; 110 void GetExtensions(ExtensionIdSet* out) const;
107 111
108 // Getter and setter for browser action visibility. 112 // Getter and setter for browser action visibility.
109 bool GetBrowserActionVisibility(const Extension* extension); 113 bool GetBrowserActionVisibility(const Extension* extension);
110 void SetBrowserActionVisibility(const Extension* extension, bool visible); 114 void SetBrowserActionVisibility(const Extension* extension, bool visible);
111 115
112 // Did the extension ask to escalate its permission during an upgrade? 116 // Did the extension ask to escalate its permission during an upgrade?
113 bool DidExtensionEscalatePermissions(const std::string& id); 117 bool DidExtensionEscalatePermissions(const std::string& id);
114 118
115 // If |did_escalate| is true, the preferences for |extension| will be set to 119 // If |did_escalate| is true, the preferences for |extension| will be set to
116 // require the install warning when the user tries to enable. 120 // require the install warning when the user tries to enable.
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 // of the extension is available. 260 // of the extension is available.
257 void SetUpdateUrlData(const std::string& extension_id, 261 void SetUpdateUrlData(const std::string& extension_id,
258 const std::string& data); 262 const std::string& data);
259 std::string GetUpdateUrlData(const std::string& extension_id); 263 std::string GetUpdateUrlData(const std::string& extension_id);
260 264
261 // Sets a preference value that is controlled by the extension. In other 265 // Sets a preference value that is controlled by the extension. In other
262 // words, this is not a pref value *about* the extension but something 266 // words, this is not a pref value *about* the extension but something
263 // global the extension wants to override. 267 // global the extension wants to override.
264 void SetExtensionControlledPref(const std::string& extension_id, 268 void SetExtensionControlledPref(const std::string& extension_id,
265 const std::string& pref_key, 269 const std::string& pref_key,
270 bool incognito,
266 Value* value); 271 Value* value);
267 272
273 PrefService* CreateIncognitoPrefService() const;
Mattias Nissler (ping if slow) 2011/01/05 12:08:07 This shouldn't be here.
battre 2011/01/05 20:23:08 Gone.
274
268 static void RegisterUserPrefs(PrefService* prefs); 275 static void RegisterUserPrefs(PrefService* prefs);
269 276
270 // The underlying PrefService. 277 // The underlying PrefService.
271 PrefService* pref_service() const { return prefs_; } 278 PrefService* pref_service() const { return prefs_; }
272 279
273 protected: 280 protected:
274 // For unit testing. Enables injecting an artificial clock that is used 281 // For unit testing. Enables injecting an artificial clock that is used
275 // to query the current time, when an extension is installed. 282 // to query the current time, when an extension is installed.
276 virtual base::Time GetCurrentTime() const; 283 virtual base::Time GetCurrentTime() const;
277 284
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 const std::string& pref_key, 335 const std::string& pref_key,
329 const std::set<std::string>& added_values); 336 const std::set<std::string>& added_values);
330 337
331 // Ensures and returns a mutable dictionary for extension |id|'s prefs. 338 // Ensures and returns a mutable dictionary for extension |id|'s prefs.
332 DictionaryValue* GetOrCreateExtensionPref(const std::string& id); 339 DictionaryValue* GetOrCreateExtensionPref(const std::string& id);
333 340
334 // Same as above, but returns NULL if it doesn't exist. 341 // Same as above, but returns NULL if it doesn't exist.
335 DictionaryValue* GetExtensionPref(const std::string& id) const; 342 DictionaryValue* GetExtensionPref(const std::string& id) const;
336 343
337 // Returns the dictionary of preferences controlled by the specified extension 344 // Returns the dictionary of preferences controlled by the specified extension
338 // or NULL if unknown. All entries in the dictionary contain non-expanded 345 // or creates a new one. All entries in the dictionary contain non-expanded
339 // paths. 346 // paths.
340 DictionaryValue* GetExtensionControlledPrefs(const std::string& id) const; 347 DictionaryValue* GetExtensionControlledPrefs(const std::string& id) const;
341 348
342 // Serializes the data and schedules a persistent save via the |PrefService|. 349 // Serializes the data and schedules a persistent save via the |PrefService|.
343 // Additionally fires a PREF_CHANGED notification with the top-level 350 // Additionally fires a PREF_CHANGED notification with the top-level
344 // |kExtensionsPref| path set. 351 // |kExtensionsPref| path set.
345 // TODO(andybons): Switch this to EXTENSION_PREF_CHANGED to be more granular. 352 // TODO(andybons): Switch this to EXTENSION_PREF_CHANGED to be more granular.
346 // TODO(andybons): Use a ScopedPrefUpdate to update observers on changes to 353 // TODO(andybons): Use a ScopedPrefUpdate to update observers on changes to
347 // the mutable extension dictionary. 354 // the mutable extension dictionary.
348 void SavePrefsAndNotify(); 355 void SavePrefsAndNotify();
(...skipping 11 matching lines...) Expand all
360 base::Time GetInstallTime(const std::string& extension_id) const; 367 base::Time GetInstallTime(const std::string& extension_id) const;
361 368
362 // Fix missing preference entries in the extensions that are were introduced 369 // Fix missing preference entries in the extensions that are were introduced
363 // in a later Chrome version. 370 // in a later Chrome version.
364 void FixMissingPrefs(const ExtensionIdSet& extension_ids); 371 void FixMissingPrefs(const ExtensionIdSet& extension_ids);
365 372
366 // Installs the persistent extension preferences into |prefs_|'s extension 373 // Installs the persistent extension preferences into |prefs_|'s extension
367 // pref store. 374 // pref store.
368 void InitPrefStore(); 375 void InitPrefStore();
369 376
370 // Returns the extension controlled preference value of the extension that was 377 // The pref service specific to this set of extension prefs. Owned by profile.
371 // installed most recently.
372 const Value* GetWinningExtensionControlledPrefValue(
373 const std::string& key) const;
374
375 // Executes UpdatePrefStore for all |pref_keys|.
376 void UpdatePrefStore(const PrefKeySet& pref_keys);
377
378 // Finds the most recently installed extension that defines a preference
379 // for |pref_key|, then stores its value in the PrefValueStore's extension
380 // pref store and sends notifications to observers in case the value changed.
381 void UpdatePrefStore(const std::string& pref_key);
382
383 // Retrieves a list of preference keys that the specified extension
384 // intends to manage. Keys are always appended, |out| is not cleared.
385 void GetExtensionControlledPrefKeys(const std::string& extension_id,
386 PrefKeySet *out) const;
387
388 // The pref service specific to this set of extension prefs.
389 PrefService* prefs_; 378 PrefService* prefs_;
390 379
391 // Base extensions install directory. 380 // Base extensions install directory.
392 FilePath install_directory_; 381 FilePath install_directory_;
393 382
383 ExtensionPrefValueMap extension_pref_value_map_;
384
394 // Used to manipulate extension preferences. 385 // Used to manipulate extension preferences.
395 ExtensionPrefStore* pref_store_; 386 scoped_refptr<ExtensionPrefStore> pref_store_;
387 // Shared with PrefValueStore of |incognito_prefs_|.
388 scoped_refptr<ExtensionPrefStore> incognito_pref_store_;
396 389
397 // The URLs of all of the toolstrips. 390 // The URLs of all of the toolstrips.
398 URLList shelf_order_; 391 URLList shelf_order_;
399 392
400 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs); 393 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs);
401 }; 394 };
402 395
403 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ 396 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698