OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/internal_api/base_node.h" | 5 #include "chrome/browser/sync/internal_api/base_node.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/sha1.h" | 8 #include "base/sha1.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/browser/sync/engine/syncapi_internal.h" | 12 #include "chrome/browser/sync/engine/syncapi_internal.h" |
13 #include "chrome/browser/sync/internal_api/base_transaction.h" | 13 #include "chrome/browser/sync/internal_api/base_transaction.h" |
14 #include "chrome/browser/sync/protocol/app_specifics.pb.h" | 14 #include "chrome/browser/sync/protocol/app_specifics.pb.h" |
15 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" | 15 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" |
16 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" | 16 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" |
17 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" | 17 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" |
18 #include "chrome/browser/sync/protocol/nigori_specifics.pb.h" | 18 #include "chrome/browser/sync/protocol/nigori_specifics.pb.h" |
19 #include "chrome/browser/sync/protocol/password_specifics.pb.h" | 19 #include "chrome/browser/sync/protocol/password_specifics.pb.h" |
20 #include "chrome/browser/sync/protocol/session_specifics.pb.h" | 20 #include "chrome/browser/sync/protocol/session_specifics.pb.h" |
21 #include "chrome/browser/sync/protocol/theme_specifics.pb.h" | 21 #include "chrome/browser/sync/protocol/theme_specifics.pb.h" |
22 #include "chrome/browser/sync/protocol/typed_url_specifics.pb.h" | 22 #include "chrome/browser/sync/protocol/typed_url_specifics.pb.h" |
23 #include "chrome/browser/sync/syncable/directory_manager.h" | 23 #include "chrome/browser/sync/syncable/directory_manager.h" |
24 #include "chrome/browser/sync/syncable/syncable.h" | 24 #include "chrome/browser/sync/syncable/syncable.h" |
25 #include "chrome/browser/sync/syncable/syncable_id.h" | 25 #include "chrome/browser/sync/syncable/syncable_id.h" |
| 26 #include "chrome/browser/sync/util/time.h" |
26 | 27 |
27 using syncable::SPECIFICS; | 28 using syncable::SPECIFICS; |
28 using sync_pb::AutofillProfileSpecifics; | 29 using sync_pb::AutofillProfileSpecifics; |
29 | 30 |
30 namespace sync_api { | 31 namespace sync_api { |
31 | 32 |
32 // Helper function to look up the int64 metahandle of an object given the ID | 33 // Helper function to look up the int64 metahandle of an object given the ID |
33 // string. | 34 // string. |
34 static int64 IdToMetahandle(syncable::BaseTransaction* trans, | 35 static int64 IdToMetahandle(syncable::BaseTransaction* trans, |
35 const syncable::Id& id) { | 36 const syncable::Id& id) { |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 | 168 |
168 int64 BaseNode::GetParentId() const { | 169 int64 BaseNode::GetParentId() const { |
169 return IdToMetahandle(GetTransaction()->GetWrappedTrans(), | 170 return IdToMetahandle(GetTransaction()->GetWrappedTrans(), |
170 GetEntry()->Get(syncable::PARENT_ID)); | 171 GetEntry()->Get(syncable::PARENT_ID)); |
171 } | 172 } |
172 | 173 |
173 int64 BaseNode::GetId() const { | 174 int64 BaseNode::GetId() const { |
174 return GetEntry()->Get(syncable::META_HANDLE); | 175 return GetEntry()->Get(syncable::META_HANDLE); |
175 } | 176 } |
176 | 177 |
177 int64 BaseNode::GetModificationTime() const { | 178 const base::Time& BaseNode::GetModificationTime() const { |
178 return GetEntry()->Get(syncable::MTIME); | 179 return GetEntry()->Get(syncable::MTIME); |
179 } | 180 } |
180 | 181 |
181 bool BaseNode::GetIsFolder() const { | 182 bool BaseNode::GetIsFolder() const { |
182 return GetEntry()->Get(syncable::IS_DIR); | 183 return GetEntry()->Get(syncable::IS_DIR); |
183 } | 184 } |
184 | 185 |
185 std::string BaseNode::GetTitle() const { | 186 std::string BaseNode::GetTitle() const { |
186 std::string result; | 187 std::string result; |
187 // TODO(zea): refactor bookmarks to not need this functionality. | 188 // TODO(zea): refactor bookmarks to not need this functionality. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 DictionaryValue* node_info = new DictionaryValue(); | 229 DictionaryValue* node_info = new DictionaryValue(); |
229 node_info->SetString("id", base::Int64ToString(GetId())); | 230 node_info->SetString("id", base::Int64ToString(GetId())); |
230 node_info->SetBoolean("isFolder", GetIsFolder()); | 231 node_info->SetBoolean("isFolder", GetIsFolder()); |
231 node_info->SetString("title", GetTitle()); | 232 node_info->SetString("title", GetTitle()); |
232 node_info->Set("type", ModelTypeToValue(GetModelType())); | 233 node_info->Set("type", ModelTypeToValue(GetModelType())); |
233 return node_info; | 234 return node_info; |
234 } | 235 } |
235 | 236 |
236 DictionaryValue* BaseNode::GetDetailsAsValue() const { | 237 DictionaryValue* BaseNode::GetDetailsAsValue() const { |
237 DictionaryValue* node_info = GetSummaryAsValue(); | 238 DictionaryValue* node_info = GetSummaryAsValue(); |
238 // TODO(akalin): Return time in a better format. | 239 node_info->SetString( |
239 node_info->SetString("modificationTime", | 240 "modificationTime", |
240 base::Int64ToString(GetModificationTime())); | 241 browser_sync::GetTimeDebugString(GetModificationTime())); |
241 node_info->SetString("parentId", base::Int64ToString(GetParentId())); | 242 node_info->SetString("parentId", base::Int64ToString(GetParentId())); |
242 // Specifics are already in the Entry value, so no need to duplicate | 243 // Specifics are already in the Entry value, so no need to duplicate |
243 // it here. | 244 // it here. |
244 node_info->SetString("externalId", | 245 node_info->SetString("externalId", |
245 base::Int64ToString(GetExternalId())); | 246 base::Int64ToString(GetExternalId())); |
246 node_info->SetString("predecessorId", | 247 node_info->SetString("predecessorId", |
247 base::Int64ToString(GetPredecessorId())); | 248 base::Int64ToString(GetPredecessorId())); |
248 node_info->SetString("successorId", | 249 node_info->SetString("successorId", |
249 base::Int64ToString(GetSuccessorId())); | 250 base::Int64ToString(GetSuccessorId())); |
250 node_info->SetString("firstChildId", | 251 node_info->SetString("firstChildId", |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 const sync_pb::EntitySpecifics& specifics) { | 329 const sync_pb::EntitySpecifics& specifics) { |
329 syncable::ModelType type = syncable::GetModelTypeFromSpecifics(specifics); | 330 syncable::ModelType type = syncable::GetModelTypeFromSpecifics(specifics); |
330 DCHECK_NE(syncable::UNSPECIFIED, type); | 331 DCHECK_NE(syncable::UNSPECIFIED, type); |
331 if (GetModelType() != syncable::UNSPECIFIED) { | 332 if (GetModelType() != syncable::UNSPECIFIED) { |
332 DCHECK_EQ(GetModelType(), type); | 333 DCHECK_EQ(GetModelType(), type); |
333 } | 334 } |
334 unencrypted_data_.CopyFrom(specifics); | 335 unencrypted_data_.CopyFrom(specifics); |
335 } | 336 } |
336 | 337 |
337 } // namespace sync_api | 338 } // namespace sync_api |
OLD | NEW |