| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 61 |
| 62 scoped_ptr<DeviceInfo> SyncedDeviceTracker::ReadLocalDeviceInfo( | 62 scoped_ptr<DeviceInfo> SyncedDeviceTracker::ReadLocalDeviceInfo( |
| 63 const syncer::BaseTransaction& trans) const { | 63 const syncer::BaseTransaction& trans) const { |
| 64 syncer::ReadNode node(&trans); | 64 syncer::ReadNode node(&trans); |
| 65 if (node.InitByClientTagLookup(syncer::DEVICE_INFO, local_device_info_tag_) != | 65 if (node.InitByClientTagLookup(syncer::DEVICE_INFO, local_device_info_tag_) != |
| 66 syncer::BaseNode::INIT_OK) { | 66 syncer::BaseNode::INIT_OK) { |
| 67 return scoped_ptr<DeviceInfo>(); | 67 return scoped_ptr<DeviceInfo>(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 const sync_pb::DeviceInfoSpecifics& specifics = node.GetDeviceInfoSpecifics(); | 70 const sync_pb::DeviceInfoSpecifics& specifics = node.GetDeviceInfoSpecifics(); |
| 71 return scoped_ptr<DeviceInfo> ( | 71 return scoped_ptr<DeviceInfo>( |
| 72 new DeviceInfo(specifics.cache_guid(), | 72 new DeviceInfo(specifics.cache_guid(), |
| 73 specifics.client_name(), | 73 specifics.client_name(), |
| 74 specifics.chrome_version(), | 74 specifics.chrome_version(), |
| 75 specifics.sync_user_agent(), | 75 specifics.sync_user_agent(), |
| 76 specifics.device_type())); | 76 specifics.device_type(), |
| 77 specifics.signin_scoped_device_id())); |
| 77 } | 78 } |
| 78 | 79 |
| 79 scoped_ptr<DeviceInfo> SyncedDeviceTracker::ReadDeviceInfo( | 80 scoped_ptr<DeviceInfo> SyncedDeviceTracker::ReadDeviceInfo( |
| 80 const std::string& client_id) const { | 81 const std::string& client_id) const { |
| 81 syncer::ReadTransaction trans(FROM_HERE, user_share_); | 82 syncer::ReadTransaction trans(FROM_HERE, user_share_); |
| 82 syncer::ReadNode node(&trans); | 83 syncer::ReadNode node(&trans); |
| 83 std::string lookup_string = DeviceInfoLookupString(client_id); | 84 std::string lookup_string = DeviceInfoLookupString(client_id); |
| 84 if (node.InitByClientTagLookup(syncer::DEVICE_INFO, lookup_string) != | 85 if (node.InitByClientTagLookup(syncer::DEVICE_INFO, lookup_string) != |
| 85 syncer::BaseNode::INIT_OK) { | 86 syncer::BaseNode::INIT_OK) { |
| 86 return scoped_ptr<DeviceInfo>(); | 87 return scoped_ptr<DeviceInfo>(); |
| 87 } | 88 } |
| 88 | 89 |
| 89 const sync_pb::DeviceInfoSpecifics& specifics = node.GetDeviceInfoSpecifics(); | 90 const sync_pb::DeviceInfoSpecifics& specifics = node.GetDeviceInfoSpecifics(); |
| 90 return scoped_ptr<DeviceInfo> ( | 91 return scoped_ptr<DeviceInfo>( |
| 91 new DeviceInfo(specifics.cache_guid(), | 92 new DeviceInfo(specifics.cache_guid(), |
| 92 specifics.client_name(), | 93 specifics.client_name(), |
| 93 specifics.chrome_version(), | 94 specifics.chrome_version(), |
| 94 specifics.sync_user_agent(), | 95 specifics.sync_user_agent(), |
| 95 specifics.device_type())); | 96 specifics.device_type(), |
| 97 specifics.signin_scoped_device_id())); |
| 96 } | 98 } |
| 97 | 99 |
| 98 void SyncedDeviceTracker::GetAllSyncedDeviceInfo( | 100 void SyncedDeviceTracker::GetAllSyncedDeviceInfo( |
| 99 ScopedVector<DeviceInfo>* device_info) const { | 101 ScopedVector<DeviceInfo>* device_info) const { |
| 100 if (device_info == NULL) | 102 if (device_info == NULL) |
| 101 return; | 103 return; |
| 102 | 104 |
| 103 device_info->clear(); | 105 device_info->clear(); |
| 104 | 106 |
| 105 syncer::ReadTransaction trans(FROM_HERE, user_share_); | 107 syncer::ReadTransaction trans(FROM_HERE, user_share_); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 116 root_node.GetChildIds(&children); | 118 root_node.GetChildIds(&children); |
| 117 | 119 |
| 118 for (std::vector<int64>::const_iterator it = children.begin(); | 120 for (std::vector<int64>::const_iterator it = children.begin(); |
| 119 it != children.end(); ++it) { | 121 it != children.end(); ++it) { |
| 120 syncer::ReadNode node(&trans); | 122 syncer::ReadNode node(&trans); |
| 121 if (node.InitByIdLookup(*it) != syncer::BaseNode::INIT_OK) | 123 if (node.InitByIdLookup(*it) != syncer::BaseNode::INIT_OK) |
| 122 return; | 124 return; |
| 123 | 125 |
| 124 const sync_pb::DeviceInfoSpecifics& specifics = | 126 const sync_pb::DeviceInfoSpecifics& specifics = |
| 125 node.GetDeviceInfoSpecifics(); | 127 node.GetDeviceInfoSpecifics(); |
| 126 device_info->push_back( | 128 device_info->push_back(new DeviceInfo(specifics.cache_guid(), |
| 127 new DeviceInfo(specifics.cache_guid(), | 129 specifics.client_name(), |
| 128 specifics.client_name(), | 130 specifics.chrome_version(), |
| 129 specifics.chrome_version(), | 131 specifics.sync_user_agent(), |
| 130 specifics.sync_user_agent(), | 132 specifics.device_type(), |
| 131 specifics.device_type())); | 133 specifics.signin_scoped_device_id())); |
| 132 } | 134 } |
| 133 } | 135 } |
| 134 | 136 |
| 135 std::string SyncedDeviceTracker::cache_guid() const { | 137 std::string SyncedDeviceTracker::cache_guid() const { |
| 136 return cache_guid_; | 138 return cache_guid_; |
| 137 } | 139 } |
| 138 | 140 |
| 139 void SyncedDeviceTracker::AddObserver(Observer* observer) { | 141 void SyncedDeviceTracker::AddObserver(Observer* observer) { |
| 140 observers_->AddObserver(observer); | 142 observers_->AddObserver(observer); |
| 141 } | 143 } |
| 142 | 144 |
| 143 void SyncedDeviceTracker::RemoveObserver(Observer* observer) { | 145 void SyncedDeviceTracker::RemoveObserver(Observer* observer) { |
| 144 observers_->RemoveObserver(observer); | 146 observers_->RemoveObserver(observer); |
| 145 } | 147 } |
| 146 | 148 |
| 147 void SyncedDeviceTracker::InitLocalDeviceInfo(const base::Closure& callback) { | 149 void SyncedDeviceTracker::InitLocalDeviceInfo( |
| 150 const std::string& signin_scoped_device_id, |
| 151 const base::Closure& callback) { |
| 148 DeviceInfo::CreateLocalDeviceInfo( | 152 DeviceInfo::CreateLocalDeviceInfo( |
| 149 cache_guid_, | 153 cache_guid_, |
| 154 signin_scoped_device_id, |
| 150 base::Bind(&SyncedDeviceTracker::InitLocalDeviceInfoContinuation, | 155 base::Bind(&SyncedDeviceTracker::InitLocalDeviceInfoContinuation, |
| 151 weak_factory_.GetWeakPtr(), callback)); | 156 weak_factory_.GetWeakPtr(), |
| 157 callback)); |
| 152 } | 158 } |
| 153 | 159 |
| 154 void SyncedDeviceTracker::InitLocalDeviceInfoContinuation( | 160 void SyncedDeviceTracker::InitLocalDeviceInfoContinuation( |
| 155 const base::Closure& callback, const DeviceInfo& local_info) { | 161 const base::Closure& callback, const DeviceInfo& local_info) { |
| 156 WriteLocalDeviceInfo(local_info); | 162 WriteLocalDeviceInfo(local_info); |
| 157 callback.Run(); | 163 callback.Run(); |
| 158 } | 164 } |
| 159 | 165 |
| 160 void SyncedDeviceTracker::WriteLocalDeviceInfo(const DeviceInfo& info) { | 166 void SyncedDeviceTracker::WriteLocalDeviceInfo(const DeviceInfo& info) { |
| 161 DCHECK_EQ(cache_guid_, info.guid()); | 167 DCHECK_EQ(cache_guid_, info.guid()); |
| 162 WriteDeviceInfo(info, local_device_info_tag_); | 168 WriteDeviceInfo(info, local_device_info_tag_); |
| 163 } | 169 } |
| 164 | 170 |
| 165 void SyncedDeviceTracker::WriteDeviceInfo(const DeviceInfo& info, | 171 void SyncedDeviceTracker::WriteDeviceInfo(const DeviceInfo& info, |
| 166 const std::string& tag) { | 172 const std::string& tag) { |
| 167 syncer::WriteTransaction trans(FROM_HERE, user_share_); | 173 syncer::WriteTransaction trans(FROM_HERE, user_share_); |
| 168 syncer::WriteNode node(&trans); | 174 syncer::WriteNode node(&trans); |
| 169 | 175 |
| 170 sync_pb::DeviceInfoSpecifics specifics; | 176 sync_pb::DeviceInfoSpecifics specifics; |
| 171 specifics.set_cache_guid(info.guid()); | 177 specifics.set_cache_guid(info.guid()); |
| 172 specifics.set_client_name(info.client_name()); | 178 specifics.set_client_name(info.client_name()); |
| 173 specifics.set_chrome_version(info.chrome_version()); | 179 specifics.set_chrome_version(info.chrome_version()); |
| 174 specifics.set_sync_user_agent(info.sync_user_agent()); | 180 specifics.set_sync_user_agent(info.sync_user_agent()); |
| 175 specifics.set_device_type(info.device_type()); | 181 specifics.set_device_type(info.device_type()); |
| 182 specifics.set_signin_scoped_device_id(info.signin_scoped_device_id()); |
| 176 | 183 |
| 177 if (node.InitByClientTagLookup(syncer::DEVICE_INFO, tag) == | 184 if (node.InitByClientTagLookup(syncer::DEVICE_INFO, tag) == |
| 178 syncer::BaseNode::INIT_OK) { | 185 syncer::BaseNode::INIT_OK) { |
| 179 const sync_pb::DeviceInfoSpecifics& sync_specifics = | 186 const sync_pb::DeviceInfoSpecifics& sync_specifics = |
| 180 node.GetDeviceInfoSpecifics(); | 187 node.GetDeviceInfoSpecifics(); |
| 181 if (sync_specifics.has_backup_timestamp()) | 188 if (sync_specifics.has_backup_timestamp()) |
| 182 specifics.set_backup_timestamp(sync_specifics.backup_timestamp()); | 189 specifics.set_backup_timestamp(sync_specifics.backup_timestamp()); |
| 183 node.SetDeviceInfoSpecifics(specifics); | 190 node.SetDeviceInfoSpecifics(specifics); |
| 184 node.SetTitle(specifics.client_name()); | 191 node.SetTitle(specifics.client_name()); |
| 185 } else { | 192 } else { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 == syncer::BaseNode::INIT_OK && | 229 == syncer::BaseNode::INIT_OK && |
| 223 node.GetDeviceInfoSpecifics().has_backup_timestamp()) { | 230 node.GetDeviceInfoSpecifics().has_backup_timestamp()) { |
| 224 return syncer::ProtoTimeToTime( | 231 return syncer::ProtoTimeToTime( |
| 225 node.GetDeviceInfoSpecifics().backup_timestamp()); | 232 node.GetDeviceInfoSpecifics().backup_timestamp()); |
| 226 } else { | 233 } else { |
| 227 return base::Time(); | 234 return base::Time(); |
| 228 } | 235 } |
| 229 } | 236 } |
| 230 | 237 |
| 231 } // namespace browser_sync | 238 } // namespace browser_sync |
| OLD | NEW |