Chromium Code Reviews| 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/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" |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 weak_factory_.GetWeakPtr(), callback)); | 150 weak_factory_.GetWeakPtr(), callback)); |
| 151 } | 151 } |
| 152 | 152 |
| 153 void SyncedDeviceTracker::InitLocalDeviceInfoContinuation( | 153 void SyncedDeviceTracker::InitLocalDeviceInfoContinuation( |
| 154 const base::Closure& callback, const DeviceInfo& local_info) { | 154 const base::Closure& callback, const DeviceInfo& local_info) { |
| 155 WriteLocalDeviceInfo(local_info); | 155 WriteLocalDeviceInfo(local_info); |
| 156 callback.Run(); | 156 callback.Run(); |
| 157 } | 157 } |
| 158 | 158 |
| 159 void SyncedDeviceTracker::WriteLocalDeviceInfo(const DeviceInfo& info) { | 159 void SyncedDeviceTracker::WriteLocalDeviceInfo(const DeviceInfo& info) { |
| 160 DCHECK_EQ(cache_guid_, info.guid()); | |
| 161 WriteDeviceInfo(info, local_device_info_tag_); | |
| 162 } | |
| 163 | |
| 164 void SyncedDeviceTracker::WriteDeviceInfo(const DeviceInfo& info, | |
| 165 const std::string& tag) { | |
| 166 syncer::WriteTransaction trans(FROM_HERE, user_share_); | |
| 167 syncer::WriteNode node(&trans); | |
| 168 | |
| 160 sync_pb::DeviceInfoSpecifics specifics; | 169 sync_pb::DeviceInfoSpecifics specifics; |
| 161 DCHECK_EQ(cache_guid_, info.guid()); | 170 specifics.set_cache_guid(info.guid()); |
| 162 specifics.set_cache_guid(cache_guid_); | |
| 163 specifics.set_client_name(info.client_name()); | 171 specifics.set_client_name(info.client_name()); |
| 164 specifics.set_chrome_version(info.chrome_version()); | 172 specifics.set_chrome_version(info.chrome_version()); |
| 165 specifics.set_sync_user_agent(info.sync_user_agent()); | 173 specifics.set_sync_user_agent(info.sync_user_agent()); |
| 166 specifics.set_device_type(info.device_type()); | 174 specifics.set_device_type(info.device_type()); |
| 167 | 175 |
| 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) == | 176 if (node.InitByClientTagLookup(syncer::DEVICE_INFO, tag) == |
| 178 syncer::BaseNode::INIT_OK) { | 177 syncer::BaseNode::INIT_OK) { |
| 178 const sync_pb::DeviceInfoSpecifics& sync_specifics = | |
| 179 node.GetDeviceInfoSpecifics(); | |
| 180 if (sync_specifics.has_backup_timestamp()) | |
| 181 specifics.set_backup_timestamp(sync_specifics.backup_timestamp()); | |
| 179 node.SetDeviceInfoSpecifics(specifics); | 182 node.SetDeviceInfoSpecifics(specifics); |
| 180 node.SetTitle(specifics.client_name()); | 183 node.SetTitle(specifics.client_name()); |
| 181 } else { | 184 } else { |
| 182 syncer::ReadNode type_root(&trans); | 185 syncer::ReadNode type_root(&trans); |
| 183 syncer::BaseNode::InitByLookupResult type_root_lookup_result = | 186 syncer::BaseNode::InitByLookupResult type_root_lookup_result = |
| 184 type_root.InitTypeRoot(syncer::DEVICE_INFO); | 187 type_root.InitTypeRoot(syncer::DEVICE_INFO); |
| 185 DCHECK_EQ(syncer::BaseNode::INIT_OK, type_root_lookup_result); | 188 DCHECK_EQ(syncer::BaseNode::INIT_OK, type_root_lookup_result); |
| 186 | 189 |
| 187 syncer::WriteNode new_node(&trans); | 190 syncer::WriteNode new_node(&trans); |
| 188 syncer::WriteNode::InitUniqueByCreationResult create_result = | 191 syncer::WriteNode::InitUniqueByCreationResult create_result = |
| 189 new_node.InitUniqueByCreation(syncer::DEVICE_INFO, | 192 new_node.InitUniqueByCreation(syncer::DEVICE_INFO, |
| 190 type_root, | 193 type_root, |
| 191 tag); | 194 tag); |
| 192 DCHECK_EQ(syncer::WriteNode::INIT_SUCCESS, create_result); | 195 DCHECK_EQ(syncer::WriteNode::INIT_SUCCESS, create_result); |
| 193 new_node.SetDeviceInfoSpecifics(specifics); | 196 new_node.SetDeviceInfoSpecifics(specifics); |
| 194 new_node.SetTitle(specifics.client_name()); | 197 new_node.SetTitle(specifics.client_name()); |
| 195 } | 198 } |
| 196 } | 199 } |
| 197 | 200 |
| 201 void SyncedDeviceTracker::UpdateLocalDeviceBackupTime(base::Time backup_time) { | |
| 202 syncer::WriteTransaction trans(FROM_HERE, user_share_); | |
| 203 syncer::WriteNode node(&trans); | |
| 204 | |
| 205 if (node.InitByClientTagLookup(syncer::DEVICE_INFO, local_device_info_tag_) | |
| 206 == syncer::BaseNode::INIT_OK) { | |
| 207 sync_pb::DeviceInfoSpecifics specifics = node.GetDeviceInfoSpecifics(); | |
| 208 if (!specifics.has_backup_timestamp() || | |
| 209 specifics.backup_timestamp() != backup_time.ToInternalValue()) { | |
| 210 specifics.set_backup_timestamp(backup_time.ToInternalValue()); | |
|
Nicolas Zea
2014/06/13 22:36:41
ToInternalValue uses the windows epoch. It's proba
haitaol1
2014/06/13 23:28:25
Done.
| |
| 211 node.SetDeviceInfoSpecifics(specifics); | |
| 212 } | |
| 213 } | |
| 214 } | |
| 215 | |
| 216 base::Time SyncedDeviceTracker::GetLocalDeviceBackupTime() const { | |
| 217 syncer::ReadTransaction trans(FROM_HERE, user_share_); | |
| 218 syncer::ReadNode node(&trans); | |
| 219 if (node.InitByClientTagLookup(syncer::DEVICE_INFO, local_device_info_tag_) | |
| 220 == syncer::BaseNode::INIT_OK && | |
| 221 node.GetDeviceInfoSpecifics().has_backup_timestamp()) { | |
| 222 return base::Time::FromInternalValue( | |
| 223 node.GetDeviceInfoSpecifics().backup_timestamp()); | |
| 224 } else { | |
| 225 return base::Time(); | |
| 226 } | |
| 227 } | |
| 228 | |
| 198 } // namespace browser_sync | 229 } // namespace browser_sync |
| OLD | NEW |