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

Side by Side Diff: components/sync_driver/local_device_info_provider_impl.cc

Issue 1951703002: [Sync] Clear LocalDeviceInfoProvider cache on sync DB destruction. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move NonThreadSafe to LocalDeviceInfoProviderImpl. Created 4 years, 7 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
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_driver/local_device_info_provider_impl.h" 5 #include "components/sync_driver/local_device_info_provider_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/task_runner.h" 8 #include "base/task_runner.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "components/sync_driver/sync_util.h" 10 #include "components/sync_driver/sync_util.h"
(...skipping 22 matching lines...) Expand all
33 33
34 } // namespace 34 } // namespace
35 35
36 LocalDeviceInfoProviderImpl::LocalDeviceInfoProviderImpl( 36 LocalDeviceInfoProviderImpl::LocalDeviceInfoProviderImpl(
37 version_info::Channel channel, 37 version_info::Channel channel,
38 const std::string& version, 38 const std::string& version,
39 bool is_tablet) 39 bool is_tablet)
40 : channel_(channel), 40 : channel_(channel),
41 version_(version), 41 version_(version),
42 is_tablet_(is_tablet), 42 is_tablet_(is_tablet),
43 weak_factory_(this) {} 43 weak_factory_(this) {
44 DCHECK(CalledOnValidThread());
45 }
44 46
45 LocalDeviceInfoProviderImpl::~LocalDeviceInfoProviderImpl() {} 47 LocalDeviceInfoProviderImpl::~LocalDeviceInfoProviderImpl() {}
46 48
47 const sync_driver::DeviceInfo* LocalDeviceInfoProviderImpl::GetLocalDeviceInfo() 49 const sync_driver::DeviceInfo* LocalDeviceInfoProviderImpl::GetLocalDeviceInfo()
48 const { 50 const {
51 DCHECK(CalledOnValidThread());
49 return local_device_info_.get(); 52 return local_device_info_.get();
50 } 53 }
51 54
52 std::string LocalDeviceInfoProviderImpl::GetSyncUserAgent() const { 55 std::string LocalDeviceInfoProviderImpl::GetSyncUserAgent() const {
56 DCHECK(CalledOnValidThread());
53 #if defined(OS_CHROMEOS) 57 #if defined(OS_CHROMEOS)
54 return MakeUserAgentForSync("CROS ", channel_); 58 return MakeUserAgentForSync("CROS ", channel_);
55 #elif defined(OS_ANDROID) 59 #elif defined(OS_ANDROID)
56 if (is_tablet_) { 60 if (is_tablet_) {
57 return MakeUserAgentForSync("ANDROID-TABLET ", channel_); 61 return MakeUserAgentForSync("ANDROID-TABLET ", channel_);
58 } else { 62 } else {
59 return MakeUserAgentForSync("ANDROID-PHONE ", channel_); 63 return MakeUserAgentForSync("ANDROID-PHONE ", channel_);
60 } 64 }
61 #elif defined(OS_IOS) 65 #elif defined(OS_IOS)
62 if (is_tablet_) { 66 if (is_tablet_) {
63 return MakeUserAgentForSync("IOS-TABLET ", channel_); 67 return MakeUserAgentForSync("IOS-TABLET ", channel_);
64 } else { 68 } else {
65 return MakeUserAgentForSync("IOS-PHONE ", channel_); 69 return MakeUserAgentForSync("IOS-PHONE ", channel_);
66 } 70 }
67 #else 71 #else
68 return MakeDesktopUserAgentForSync(channel_); 72 return MakeDesktopUserAgentForSync(channel_);
69 #endif 73 #endif
70 } 74 }
71 75
72 std::string LocalDeviceInfoProviderImpl::GetLocalSyncCacheGUID() const { 76 std::string LocalDeviceInfoProviderImpl::GetLocalSyncCacheGUID() const {
77 DCHECK(CalledOnValidThread());
73 return cache_guid_; 78 return cache_guid_;
74 } 79 }
75 80
76 std::unique_ptr<sync_driver::LocalDeviceInfoProvider::Subscription> 81 std::unique_ptr<sync_driver::LocalDeviceInfoProvider::Subscription>
77 LocalDeviceInfoProviderImpl::RegisterOnInitializedCallback( 82 LocalDeviceInfoProviderImpl::RegisterOnInitializedCallback(
78 const base::Closure& callback) { 83 const base::Closure& callback) {
84 DCHECK(CalledOnValidThread());
79 DCHECK(!local_device_info_.get()); 85 DCHECK(!local_device_info_.get());
80 return callback_list_.Add(callback); 86 return callback_list_.Add(callback);
81 } 87 }
82 88
83 void LocalDeviceInfoProviderImpl::Initialize( 89 void LocalDeviceInfoProviderImpl::Initialize(
84 const std::string& cache_guid, 90 const std::string& cache_guid,
85 const std::string& signin_scoped_device_id, 91 const std::string& signin_scoped_device_id,
86 const scoped_refptr<base::TaskRunner>& blocking_task_runner) { 92 const scoped_refptr<base::TaskRunner>& blocking_task_runner) {
93 DCHECK(CalledOnValidThread());
87 DCHECK(!cache_guid.empty()); 94 DCHECK(!cache_guid.empty());
88 cache_guid_ = cache_guid; 95 cache_guid_ = cache_guid;
89 96
90 syncer::GetSessionName( 97 syncer::GetSessionName(
91 blocking_task_runner, 98 blocking_task_runner,
92 base::Bind(&LocalDeviceInfoProviderImpl::InitializeContinuation, 99 base::Bind(&LocalDeviceInfoProviderImpl::InitializeContinuation,
93 weak_factory_.GetWeakPtr(), cache_guid, 100 weak_factory_.GetWeakPtr(), cache_guid,
94 signin_scoped_device_id)); 101 signin_scoped_device_id));
95 } 102 }
96 103
97 void LocalDeviceInfoProviderImpl::InitializeContinuation( 104 void LocalDeviceInfoProviderImpl::InitializeContinuation(
98 const std::string& guid, 105 const std::string& guid,
99 const std::string& signin_scoped_device_id, 106 const std::string& signin_scoped_device_id,
100 const std::string& session_name) { 107 const std::string& session_name) {
108 DCHECK(CalledOnValidThread());
109 if (guid != cache_guid_) {
110 // Clear() happened before this callback; abort.
111 return;
112 }
113
101 local_device_info_.reset(new sync_driver::DeviceInfo( 114 local_device_info_.reset(new sync_driver::DeviceInfo(
102 guid, session_name, version_, GetSyncUserAgent(), 115 guid, session_name, version_, GetSyncUserAgent(),
103 GetLocalDeviceType(is_tablet_), signin_scoped_device_id)); 116 GetLocalDeviceType(is_tablet_), signin_scoped_device_id));
104 117
105 // Notify observers. 118 // Notify observers.
106 callback_list_.Notify(); 119 callback_list_.Notify();
107 } 120 }
108 121
122 void LocalDeviceInfoProviderImpl::Clear() {
123 DCHECK(CalledOnValidThread());
124 cache_guid_ = "";
125 local_device_info_.reset();
126 }
127
109 } // namespace browser_sync 128 } // namespace browser_sync
OLDNEW
« no previous file with comments | « components/sync_driver/local_device_info_provider_impl.h ('k') | components/sync_driver/local_device_info_provider_mock.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698