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

Side by Side Diff: chrome/browser/extensions/extension_settings_backend.cc

Issue 8361027: Re-commit 106660 with the crashing test disabled. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 9 years, 2 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 #include "chrome/browser/extensions/extension_settings_backend.h" 5 #include "chrome/browser/extensions/extension_settings_backend.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 18 matching lines...) Expand all
29 29
30 // Quota for each setting. Sync supports 5k per setting, so be a bit more 30 // Quota for each setting. Sync supports 5k per setting, so be a bit more
31 // restrictive than that. 31 // restrictive than that.
32 const size_t kQuotaPerSettingBytes = 2048; 32 const size_t kQuotaPerSettingBytes = 2048;
33 33
34 // Max number of settings per extension. Keep low for sync. 34 // Max number of settings per extension. Keep low for sync.
35 const size_t kMaxSettingKeys = 512; 35 const size_t kMaxSettingKeys = 512;
36 36
37 } // namespace 37 } // namespace
38 38
39 ExtensionSettingsBackend::ExtensionSettingsBackend(const FilePath& base_path) 39 ExtensionSettingsBackend::ExtensionSettingsBackend(
40 const FilePath& base_path,
41 const scoped_refptr<ObserverListThreadSafe<ExtensionSettingsObserver> >&
42 observers)
40 : base_path_(base_path), 43 : base_path_(base_path),
44 observers_(observers),
41 sync_processor_(NULL) { 45 sync_processor_(NULL) {
42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
43 } 47 }
44 48
45 ExtensionSettingsBackend::~ExtensionSettingsBackend() { 49 ExtensionSettingsBackend::~ExtensionSettingsBackend() {
46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
47 } 51 }
48 52
49 ExtensionSettingsStorage* ExtensionSettingsBackend::GetStorage( 53 ExtensionSettingsStorage* ExtensionSettingsBackend::GetStorage(
50 const std::string& extension_id) const { 54 const std::string& extension_id) const {
(...skipping 25 matching lines...) Expand all
76 storage = new InMemoryExtensionSettingsStorage(); 80 storage = new InMemoryExtensionSettingsStorage();
77 } 81 }
78 82
79 // It's fine to create the quota enforcer underneath the sync later, since 83 // It's fine to create the quota enforcer underneath the sync later, since
80 // sync will only go ahead if each underlying storage operation is successful. 84 // sync will only go ahead if each underlying storage operation is successful.
81 storage = new ExtensionSettingsStorageQuotaEnforcer( 85 storage = new ExtensionSettingsStorageQuotaEnforcer(
82 kTotalQuotaBytes, kQuotaPerSettingBytes, kMaxSettingKeys, storage); 86 kTotalQuotaBytes, kQuotaPerSettingBytes, kMaxSettingKeys, storage);
83 87
84 syncable_storage = 88 syncable_storage =
85 linked_ptr<SyncableExtensionSettingsStorage>( 89 linked_ptr<SyncableExtensionSettingsStorage>(
86 new SyncableExtensionSettingsStorage(extension_id, storage)); 90 new SyncableExtensionSettingsStorage(
91 observers_,
92 extension_id,
93 storage));
87 if (sync_processor_) { 94 if (sync_processor_) {
88 // TODO(kalman): do something if StartSyncing fails. 95 // TODO(kalman): do something if StartSyncing fails.
89 ignore_result(syncable_storage->StartSyncing(sync_data, sync_processor_)); 96 ignore_result(syncable_storage->StartSyncing(sync_data, sync_processor_));
90 } 97 }
91 98
92 storage_objs_[extension_id] = syncable_storage; 99 storage_objs_[extension_id] = syncable_storage;
93 return syncable_storage.get(); 100 return syncable_storage.get();
94 } 101 }
95 102
96 void ExtensionSettingsBackend::DeleteExtensionData( 103 void ExtensionSettingsBackend::DeleteExtensionData(
97 const std::string& extension_id) { 104 const std::string& extension_id) {
98 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
99 StorageObjMap::iterator maybe_storage = storage_objs_.find(extension_id); 106 StorageObjMap::iterator maybe_storage = storage_objs_.find(extension_id);
100 if (maybe_storage == storage_objs_.end()) { 107 if (maybe_storage == storage_objs_.end()) {
101 return; 108 return;
102 } 109 }
103 110
104 // Clear settings when the extension is uninstalled. Leveldb implementations 111 // Clear settings when the extension is uninstalled. Leveldb implementations
105 // will also delete the database from disk when the object is destroyed as 112 // will also delete the database from disk when the object is destroyed as
106 // a result of being removed from |storage_objs_|. 113 // a result of being removed from |storage_objs_|.
107 maybe_storage->second->Clear(); 114 maybe_storage->second->Clear();
108 storage_objs_.erase(maybe_storage); 115 storage_objs_.erase(maybe_storage);
109 } 116 }
110 117
118 void ExtensionSettingsBackend::TriggerOnSettingsChanged(
119 Profile* profile,
120 const std::string& extension_id,
121 const ExtensionSettingChanges& changes) const {
122 observers_->Notify(
123 &ExtensionSettingsObserver::OnSettingsChanged,
124 profile,
125 extension_id,
126 changes);
127 }
128
111 std::set<std::string> ExtensionSettingsBackend::GetKnownExtensionIDs() const { 129 std::set<std::string> ExtensionSettingsBackend::GetKnownExtensionIDs() const {
112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
113 std::set<std::string> result; 131 std::set<std::string> result;
114 132
115 // TODO(kalman): we will need to do something to disambiguate between app 133 // TODO(kalman): we will need to do something to disambiguate between app
116 // settings and extension settings, since settings for apps should be synced 134 // settings and extension settings, since settings for apps should be synced
117 // iff app sync is turned on, ditto for extensions. 135 // iff app sync is turned on, ditto for extensions.
118 136
119 // Extension IDs live in-memory and/or on disk. The cache will contain all 137 // Extension IDs live in-memory and/or on disk. The cache will contain all
120 // that are in-memory. 138 // that are in-memory.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 172
155 for (std::set<std::string>::const_iterator it = known_extension_ids.begin(); 173 for (std::set<std::string>::const_iterator it = known_extension_ids.begin();
156 it != known_extension_ids.end(); ++it) { 174 it != known_extension_ids.end(); ++it) {
157 ExtensionSettingsStorage::Result maybe_settings = GetStorage(*it)->Get(); 175 ExtensionSettingsStorage::Result maybe_settings = GetStorage(*it)->Get();
158 if (maybe_settings.HasError()) { 176 if (maybe_settings.HasError()) {
159 LOG(WARNING) << "Failed to get settings for " << *it << ": " << 177 LOG(WARNING) << "Failed to get settings for " << *it << ": " <<
160 maybe_settings.GetError(); 178 maybe_settings.GetError();
161 continue; 179 continue;
162 } 180 }
163 181
164 DictionaryValue* settings = maybe_settings.GetSettings(); 182 const DictionaryValue* settings = maybe_settings.GetSettings();
165 for (DictionaryValue::key_iterator key_it = settings->begin_keys(); 183 for (DictionaryValue::key_iterator key_it = settings->begin_keys();
166 key_it != settings->end_keys(); ++key_it) { 184 key_it != settings->end_keys(); ++key_it) {
167 Value *value = NULL; 185 Value *value = NULL;
168 settings->GetWithoutPathExpansion(*key_it, &value); 186 settings->GetWithoutPathExpansion(*key_it, &value);
169 all_sync_data.push_back( 187 all_sync_data.push_back(
170 extension_settings_sync_util::CreateData(*it, *key_it, *value)); 188 extension_settings_sync_util::CreateData(*it, *key_it, *value));
171 } 189 }
172 } 190 }
173 191
174 return all_sync_data; 192 return all_sync_data;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 void ExtensionSettingsBackend::StopSyncing(syncable::ModelType type) { 275 void ExtensionSettingsBackend::StopSyncing(syncable::ModelType type) {
258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
259 DCHECK(sync_processor_); 277 DCHECK(sync_processor_);
260 sync_processor_ = NULL; 278 sync_processor_ = NULL;
261 279
262 for (StorageObjMap::iterator it = storage_objs_.begin(); 280 for (StorageObjMap::iterator it = storage_objs_.begin();
263 it != storage_objs_.end(); ++it) { 281 it != storage_objs_.end(); ++it) {
264 it->second->StopSyncing(); 282 it->second->StopSyncing();
265 } 283 }
266 } 284 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_settings_backend.h ('k') | chrome/browser/extensions/extension_settings_frontend.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698