OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/api/storage/syncable_settings_storage.h" | 5 #include "chrome/browser/extensions/api/storage/syncable_settings_storage.h" |
6 | 6 |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "chrome/browser/extensions/api/storage/settings_namespace.h" | 8 #include "chrome/browser/extensions/api/storage/settings_namespace.h" |
9 #include "chrome/browser/extensions/api/storage/settings_sync_processor.h" | 9 #include "chrome/browser/extensions/api/storage/settings_sync_processor.h" |
10 #include "chrome/browser/extensions/api/storage/settings_sync_util.h" | 10 #include "chrome/browser/extensions/api/storage/settings_sync_util.h" |
11 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
12 #include "sync/api/sync_data.h" | 12 #include "sync/api/sync_data.h" |
13 #include "sync/protocol/extension_setting_specifics.pb.h" | 13 #include "sync/protocol/extension_setting_specifics.pb.h" |
14 | 14 |
15 namespace extensions { | 15 namespace extensions { |
16 | 16 |
17 using content::BrowserThread; | 17 using content::BrowserThread; |
18 | 18 |
19 SyncableSettingsStorage::SyncableSettingsStorage( | 19 SyncableSettingsStorage::SyncableSettingsStorage( |
20 const scoped_refptr<ObserverListThreadSafe<SettingsObserver> >& | 20 const scoped_refptr<ObserverListThreadSafe<SettingsObserver> >& |
21 observers, | 21 observers, |
22 const std::string& extension_id, | 22 const std::string& extension_id, |
23 ValueStore* delegate) | 23 ValueStore* delegate, |
24 syncer::ModelType sync_type, | |
25 const syncer::SyncableService::StartSyncFlare& flare) | |
24 : observers_(observers), | 26 : observers_(observers), |
25 extension_id_(extension_id), | 27 extension_id_(extension_id), |
26 delegate_(delegate) { | 28 delegate_(delegate), |
29 sync_type_(sync_type), | |
30 flare_(flare) { | |
27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
28 } | 32 } |
29 | 33 |
30 SyncableSettingsStorage::~SyncableSettingsStorage() { | 34 SyncableSettingsStorage::~SyncableSettingsStorage() { |
31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
32 } | 36 } |
33 | 37 |
34 size_t SyncableSettingsStorage::GetBytesInUse(const std::string& key) { | 38 size_t SyncableSettingsStorage::GetBytesInUse(const std::string& key) { |
35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
36 return delegate_->GetBytesInUse(key); | 40 return delegate_->GetBytesInUse(key); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 WriteResult result = delegate_->Clear(); | 117 WriteResult result = delegate_->Clear(); |
114 if (result->HasError()) { | 118 if (result->HasError()) { |
115 return result.Pass(); | 119 return result.Pass(); |
116 } | 120 } |
117 SyncResultIfEnabled(result); | 121 SyncResultIfEnabled(result); |
118 return result.Pass(); | 122 return result.Pass(); |
119 } | 123 } |
120 | 124 |
121 void SyncableSettingsStorage::SyncResultIfEnabled( | 125 void SyncableSettingsStorage::SyncResultIfEnabled( |
122 const ValueStore::WriteResult& result) { | 126 const ValueStore::WriteResult& result) { |
123 if (sync_processor_.get() && !result->changes().empty()) { | 127 if (result->changes().empty()) |
128 return; | |
129 | |
130 if (sync_processor_.get()) { | |
124 syncer::SyncError error = sync_processor_->SendChanges(result->changes()); | 131 syncer::SyncError error = sync_processor_->SendChanges(result->changes()); |
125 if (error.IsSet()) | 132 if (error.IsSet()) |
126 StopSyncing(); | 133 StopSyncing(); |
134 } else { | |
135 // Tell sync to try and start soon, because syncable changes to sync_type_ | |
136 // have started happening. This will cause sync to call us back | |
137 // asynchronously via StartSyncing(...) as soon as possible. | |
138 flare_.Run(sync_type_); | |
not at google - send to devlin
2014/01/15 18:39:46
and it's ok to ignore the changes here because one
| |
127 } | 139 } |
128 } | 140 } |
129 | 141 |
130 // Sync-related methods. | 142 // Sync-related methods. |
131 | 143 |
132 syncer::SyncError SyncableSettingsStorage::StartSyncing( | 144 syncer::SyncError SyncableSettingsStorage::StartSyncing( |
133 const base::DictionaryValue& sync_state, | 145 const base::DictionaryValue& sync_state, |
134 scoped_ptr<SettingsSyncProcessor> sync_processor) { | 146 scoped_ptr<SettingsSyncProcessor> sync_processor) { |
135 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
136 DCHECK(!sync_processor_.get()); | 148 DCHECK(!sync_processor_.get()); |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
382 syncer::SyncError::DATATYPE_ERROR, | 394 syncer::SyncError::DATATYPE_ERROR, |
383 base::StringPrintf("Error pushing sync remove to local settings: %s", | 395 base::StringPrintf("Error pushing sync remove to local settings: %s", |
384 result->error().message.c_str()), | 396 result->error().message.c_str()), |
385 sync_processor_->type()); | 397 sync_processor_->type()); |
386 } | 398 } |
387 changes->push_back(ValueStoreChange(key, old_value, NULL)); | 399 changes->push_back(ValueStoreChange(key, old_value, NULL)); |
388 return syncer::SyncError(); | 400 return syncer::SyncError(); |
389 } | 401 } |
390 | 402 |
391 } // namespace extensions | 403 } // namespace extensions |
OLD | NEW |