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

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

Issue 2810873005: [Sync] Always check the device info provider for being null before using it. (Closed)
Patch Set: Created 3 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_sync_service.h" 5 #include "components/sync/device_info/device_info_sync_service.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <utility> 10 #include <utility>
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 } 278 }
279 } 279 }
280 280
281 void DeviceInfoSyncService::SendLocalData( 281 void DeviceInfoSyncService::SendLocalData(
282 const SyncChange::SyncChangeType change_type) { 282 const SyncChange::SyncChangeType change_type) {
283 DCHECK_NE(change_type, SyncChange::ACTION_INVALID); 283 DCHECK_NE(change_type, SyncChange::ACTION_INVALID);
284 DCHECK(sync_processor_); 284 DCHECK(sync_processor_);
285 285
286 const DeviceInfo* device_info = 286 const DeviceInfo* device_info =
287 local_device_info_provider_->GetLocalDeviceInfo(); 287 local_device_info_provider_->GetLocalDeviceInfo();
288 const SyncData& data = CreateLocalData(device_info);
289 StoreSyncData(device_info->guid(), data);
290 288
291 SyncChangeList change_list; 289 // While the |pulse_timer_| is shutdown eventually in StopSyncing(), our
292 change_list.push_back(SyncChange(FROM_HERE, change_type, data)); 290 // device info provider is ripped out from underneath us before that happens,
293 sync_processor_->ProcessSyncChanges(FROM_HERE, change_list); 291 // and we need to guard against this.
292 if (device_info != nullptr) {
293 const SyncData& data = CreateLocalData(device_info);
294 StoreSyncData(device_info->guid(), data);
295
296 SyncChangeList change_list;
297 change_list.push_back(SyncChange(FROM_HERE, change_type, data));
298 sync_processor_->ProcessSyncChanges(FROM_HERE, change_list);
299 }
294 300
295 pulse_timer_.Start( 301 pulse_timer_.Start(
296 FROM_HERE, DeviceInfoUtil::kPulseInterval, 302 FROM_HERE, DeviceInfoUtil::kPulseInterval,
297 base::Bind(&DeviceInfoSyncService::SendLocalData, base::Unretained(this), 303 base::Bind(&DeviceInfoSyncService::SendLocalData, base::Unretained(this),
298 SyncChange::ACTION_UPDATE)); 304 SyncChange::ACTION_UPDATE));
299 } 305 }
300 306
301 int DeviceInfoSyncService::CountActiveDevices(const Time now) const { 307 int DeviceInfoSyncService::CountActiveDevices(const Time now) const {
302 return std::count_if(all_data_.begin(), all_data_.end(), 308 return std::count_if(all_data_.begin(), all_data_.end(),
303 [now](SyncDataMap::const_reference pair) { 309 [now](SyncDataMap::const_reference pair) {
(...skipping 12 matching lines...) Expand all
316 return SyncDataRemote(device_info).GetModifiedTime(); 322 return SyncDataRemote(device_info).GetModifiedTime();
317 } else { 323 } else {
318 // We shouldn't reach this point for remote data, so this means we're likely 324 // We shouldn't reach this point for remote data, so this means we're likely
319 // looking at the local device info. Using a long ago time is perfect, since 325 // looking at the local device info. Using a long ago time is perfect, since
320 // the desired behavior is to update/pulse our data as soon as possible. 326 // the desired behavior is to update/pulse our data as soon as possible.
321 return Time(); 327 return Time();
322 } 328 }
323 } 329 }
324 330
325 } // namespace syncer 331 } // namespace syncer
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698