OLD | NEW |
---|---|
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 #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" |
15 #include "chrome/browser/prefs/pref_service.h" | 16 #include "chrome/browser/prefs/pref_service.h" |
16 #include "chrome/common/extensions/extension.h" | 17 #include "chrome/common/extensions/extension.h" |
17 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
18 | 19 |
19 class ExtensionPrefStore; | 20 class ExtensionPrefStore; |
20 | 21 |
21 // Class for managing global and per-extension preferences. | 22 // Class for managing global and per-extension preferences. |
22 // | 23 // |
23 // This class distinguishes the following kinds of preferences: | 24 // This class distinguishes the following kinds of preferences: |
(...skipping 28 matching lines...) Expand all Loading... | |
52 // application. | 53 // application. |
53 // Do not remove items or re-order this enum as it is used in preferences | 54 // Do not remove items or re-order this enum as it is used in preferences |
54 // and histograms. | 55 // and histograms. |
55 enum LaunchType { | 56 enum LaunchType { |
56 LAUNCH_PINNED, | 57 LAUNCH_PINNED, |
57 LAUNCH_REGULAR, | 58 LAUNCH_REGULAR, |
58 LAUNCH_FULLSCREEN, | 59 LAUNCH_FULLSCREEN, |
59 LAUNCH_WINDOW | 60 LAUNCH_WINDOW |
60 }; | 61 }; |
61 | 62 |
63 // Does not assume owner ship of |prefs| and |incognito_prefs|. | |
danno
2010/12/22 10:48:21
nit: s/owner ship/ownership/
Mattias Nissler (ping if slow)
2010/12/22 12:09:03
s/owner ship/ownership/
battre
2010/12/22 18:34:53
Done.
battre
2010/12/22 18:34:53
Done.
| |
62 explicit ExtensionPrefs(PrefService* prefs, | 64 explicit ExtensionPrefs(PrefService* prefs, |
65 PrefService* incognito_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)
2010/12/22 12:09:03
It worries me that we need the incognito_prefs poi
battre
2010/12/22 18:34:53
Will do this in the next patch set of this CL.
| |
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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 |
268 static void RegisterUserPrefs(PrefService* prefs); | 273 static void RegisterUserPrefs(PrefService* prefs); |
269 | 274 |
270 // The underlying PrefService. | 275 // The underlying PrefService. |
271 PrefService* pref_service() const { return prefs_; } | 276 PrefService* pref_service() const { return prefs_; } |
272 | 277 |
273 protected: | 278 protected: |
274 // For unit testing. Enables injecting an artificial clock that is used | 279 // For unit testing. Enables injecting an artificial clock that is used |
275 // to query the current time, when an extension is installed. | 280 // to query the current time, when an extension is installed. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
328 const std::string& pref_key, | 333 const std::string& pref_key, |
329 const std::set<std::string>& added_values); | 334 const std::set<std::string>& added_values); |
330 | 335 |
331 // Ensures and returns a mutable dictionary for extension |id|'s prefs. | 336 // Ensures and returns a mutable dictionary for extension |id|'s prefs. |
332 DictionaryValue* GetOrCreateExtensionPref(const std::string& id); | 337 DictionaryValue* GetOrCreateExtensionPref(const std::string& id); |
333 | 338 |
334 // Same as above, but returns NULL if it doesn't exist. | 339 // Same as above, but returns NULL if it doesn't exist. |
335 DictionaryValue* GetExtensionPref(const std::string& id) const; | 340 DictionaryValue* GetExtensionPref(const std::string& id) const; |
336 | 341 |
337 // Returns the dictionary of preferences controlled by the specified extension | 342 // Returns the dictionary of preferences controlled by the specified extension |
338 // or NULL if unknown. All entries in the dictionary contain non-expanded | 343 // or creates a new one. All entries in the dictionary contain non-expanded |
339 // paths. | 344 // paths. |
340 DictionaryValue* GetExtensionControlledPrefs(const std::string& id) const; | 345 DictionaryValue* GetExtensionControlledPrefs(const std::string& id, |
346 bool incognito) const; | |
341 | 347 |
342 // Serializes the data and schedules a persistent save via the |PrefService|. | 348 // Serializes the data and schedules a persistent save via the |PrefService|. |
343 // Additionally fires a PREF_CHANGED notification with the top-level | 349 // Additionally fires a PREF_CHANGED notification with the top-level |
344 // |kExtensionsPref| path set. | 350 // |kExtensionsPref| path set. |
345 // TODO(andybons): Switch this to EXTENSION_PREF_CHANGED to be more granular. | 351 // TODO(andybons): Switch this to EXTENSION_PREF_CHANGED to be more granular. |
346 // TODO(andybons): Use a ScopedPrefUpdate to update observers on changes to | 352 // TODO(andybons): Use a ScopedPrefUpdate to update observers on changes to |
347 // the mutable extension dictionary. | 353 // the mutable extension dictionary. |
348 void SavePrefsAndNotify(); | 354 void SavePrefsAndNotify(); |
349 | 355 |
350 // Checks if kPrefBlacklist is set to true in the DictionaryValue. | 356 // Checks if kPrefBlacklist is set to true in the DictionaryValue. |
(...skipping 12 matching lines...) Expand all Loading... | |
363 // in a later Chrome version. | 369 // in a later Chrome version. |
364 void FixMissingPrefs(const ExtensionIdSet& extension_ids); | 370 void FixMissingPrefs(const ExtensionIdSet& extension_ids); |
365 | 371 |
366 // Installs the persistent extension preferences into |prefs_|'s extension | 372 // Installs the persistent extension preferences into |prefs_|'s extension |
367 // pref store. | 373 // pref store. |
368 void InitPrefStore(); | 374 void InitPrefStore(); |
369 | 375 |
370 // Returns the extension controlled preference value of the extension that was | 376 // Returns the extension controlled preference value of the extension that was |
371 // installed most recently. | 377 // installed most recently. |
372 const Value* GetWinningExtensionControlledPrefValue( | 378 const Value* GetWinningExtensionControlledPrefValue( |
373 const std::string& key) const; | 379 const std::string& key, bool incognito) const; |
374 | 380 |
375 // Executes UpdatePrefStore for all |pref_keys|. | 381 // Executes UpdatePrefStore for all |pref_keys|. |
376 void UpdatePrefStore(const PrefKeySet& pref_keys); | 382 void UpdatePrefStore(const PrefKeySet& pref_keys); |
377 | 383 |
378 // Finds the most recently installed extension that defines a preference | 384 // Finds the most recently installed extension that defines a preference |
379 // for |pref_key|, then stores its value in the PrefValueStore's extension | 385 // 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. | 386 // pref store and sends notifications to observers in case the value changed. |
381 void UpdatePrefStore(const std::string& pref_key); | 387 void UpdatePrefStore(const std::string& pref_key, bool incognito); |
382 | 388 |
383 // Retrieves a list of preference keys that the specified extension | 389 // Retrieves a list of preference keys that the specified extension |
384 // intends to manage. Keys are always appended, |out| is not cleared. | 390 // intends to manage. Keys are always appended, |out| is not cleared. |
385 void GetExtensionControlledPrefKeys(const std::string& extension_id, | 391 void GetExtensionControlledPrefKeys(const std::string& extension_id, |
386 PrefKeySet *out) const; | 392 PrefKeySet *out) const; |
387 | 393 |
388 // The pref service specific to this set of extension prefs. | 394 // The pref service specific to this set of extension prefs. Owned by profile. |
389 PrefService* prefs_; | 395 PrefService* prefs_; |
396 PrefService* incognito_prefs_; | |
390 | 397 |
391 // Base extensions install directory. | 398 // Base extensions install directory. |
392 FilePath install_directory_; | 399 FilePath install_directory_; |
393 | 400 |
394 // Used to manipulate extension preferences. | 401 // Used to manipulate extension preferences. |
395 ExtensionPrefStore* pref_store_; | 402 scoped_refptr<ExtensionPrefStore> pref_store_; |
403 // Shared with PrefValueStore of |incognito_prefs_|. | |
404 scoped_refptr<ExtensionPrefStore> incognito_pref_store_; | |
396 | 405 |
397 // The URLs of all of the toolstrips. | 406 // The URLs of all of the toolstrips. |
398 URLList shelf_order_; | 407 URLList shelf_order_; |
399 | 408 |
400 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs); | 409 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs); |
401 }; | 410 }; |
402 | 411 |
403 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ | 412 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ |
OLD | NEW |