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 #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 Loading... | |
| 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 Loading... | |
| 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_.get(), | |
|
akalin
2011/10/12 22:26:30
just observers_
not at google - send to devlin
2011/10/13 06:40:43
Done.
| |
| 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 |
| 103 void ExtensionSettingsBackend::TriggerOnSettingsChanged( | |
| 104 Profile* profile, | |
| 105 const std::string& extension_id, | |
| 106 const std::string& event_json) { | |
| 107 observers_->Notify( | |
| 108 &ExtensionSettingsObserver::OnSettingsChanged, | |
| 109 profile, | |
| 110 extension_id, | |
| 111 event_json); | |
| 112 } | |
| 113 | |
| 96 std::set<std::string> ExtensionSettingsBackend::GetKnownExtensionIDs() const { | 114 std::set<std::string> ExtensionSettingsBackend::GetKnownExtensionIDs() const { |
| 97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 115 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 98 std::set<std::string> result; | 116 std::set<std::string> result; |
| 99 | 117 |
| 100 // TODO(kalman): we will need to do something to disambiguate between app | 118 // TODO(kalman): we will need to do something to disambiguate between app |
| 101 // settings and extension settings, since settings for apps should be synced | 119 // settings and extension settings, since settings for apps should be synced |
| 102 // iff app sync is turned on, ditto for extensions. | 120 // iff app sync is turned on, ditto for extensions. |
| 103 | 121 |
| 104 // Extension IDs live in-memory and/or on disk. The cache will contain all | 122 // Extension IDs live in-memory and/or on disk. The cache will contain all |
| 105 // that are in-memory. | 123 // that are in-memory. |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 void ExtensionSettingsBackend::StopSyncing(syncable::ModelType type) { | 260 void ExtensionSettingsBackend::StopSyncing(syncable::ModelType type) { |
| 243 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 261 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 244 DCHECK(sync_processor_); | 262 DCHECK(sync_processor_); |
| 245 sync_processor_ = NULL; | 263 sync_processor_ = NULL; |
| 246 | 264 |
| 247 for (StorageObjMap::iterator it = storage_objs_.begin(); | 265 for (StorageObjMap::iterator it = storage_objs_.begin(); |
| 248 it != storage_objs_.end(); ++it) { | 266 it != storage_objs_.end(); ++it) { |
| 249 it->second->StopSyncing(); | 267 it->second->StopSyncing(); |
| 250 } | 268 } |
| 251 } | 269 } |
| OLD | NEW |