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

Side by Side Diff: chrome/browser/sync/glue/synced_device_tracker.cc

Issue 332923002: [sync] Add backup time in synced device info so that server can flag device (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: check db on DB thread Created 6 years, 5 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 | Annotate | Revision Log
OLDNEW
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/sync/glue/synced_device_tracker.h" 5 #include "chrome/browser/sync/glue/synced_device_tracker.h"
6 6
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/sync/glue/device_info.h" 9 #include "chrome/browser/sync/glue/device_info.h"
10 #include "sync/internal_api/public/base/model_type.h" 10 #include "sync/internal_api/public/base/model_type.h"
11 #include "sync/internal_api/public/read_node.h" 11 #include "sync/internal_api/public/read_node.h"
12 #include "sync/internal_api/public/read_transaction.h" 12 #include "sync/internal_api/public/read_transaction.h"
13 #include "sync/internal_api/public/user_share.h" 13 #include "sync/internal_api/public/user_share.h"
14 #include "sync/internal_api/public/write_node.h" 14 #include "sync/internal_api/public/write_node.h"
15 #include "sync/internal_api/public/write_transaction.h" 15 #include "sync/internal_api/public/write_transaction.h"
16 #include "sync/util/time.h"
16 17
17 namespace browser_sync { 18 namespace browser_sync {
18 19
19 namespace { 20 namespace {
20 21
21 // Return the DeviceInfo UNIQUE_CLIENT_TAG value for the given sync cache_guid. 22 // Return the DeviceInfo UNIQUE_CLIENT_TAG value for the given sync cache_guid.
22 std::string DeviceInfoLookupString(const std::string& cache_guid) { 23 std::string DeviceInfoLookupString(const std::string& cache_guid) {
23 return base::StringPrintf("DeviceInfo_%s", cache_guid.c_str()); 24 return base::StringPrintf("DeviceInfo_%s", cache_guid.c_str());
24 } 25 }
25 26
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 weak_factory_.GetWeakPtr(), callback)); 151 weak_factory_.GetWeakPtr(), callback));
151 } 152 }
152 153
153 void SyncedDeviceTracker::InitLocalDeviceInfoContinuation( 154 void SyncedDeviceTracker::InitLocalDeviceInfoContinuation(
154 const base::Closure& callback, const DeviceInfo& local_info) { 155 const base::Closure& callback, const DeviceInfo& local_info) {
155 WriteLocalDeviceInfo(local_info); 156 WriteLocalDeviceInfo(local_info);
156 callback.Run(); 157 callback.Run();
157 } 158 }
158 159
159 void SyncedDeviceTracker::WriteLocalDeviceInfo(const DeviceInfo& info) { 160 void SyncedDeviceTracker::WriteLocalDeviceInfo(const DeviceInfo& info) {
161 DCHECK_EQ(cache_guid_, info.guid());
162 WriteDeviceInfo(info, local_device_info_tag_);
163 }
164
165 void SyncedDeviceTracker::WriteDeviceInfo(const DeviceInfo& info,
166 const std::string& tag) {
167 syncer::WriteTransaction trans(FROM_HERE, user_share_);
168 syncer::WriteNode node(&trans);
169
160 sync_pb::DeviceInfoSpecifics specifics; 170 sync_pb::DeviceInfoSpecifics specifics;
161 DCHECK_EQ(cache_guid_, info.guid()); 171 specifics.set_cache_guid(info.guid());
162 specifics.set_cache_guid(cache_guid_);
163 specifics.set_client_name(info.client_name()); 172 specifics.set_client_name(info.client_name());
164 specifics.set_chrome_version(info.chrome_version()); 173 specifics.set_chrome_version(info.chrome_version());
165 specifics.set_sync_user_agent(info.sync_user_agent()); 174 specifics.set_sync_user_agent(info.sync_user_agent());
166 specifics.set_device_type(info.device_type()); 175 specifics.set_device_type(info.device_type());
167 176
168 WriteDeviceInfo(specifics, local_device_info_tag_);
169 }
170
171 void SyncedDeviceTracker::WriteDeviceInfo(
172 const sync_pb::DeviceInfoSpecifics& specifics,
173 const std::string& tag) {
174 syncer::WriteTransaction trans(FROM_HERE, user_share_);
175 syncer::WriteNode node(&trans);
176
177 if (node.InitByClientTagLookup(syncer::DEVICE_INFO, tag) == 177 if (node.InitByClientTagLookup(syncer::DEVICE_INFO, tag) ==
178 syncer::BaseNode::INIT_OK) { 178 syncer::BaseNode::INIT_OK) {
179 const sync_pb::DeviceInfoSpecifics& sync_specifics =
180 node.GetDeviceInfoSpecifics();
181 if (sync_specifics.has_backup_timestamp())
182 specifics.set_backup_timestamp(sync_specifics.backup_timestamp());
179 node.SetDeviceInfoSpecifics(specifics); 183 node.SetDeviceInfoSpecifics(specifics);
180 node.SetTitle(specifics.client_name()); 184 node.SetTitle(specifics.client_name());
181 } else { 185 } else {
182 syncer::ReadNode type_root(&trans); 186 syncer::ReadNode type_root(&trans);
183 syncer::BaseNode::InitByLookupResult type_root_lookup_result = 187 syncer::BaseNode::InitByLookupResult type_root_lookup_result =
184 type_root.InitTypeRoot(syncer::DEVICE_INFO); 188 type_root.InitTypeRoot(syncer::DEVICE_INFO);
185 DCHECK_EQ(syncer::BaseNode::INIT_OK, type_root_lookup_result); 189 DCHECK_EQ(syncer::BaseNode::INIT_OK, type_root_lookup_result);
186 190
187 syncer::WriteNode new_node(&trans); 191 syncer::WriteNode new_node(&trans);
188 syncer::WriteNode::InitUniqueByCreationResult create_result = 192 syncer::WriteNode::InitUniqueByCreationResult create_result =
189 new_node.InitUniqueByCreation(syncer::DEVICE_INFO, 193 new_node.InitUniqueByCreation(syncer::DEVICE_INFO,
190 type_root, 194 type_root,
191 tag); 195 tag);
192 DCHECK_EQ(syncer::WriteNode::INIT_SUCCESS, create_result); 196 DCHECK_EQ(syncer::WriteNode::INIT_SUCCESS, create_result);
193 new_node.SetDeviceInfoSpecifics(specifics); 197 new_node.SetDeviceInfoSpecifics(specifics);
194 new_node.SetTitle(specifics.client_name()); 198 new_node.SetTitle(specifics.client_name());
195 } 199 }
196 } 200 }
197 201
202 void SyncedDeviceTracker::UpdateLocalDeviceBackupTime(base::Time backup_time) {
203 syncer::WriteTransaction trans(FROM_HERE, user_share_);
204 syncer::WriteNode node(&trans);
205
206 if (node.InitByClientTagLookup(syncer::DEVICE_INFO, local_device_info_tag_)
207 == syncer::BaseNode::INIT_OK) {
208 sync_pb::DeviceInfoSpecifics specifics = node.GetDeviceInfoSpecifics();
209 int64 new_backup_timestamp = syncer::TimeToProtoTime(backup_time);
210 if (!specifics.has_backup_timestamp() ||
211 specifics.backup_timestamp() != new_backup_timestamp) {
212 specifics.set_backup_timestamp(new_backup_timestamp);
213 node.SetDeviceInfoSpecifics(specifics);
214 }
215 }
216 }
217
218 base::Time SyncedDeviceTracker::GetLocalDeviceBackupTime() const {
219 syncer::ReadTransaction trans(FROM_HERE, user_share_);
220 syncer::ReadNode node(&trans);
221 if (node.InitByClientTagLookup(syncer::DEVICE_INFO, local_device_info_tag_)
222 == syncer::BaseNode::INIT_OK &&
223 node.GetDeviceInfoSpecifics().has_backup_timestamp()) {
224 return syncer::ProtoTimeToTime(
225 node.GetDeviceInfoSpecifics().backup_timestamp());
226 } else {
227 return base::Time();
228 }
229 }
230
198 } // namespace browser_sync 231 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/synced_device_tracker.h ('k') | chrome/browser/sync/glue/synced_device_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698