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

Side by Side Diff: components/sync/device_info/device_info_service.cc

Issue 2455693002: [Sync] On disabling sync, device info records are removed. (Closed)
Patch Set: Updates for Max. Created 4 years, 1 month 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/sync/device_info/device_info_service.h" 5 #include "components/sync/device_info/device_info_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 std::string DeviceInfoService::GetClientTag(const EntityData& entity_data) { 173 std::string DeviceInfoService::GetClientTag(const EntityData& entity_data) {
174 DCHECK(entity_data.specifics.has_device_info()); 174 DCHECK(entity_data.specifics.has_device_info());
175 return DeviceInfoUtil::SpecificsToTag(entity_data.specifics.device_info()); 175 return DeviceInfoUtil::SpecificsToTag(entity_data.specifics.device_info());
176 } 176 }
177 177
178 std::string DeviceInfoService::GetStorageKey(const EntityData& entity_data) { 178 std::string DeviceInfoService::GetStorageKey(const EntityData& entity_data) {
179 DCHECK(entity_data.specifics.has_device_info()); 179 DCHECK(entity_data.specifics.has_device_info());
180 return entity_data.specifics.device_info().cache_guid(); 180 return entity_data.specifics.device_info().cache_guid();
181 } 181 }
182 182
183 void DeviceInfoService::DisableSync() {
184 // TODO(skym, crbug.com/659263): Would it be reasonable to pulse_timer_.Stop()
185 // or subscription_.reset() here?
186
187 // Allow deletion of metadata to happen before the deletion of data below. If
188 // we crash after removing metadata but not regular data, then merge can
189 // handle pairing everything back up.
190 ModelTypeService::DisableSync();
191
192 // Remove all local data, if sync is being disabled, the user has expressed
193 // their desire to not have knowledge about other devices.
194 if (!all_data_.empty()) {
195 std::unique_ptr<WriteBatch> batch = store_->CreateWriteBatch();
196 for (const auto& kv : all_data_) {
197 store_->DeleteData(batch.get(), kv.first);
198 }
199 store_->CommitWriteBatch(
200 std::move(batch),
201 base::Bind(&DeviceInfoService::OnCommit, base::AsWeakPtr(this)));
202
203 all_data_.clear();
204 NotifyObservers();
205 }
206 }
207
183 bool DeviceInfoService::IsSyncing() const { 208 bool DeviceInfoService::IsSyncing() const {
184 return !all_data_.empty(); 209 return !all_data_.empty();
185 } 210 }
186 211
187 std::unique_ptr<DeviceInfo> DeviceInfoService::GetDeviceInfo( 212 std::unique_ptr<DeviceInfo> DeviceInfoService::GetDeviceInfo(
188 const std::string& client_id) const { 213 const std::string& client_id) const {
189 const ClientIdToSpecifics::const_iterator iter = all_data_.find(client_id); 214 const ClientIdToSpecifics::const_iterator iter = all_data_.find(client_id);
190 if (iter == all_data_.end()) { 215 if (iter == all_data_.end()) {
191 return std::unique_ptr<DeviceInfo>(); 216 return std::unique_ptr<DeviceInfo>();
192 } 217 }
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 Time DeviceInfoService::GetLastUpdateTime( 496 Time DeviceInfoService::GetLastUpdateTime(
472 const DeviceInfoSpecifics& specifics) { 497 const DeviceInfoSpecifics& specifics) {
473 if (specifics.has_last_updated_timestamp()) { 498 if (specifics.has_last_updated_timestamp()) {
474 return ProtoTimeToTime(specifics.last_updated_timestamp()); 499 return ProtoTimeToTime(specifics.last_updated_timestamp());
475 } else { 500 } else {
476 return Time(); 501 return Time();
477 } 502 }
478 } 503 }
479 504
480 } // namespace syncer 505 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/device_info/device_info_service.h ('k') | components/sync/device_info/device_info_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698