| 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 ObserverListThreadSafe<ExtensionSettingsObserver>* observers) |
| 40 : base_path_(base_path), | 42 : base_path_(base_path), |
| 43 observers_(observers), |
| 41 sync_processor_(NULL) { | 44 sync_processor_(NULL) { |
| 42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 43 } | 46 } |
| 44 | 47 |
| 45 ExtensionSettingsBackend::~ExtensionSettingsBackend() { | 48 ExtensionSettingsBackend::~ExtensionSettingsBackend() { |
| 46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 47 } | 50 } |
| 48 | 51 |
| 49 ExtensionSettingsStorage* ExtensionSettingsBackend::GetStorage( | 52 ExtensionSettingsStorage* ExtensionSettingsBackend::GetStorage( |
| 50 const std::string& extension_id) const { | 53 const std::string& extension_id) const { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 76 storage = new InMemoryExtensionSettingsStorage(); | 79 storage = new InMemoryExtensionSettingsStorage(); |
| 77 } | 80 } |
| 78 | 81 |
| 79 // It's fine to create the quota enforcer underneath the sync later, since | 82 // 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. | 83 // sync will only go ahead if each underlying storage operation is successful. |
| 81 storage = new ExtensionSettingsStorageQuotaEnforcer( | 84 storage = new ExtensionSettingsStorageQuotaEnforcer( |
| 82 kTotalQuotaBytes, kQuotaPerSettingBytes, kMaxSettingKeys, storage); | 85 kTotalQuotaBytes, kQuotaPerSettingBytes, kMaxSettingKeys, storage); |
| 83 | 86 |
| 84 syncable_storage = | 87 syncable_storage = |
| 85 linked_ptr<SyncableExtensionSettingsStorage>( | 88 linked_ptr<SyncableExtensionSettingsStorage>( |
| 86 new SyncableExtensionSettingsStorage(extension_id, storage)); | 89 new SyncableExtensionSettingsStorage( |
| 90 observers_.get(), |
| 91 extension_id, |
| 92 storage)); |
| 87 if (sync_processor_) { | 93 if (sync_processor_) { |
| 88 // TODO(kalman): do something if StartSyncing fails. | 94 // TODO(kalman): do something if StartSyncing fails. |
| 89 ignore_result(syncable_storage->StartSyncing(sync_data, sync_processor_)); | 95 ignore_result(syncable_storage->StartSyncing(sync_data, sync_processor_)); |
| 90 } | 96 } |
| 91 | 97 |
| 92 storage_objs_[extension_id] = syncable_storage; | 98 storage_objs_[extension_id] = syncable_storage; |
| 93 return syncable_storage.get(); | 99 return syncable_storage.get(); |
| 94 } | 100 } |
| 95 | 101 |
| 102 void ExtensionSettingsBackend::TriggerOnSettingsChanged( |
| 103 Profile* profile, |
| 104 const std::string& extension_id, |
| 105 const std::string& event_json) { |
| 106 observers_->Notify( |
| 107 &ExtensionSettingsObserver::OnSettingsChanged, |
| 108 profile, |
| 109 extension_id, |
| 110 event_json); |
| 111 } |
| 112 |
| 96 std::set<std::string> ExtensionSettingsBackend::GetKnownExtensionIDs() const { | 113 std::set<std::string> ExtensionSettingsBackend::GetKnownExtensionIDs() const { |
| 97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 114 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 98 std::set<std::string> result; | 115 std::set<std::string> result; |
| 99 | 116 |
| 100 // TODO(kalman): we will need to do something to disambiguate between app | 117 // TODO(kalman): we will need to do something to disambiguate between app |
| 101 // settings and extension settings, since settings for apps should be synced | 118 // settings and extension settings, since settings for apps should be synced |
| 102 // iff app sync is turned on, ditto for extensions. | 119 // iff app sync is turned on, ditto for extensions. |
| 103 | 120 |
| 104 // Extension IDs live in-memory and/or on disk. The cache will contain all | 121 // Extension IDs live in-memory and/or on disk. The cache will contain all |
| 105 // that are in-memory. | 122 // that are in-memory. |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 void ExtensionSettingsBackend::StopSyncing(syncable::ModelType type) { | 259 void ExtensionSettingsBackend::StopSyncing(syncable::ModelType type) { |
| 243 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 244 DCHECK(sync_processor_); | 261 DCHECK(sync_processor_); |
| 245 sync_processor_ = NULL; | 262 sync_processor_ = NULL; |
| 246 | 263 |
| 247 for (StorageObjMap::iterator it = storage_objs_.begin(); | 264 for (StorageObjMap::iterator it = storage_objs_.begin(); |
| 248 it != storage_objs_.end(); ++it) { | 265 it != storage_objs_.end(); ++it) { |
| 249 it->second->StopSyncing(); | 266 it->second->StopSyncing(); |
| 250 } | 267 } |
| 251 } | 268 } |
| OLD | NEW |