Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 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_SETTINGS_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "chrome/browser/extensions/extension_settings_storage.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
| 12 #include "chrome/browser/extensions/syncable_extension_settings_storage.h" | |
| 13 #include "chrome/browser/sync/api/syncable_service.h" | |
| 12 | 14 |
| 13 // Manages ExtensionSettingsStorage objects for extensions. | 15 // Manages ExtensionSettingsStorage objects for extensions, including routing |
| 14 class ExtensionSettings : public base::RefCountedThreadSafe<ExtensionSettings> { | 16 // changes from sync to them. |
| 17 class ExtensionSettings | |
|
akalin
2011/09/15 19:56:44
Say that this lives on the FILE thread, and all me
not at google - send to devlin
2011/09/16 05:18:59
Done.
| |
| 18 : public base::RefCountedThreadSafe<ExtensionSettings>, | |
|
akalin
2011/09/15 19:56:44
since this lives on the FILE thread only, shouldn'
not at google - send to devlin
2011/09/16 05:18:59
It seemed easiest to do the RefCountedThreadSafe w
akalin
2011/09/16 15:36:40
See earlier rant about lifetime management. This
not at google - send to devlin
2011/09/19 07:10:46
See previous comment.
| |
| 19 public SyncableService { | |
| 15 public: | 20 public: |
| 16 // File path is the base of the extension settings directory. | 21 // File path is the base of the extension settings directory. |
| 17 // The databases will be at base_path/extension_id. | 22 // The databases will be at base_path/extension_id. |
| 18 explicit ExtensionSettings(const FilePath& base_path); | 23 explicit ExtensionSettings(const FilePath& base_path); |
| 19 | 24 |
| 25 // Sets the current ExtensionService, required for GetAllSyncData. | |
| 26 // Ownership NOT taken. | |
| 27 void SetExtensionService(ExtensionServiceInterface* extension_service); | |
|
akalin
2011/09/15 19:56:44
Prefer to make this a constructor arg, since it'll
not at google - send to devlin
2011/09/16 05:18:59
Can't make it a ctor argument unfortunately becaus
akalin
2011/09/16 15:36:40
Ugh. Maybe add a comment? Although if ExtensionS
not at google - send to devlin
2011/09/19 07:10:46
Don't need this any more.
| |
| 28 | |
| 20 // Gets a weak reference to the storage area for a given extension. | 29 // Gets a weak reference to the storage area for a given extension. |
| 21 // Must be run on the FILE thread. | 30 // Must be run on the FILE thread. |
| 22 // | 31 // |
| 23 // By default this will be of a cached LEVELDB storage, but on failure to | 32 // By default this will be of a cached LEVELDB storage, but on failure to |
| 24 // create a leveldb instance will fall back to cached NOOP storage. | 33 // create a leveldb instance will fall back to cached NOOP storage. |
| 25 ExtensionSettingsStorage* GetStorage(const std::string& extension_id); | 34 ExtensionSettingsStorage* GetStorage( |
| 35 const std::string& extension_id) const; | |
| 26 | 36 |
| 27 // Gets a weak reference to the storage area for a given extension, with a | 37 // Gets a weak reference to the storage area for a given extension, with a |
| 28 // specific type and whether it should be wrapped in a cache. | 38 // specific type and whether it should be wrapped in a cache. |
| 29 // | 39 // |
| 30 // Use this for testing; if the given type fails to be created (e.g. if | 40 // Use this for testing; if the given type fails to be created (e.g. if |
| 31 // leveldb creation fails) then a DCHECK will fail. | 41 // leveldb creation fails) then a DCHECK will fail. |
| 32 ExtensionSettingsStorage* GetStorageForTesting( | 42 ExtensionSettingsStorage* GetStorageForTesting( |
| 33 ExtensionSettingsStorage::Type type, | 43 ExtensionSettingsStorage::Type type, |
| 34 bool cached, | 44 bool cached, |
| 35 const std::string& extension_id); | 45 const std::string& extension_id) const; |
| 46 | |
| 47 // SyncableService implementation. | |
| 48 virtual SyncDataList GetAllSyncData(syncable::ModelType type) const OVERRIDE; | |
| 49 virtual SyncError MergeDataAndStartSyncing( | |
| 50 syncable::ModelType type, | |
| 51 const SyncDataList& initial_sync_data, | |
| 52 SyncChangeProcessor* sync_processor) OVERRIDE; | |
| 53 virtual SyncError ProcessSyncChanges( | |
| 54 const tracked_objects::Location& from_here, | |
| 55 const SyncChangeList& change_list) OVERRIDE; | |
| 56 virtual void StopSyncing(syncable::ModelType type) OVERRIDE; | |
| 36 | 57 |
| 37 private: | 58 private: |
| 38 friend class base::RefCountedThreadSafe<ExtensionSettings>; | 59 friend class base::RefCountedThreadSafe<ExtensionSettings>; |
| 39 virtual ~ExtensionSettings(); | 60 virtual ~ExtensionSettings(); |
| 40 | 61 |
| 62 // Gets a weak reference to the storage area for a given extension, | |
| 63 // initializing sync with some initial data if sync enabled. | |
| 64 // | |
| 65 // By default this will be of a cached LEVELDB storage, but on failure to | |
| 66 // create a leveldb instance will fall back to cached NOOP storage. | |
| 67 SyncableExtensionSettingsStorage* GetOrCreateStorageWithSyncData( | |
| 68 const std::string& extension_id, const DictionaryValue& sync_data) const; | |
| 69 | |
| 70 // If a storage area exists in the cache, returns the cached storage area. | |
| 71 // Otherwise tries to create one using CreateAndInitStorage. | |
| 72 SyncableExtensionSettingsStorage* GetOrCreateAndInitStorage( | |
| 73 ExtensionSettingsStorage::Type type, | |
| 74 bool cached, | |
| 75 const std::string& extension_id, | |
| 76 const DictionaryValue& initial_sync_data) const; | |
| 77 | |
| 41 // Creates a storage area of a given type, optionally wrapped in a cache. | 78 // Creates a storage area of a given type, optionally wrapped in a cache. |
| 42 // Returns NULL if creation fails. | 79 // Returns NULL if creation fails. Otherwise, adds the new storage area to |
| 43 ExtensionSettingsStorage* CreateStorage( | 80 // the cache and initializes sync if sync is enabled. |
| 81 SyncableExtensionSettingsStorage* CreateAndInitStorage( | |
| 82 ExtensionSettingsStorage::Type type, | |
| 83 bool cached, | |
| 44 const std::string& extension_id, | 84 const std::string& extension_id, |
| 45 ExtensionSettingsStorage::Type type, | 85 const DictionaryValue& initial_sync_data) const; |
| 46 bool cached); | 86 |
| 87 // Appends the sync data from a list of Extensions to a given list. | |
| 88 void AppendAllSyncData( | |
| 89 SyncDataList* sync_data, const ExtensionList& extensions) const; | |
| 47 | 90 |
| 48 // The base file path to create any leveldb databases at. | 91 // The base file path to create any leveldb databases at. |
| 49 const FilePath base_path_; | 92 const FilePath base_path_; |
| 50 | 93 |
| 51 // A cache of ExtensionSettingsStorage objects that have already been created. | 94 // A cache of ExtensionSettingsStorage objects that have already been created. |
| 52 // Ensure that there is only ever one created per extension. | 95 // Ensure that there is only ever one created per extension. |
| 53 std::map<std::string, ExtensionSettingsStorage*> storage_objs_; | 96 mutable |
| 97 std::map<std::string, SyncableExtensionSettingsStorage*> storage_objs_; | |
| 98 | |
| 99 // Current extension service. Needed in order to list all extensions when | |
| 100 // getting all settings for GetAllSyncData(). | |
| 101 const ExtensionServiceInterface* extension_service_; | |
| 102 | |
| 103 // Current sync processor, if any. | |
| 104 SyncChangeProcessor* sync_processor_; | |
| 54 | 105 |
| 55 DISALLOW_COPY_AND_ASSIGN(ExtensionSettings); | 106 DISALLOW_COPY_AND_ASSIGN(ExtensionSettings); |
| 56 }; | 107 }; |
| 57 | 108 |
| 58 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_H_ | 109 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_H_ |
| OLD | NEW |