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