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

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

Issue 7775008: Enable sync for the settings from the Extension Settings API. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Review #2 against correct branch Created 9 years, 3 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) 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/linked_ptr.h"
10 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
11 #include "chrome/browser/extensions/extension_settings_storage.h" 12 #include "base/task.h"
13 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/extensions/syncable_extension_settings_storage.h"
15 #include "chrome/browser/sync/api/syncable_service.h"
12 16
13 // Manages ExtensionSettingsStorage objects for extensions. 17 // Manages ExtensionSettingsStorage objects for extensions, including routing
14 class ExtensionSettings : public base::RefCountedThreadSafe<ExtensionSettings> { 18 // changes from sync to them.
19 // Lives on the FILE thread, so all methods (apart from the constructor, but
20 // including the destructor) must be called on the FILE thread.
21 class ExtensionSettings
22 : public base::RefCountedThreadSafe<
23 ExtensionSettings, BrowserThread::DeleteOnFileThread>,
24 public SyncableService {
15 public: 25 public:
16 // File path is the base of the extension settings directory. 26 // File path is the base of the extension settings directory.
17 // The databases will be at base_path/extension_id. 27 // The databases will be at base_path/extension_id.
18 explicit ExtensionSettings(const FilePath& base_path); 28 explicit ExtensionSettings(const FilePath& base_path);
19 29
30 // Sets the current ExtensionService, required for GetAllSyncData.
31 // Ownership NOT taken.
32 void SetExtensionService(ExtensionServiceInterface* extension_service);
33
20 // Gets a weak reference to the storage area for a given extension. 34 // Gets a weak reference to the storage area for a given extension.
21 // Must be run on the FILE thread. 35 // Must be run on the FILE thread.
22 // 36 //
23 // By default this will be of a cached LEVELDB storage, but on failure to 37 // 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. 38 // create a leveldb instance will fall back to cached NOOP storage.
25 ExtensionSettingsStorage* GetStorage(const std::string& extension_id); 39 ExtensionSettingsStorage* GetStorage(
40 const std::string& extension_id) const;
26 41
27 // Gets a weak reference to the storage area for a given extension, with a 42 // 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. 43 // specific type and whether it should be wrapped in a cache.
29 // 44 //
30 // Use this for testing; if the given type fails to be created (e.g. if 45 // Use this for testing; if the given type fails to be created (e.g. if
31 // leveldb creation fails) then a DCHECK will fail. 46 // leveldb creation fails) then a DCHECK will fail.
32 ExtensionSettingsStorage* GetStorageForTesting( 47 ExtensionSettingsStorage* GetStorageForTesting(
33 ExtensionSettingsStorage::Type type, 48 ExtensionSettingsStorage::Type type,
34 bool cached, 49 bool cached,
35 const std::string& extension_id); 50 const std::string& extension_id) const;
51
52 // SyncableService implementation.
53 virtual SyncDataList GetAllSyncData(syncable::ModelType type) const OVERRIDE;
54 virtual SyncError MergeDataAndStartSyncing(
55 syncable::ModelType type,
56 const SyncDataList& initial_sync_data,
57 SyncChangeProcessor* sync_processor) OVERRIDE;
58 virtual SyncError ProcessSyncChanges(
59 const tracked_objects::Location& from_here,
60 const SyncChangeList& change_list) OVERRIDE;
61 virtual void StopSyncing(syncable::ModelType type) OVERRIDE;
36 62
37 private: 63 private:
38 friend class base::RefCountedThreadSafe<ExtensionSettings>; 64 friend struct BrowserThread::DeleteOnThread<BrowserThread::FILE>;
65 friend class DeleteTask<ExtensionSettings>;
39 virtual ~ExtensionSettings(); 66 virtual ~ExtensionSettings();
40 67
68 // Gets a weak reference to the storage area for a given extension,
69 // initializing sync with some initial data if sync enabled.
70 //
71 // By default this will be of a cached LEVELDB storage, but on failure to
72 // create a leveldb instance will fall back to cached NOOP storage.
73 SyncableExtensionSettingsStorage* GetOrCreateStorageWithSyncData(
74 const std::string& extension_id, const DictionaryValue& sync_data) const;
75
76 // If a storage area exists in the cache, returns the cached storage area.
77 // Otherwise tries to create one using CreateAndInitStorage.
78 SyncableExtensionSettingsStorage* GetOrCreateAndInitStorage(
79 ExtensionSettingsStorage::Type type,
80 bool cached,
81 const std::string& extension_id,
82 const DictionaryValue& initial_sync_data) const;
83
41 // Creates a storage area of a given type, optionally wrapped in a cache. 84 // Creates a storage area of a given type, optionally wrapped in a cache.
42 // Returns NULL if creation fails. 85 // Returns NULL if creation fails. Otherwise, adds the new storage area to
43 ExtensionSettingsStorage* CreateStorage( 86 // the cache and initializes sync if sync is enabled.
87 SyncableExtensionSettingsStorage* CreateAndInitStorage(
88 ExtensionSettingsStorage::Type type,
89 bool cached,
44 const std::string& extension_id, 90 const std::string& extension_id,
45 ExtensionSettingsStorage::Type type, 91 const DictionaryValue& initial_sync_data) const;
46 bool cached); 92
93 // Appends the sync data from a list of Extensions to a given list.
94 void AppendAllSyncData(
95 SyncDataList* sync_data, const ExtensionList& extensions) const;
47 96
48 // The base file path to create any leveldb databases at. 97 // The base file path to create any leveldb databases at.
49 const FilePath base_path_; 98 const FilePath const base_path_;
50 99
51 // A cache of ExtensionSettingsStorage objects that have already been created. 100 // A cache of ExtensionSettingsStorage objects that have already been created.
52 // Ensure that there is only ever one created per extension. 101 // Ensure that there is only ever one created per extension.
53 std::map<std::string, ExtensionSettingsStorage*> storage_objs_; 102 typedef std::map<std::string, linked_ptr<SyncableExtensionSettingsStorage> >
103 StorageObjMap;
104 mutable StorageObjMap storage_objs_;
105
106 // Current extension service. Needed in order to list all extensions when
107 // getting all settings for GetAllSyncData().
108 const ExtensionServiceInterface* extension_service_;
109
110 // Current sync processor, if any.
111 SyncChangeProcessor* sync_processor_;
54 112
55 DISALLOW_COPY_AND_ASSIGN(ExtensionSettings); 113 DISALLOW_COPY_AND_ASSIGN(ExtensionSettings);
56 }; 114 };
57 115
58 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_H_ 116 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698