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

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

Issue 7747043: WORK IN PROGRESS. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Small change 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/callback.h" 9 #include "base/callback.h"
10 #include "base/compiler_specific.h"
10 #include "base/file_path.h" 11 #include "base/file_path.h"
11 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/values.h"
12 #include "chrome/browser/extensions/extension_settings_storage.h" 15 #include "chrome/browser/extensions/extension_settings_storage.h"
16 #include "chrome/browser/extensions/extension_settings.h"
17 #include "chrome/browser/extensions/extension_settings_storage.h"
18 #include "chrome/browser/extensions/extension_settings_sync_data.h"
19 #include "chrome/browser/extensions/syncable_extension_settings_storage.h"
20 #include "chrome/browser/sync/api/syncable_service.h"
21 #include "chrome/browser/sync/api/sync_data.h"
22 #include "chrome/browser/sync/api/sync_change.h"
13 23
14 // Manages ExtensionSettingsStorage objects for extensions. 24 // Manages ExtensionSettingsStorage objects for extensions.
15 class ExtensionSettings : public base::RefCountedThreadSafe<ExtensionSettings> { 25 class ExtensionSettings
26 : public base::RefCountedThreadSafe<ExtensionSettings>,
27 public SyncableService {
16 public: 28 public:
17 // File path is the base of the extension settings directory. 29 // File path is the base of the extension settings directory.
18 // The databases will be at base_path/extension_id. 30 // The databases will be at base_path/extension_id.
19 explicit ExtensionSettings(const FilePath& base_path); 31 explicit ExtensionSettings(const FilePath& base_path);
20 32
21 // Callback from the GetStorage() methods. 33 // Callback from the GetStorage() methods.
22 typedef base::Callback<void(ExtensionSettingsStorage*)> Callback; 34 typedef base::Callback<void(SyncableExtensionSettingsStorage*)> Callback;
23 35
24 // Gets the storage area for a given extension. Only valid for the duration 36 // Gets the storage area for a given extension. Only valid for the duration
25 // of the callback. 37 // of the callback.
26 // By default this will be of a cached LEVELDB storage, but on failure to 38 // By default this will be of a cached LEVELDB storage, but on failure to
27 // create a leveldb instance will fall back to cached NOOP storage. 39 // create a leveldb instance will fall back to cached NOOP storage.
28 // Callbacks will happen asynchronously regardless of whether they need to go 40 // Callbacks will happen asynchronously regardless of whether they need to go
29 // to the FILE thread, but will always be called on the UI thread. 41 // to the FILE thread, but will always be called on the UI thread.
30 void GetStorage(const std::string& extension_id, const Callback& callback); 42 void GetStorage(const std::string& extension_id, const Callback& callback);
31 43
32 // Gets a storage area for a given extension with a specific type. 44 // Gets a storage area for a given extension with a specific type.
33 // and whether it should be wrapped in a cache. 45 // and whether it should be wrapped in a cache.
34 // Use this for testing; if the given type fails to be created (e.g. if 46 // Use this for testing; if the given type fails to be created (e.g. if
35 // leveldb creation fails) then a DCHECK will fail. 47 // leveldb creation fails) then a DCHECK will fail.
36 // Callback objects will be deleted when used. 48 // Callback objects will be deleted when used.
37 void GetStorageForTesting( 49 void GetStorageForTesting(
38 ExtensionSettingsStorage::Type type, 50 ExtensionSettingsStorage::Type type,
39 bool cached, 51 bool cached,
40 const std::string& extension_id, 52 const std::string& extension_id,
41 const Callback& callback); 53 const Callback& callback);
42 54
55 // SyncableService implementation.
56 virtual SyncDataList GetAllSyncData(syncable::ModelType type) const OVERRIDE;
57 virtual SyncError MergeDataAndStartSyncing(
58 syncable::ModelType type,
59 const SyncDataList& initial_sync_data,
60 SyncChangeProcessor* sync_processor) OVERRIDE;
61 virtual SyncError ProcessSyncChanges(
62 const tracked_objects::Location& from_here,
63 const SyncChangeList& change_list) OVERRIDE;
64 virtual void StopSyncing(syncable::ModelType type) OVERRIDE;
65
43 private: 66 private:
44 friend class base::RefCountedThreadSafe<ExtensionSettings>; 67 friend class base::RefCountedThreadSafe<ExtensionSettings>;
45 ~ExtensionSettings(); 68 ~ExtensionSettings();
46 69
47 // Attempts to get and callback with an existing storage area. Returns 70 // Attempts to get and callback with an existing storage area. Returns
48 // whether storage existed and the callback run. 71 // whether storage existed and the callback run.
49 bool GetExistingStorage( 72 bool GetExistingStorage(
50 const std::string& extension_id, const Callback& callback); 73 const std::string& extension_id, const Callback& callback);
51 74
52 // Runs a Callback with a storage argument, then deletes the callback. 75 // Runs a Callback with a storage argument, then deletes the callback.
53 void RunWithStorage(Callback* callback, ExtensionSettingsStorage* storage); 76 void RunWithStorage(
77 Callback* callback, SyncableExtensionSettingsStorage* storage);
54 78
55 // Starts the process of creation of a storage area. 79 // Starts the process of creation of a storage area.
56 // Must be run on the UI thread. 80 // Must be run on the UI thread.
57 void StartCreationOfStorage( 81 void StartCreationOfStorage(
58 const std::string& extension_id, 82 const std::string& extension_id,
59 ExtensionSettingsStorage::Type type, 83 ExtensionSettingsStorage::Type type,
60 ExtensionSettingsStorage::Type fallback_type, 84 ExtensionSettingsStorage::Type fallback_type,
61 bool cached, 85 bool cached,
62 const Callback& callback); 86 const Callback& callback);
63 87
64 // Creates a new storage area of a given type, with a fallback type if 88 // Creates a new storage area of a given type, with a fallback type if
65 // creation fails, and optionally wrapped in a cache. 89 // creation fails, and optionally wrapped in a cache.
66 // Must be run on the FILE thread. 90 // Must be run on the FILE thread.
67 void CreateStorageOnFileThread( 91 void CreateStorageOnFileThread(
68 const std::string& extension_id, 92 const std::string& extension_id,
69 ExtensionSettingsStorage::Type type, 93 ExtensionSettingsStorage::Type type,
70 ExtensionSettingsStorage::Type fallback_type, 94 ExtensionSettingsStorage::Type fallback_type,
71 bool cached, 95 bool cached,
72 const Callback& callback); 96 const Callback& callback);
73 97
74 // Creates a storage area of a given type, optionally wrapped in a cache. 98 // Creates a storage area of a given type, optionally wrapped in a cache.
99 // TODO documentation
75 // Returns NULL if creation fails. 100 // Returns NULL if creation fails.
76 ExtensionSettingsStorage* CreateStorage( 101 SyncableExtensionSettingsStorage* CreateStorage(
77 const std::string& extension_id, 102 const std::string& extension_id,
78 ExtensionSettingsStorage::Type type, 103 ExtensionSettingsStorage::Type type,
79 bool cached); 104 bool cached);
80 105
81 // End the creation of a storage area. 106 // End the creation of a storage area.
82 // Must be run on the UI thread. 107 // Must be run on the UI thread.
83 void EndCreationOfStorage( 108 void EndCreationOfStorage(
84 const std::string& extension_id, 109 const std::string& extension_id,
85 ExtensionSettingsStorage* storage, 110 SyncableExtensionSettingsStorage* storage,
86 const Callback& callback); 111 const Callback& callback);
87 112
113 // Start syncing some extension settings.
114 void StartSyncingStorage(
115 const std::string& extension_id,
116 SyncableExtensionSettingsStorage* storage);
117
118 // Stop syncing some extension settings.
119 void StopSyncingStorage(ExtensionSettingsStorage* storage);
120
121 // Asserts that there is no sync data for a storage area.
122 void AssertNoSyncData(
123 const std::string& extension_id,
124 SyncableExtensionSettingsStorage* storage);
125
88 // The base file path to create any leveldb databases at. 126 // The base file path to create any leveldb databases at.
89 const FilePath base_path_; 127 const FilePath base_path_;
90 128
91 // A cache of ExtensionSettingsStorage objects that have already been created. 129 // A cache of ExtensionSettingsStorage objects that have already been created.
92 // Ensure that there is only ever one created per extension. 130 // Ensure that there is only ever one created per extension.
93 std::map<std::string, ExtensionSettingsStorage*> storage_objs_; 131 std::map<std::string, SyncableExtensionSettingsStorage*> storage_objs_;
132
133 // Sync change processor for sync.
134 SyncChangeProcessor* sync_processor_;
135
136 // Initial settings received from sync that haven't been merged into their
137 // respective storage areas. Populated in MergeDataAndStartSyncing and
138 // depopulated in StartSyncingStorage.
139 std::map<std::string, DictionaryValue*> unmerged_sync_data_;
94 140
95 DISALLOW_COPY_AND_ASSIGN(ExtensionSettings); 141 DISALLOW_COPY_AND_ASSIGN(ExtensionSettings);
96 }; 142 };
97 143
98 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_H_ 144 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_settings.cc » ('j') | chrome/browser/ui/webui/ntp/ntp_resource_cache.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698