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/engine/syncapi.h" | 5 #include "chrome/browser/sync/engine/syncapi.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <bitset> | 8 #include <bitset> |
9 #include <iomanip> | 9 #include <iomanip> |
10 #include <list> | 10 #include <list> |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 std::string* out) { | 173 std::string* out) { |
174 *out = WideToUTF8(sync_api_name); | 174 *out = WideToUTF8(sync_api_name); |
175 if (IsNameServerIllegalAfterTrimming(*out)) | 175 if (IsNameServerIllegalAfterTrimming(*out)) |
176 out->append(" "); | 176 out->append(" "); |
177 } | 177 } |
178 | 178 |
179 // In the reverse direction, if a server name matches the pattern of a | 179 // In the reverse direction, if a server name matches the pattern of a |
180 // server-illegal name followed by one or more spaces, remove the trailing | 180 // server-illegal name followed by one or more spaces, remove the trailing |
181 // space. | 181 // space. |
182 static void ServerNameToSyncAPIName(const std::string& server_name, | 182 static void ServerNameToSyncAPIName(const std::string& server_name, |
183 std::wstring* out) { | 183 std::string* out) { |
| 184 CHECK(out); |
184 int length_to_copy = server_name.length(); | 185 int length_to_copy = server_name.length(); |
185 if (IsNameServerIllegalAfterTrimming(server_name) && | 186 if (IsNameServerIllegalAfterTrimming(server_name) && |
186 EndsWithSpace(server_name)) { | 187 EndsWithSpace(server_name)) { |
187 --length_to_copy; | 188 --length_to_copy; |
188 } | 189 } |
189 if (!UTF8ToWide(server_name.c_str(), length_to_copy, out)) { | 190 *out = std::string(server_name.c_str(), length_to_copy); |
190 NOTREACHED() << "Could not convert server name from UTF8 to wide"; | |
191 } | |
192 } | 191 } |
193 | 192 |
194 // Compare the values of two EntitySpecifics, accounting for encryption. | 193 // Compare the values of two EntitySpecifics, accounting for encryption. |
195 static bool AreSpecificsEqual(const browser_sync::Cryptographer* cryptographer, | 194 static bool AreSpecificsEqual(const browser_sync::Cryptographer* cryptographer, |
196 const sync_pb::EntitySpecifics& left, | 195 const sync_pb::EntitySpecifics& left, |
197 const sync_pb::EntitySpecifics& right) { | 196 const sync_pb::EntitySpecifics& right) { |
198 // Note that we can't compare encrypted strings directly as they are seeded | 197 // Note that we can't compare encrypted strings directly as they are seeded |
199 // with a random value. | 198 // with a random value. |
200 std::string left_plaintext, right_plaintext; | 199 std::string left_plaintext, right_plaintext; |
201 if (left.has_encrypted()) { | 200 if (left.has_encrypted()) { |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 } | 361 } |
363 | 362 |
364 int64 BaseNode::GetModificationTime() const { | 363 int64 BaseNode::GetModificationTime() const { |
365 return GetEntry()->Get(syncable::MTIME); | 364 return GetEntry()->Get(syncable::MTIME); |
366 } | 365 } |
367 | 366 |
368 bool BaseNode::GetIsFolder() const { | 367 bool BaseNode::GetIsFolder() const { |
369 return GetEntry()->Get(syncable::IS_DIR); | 368 return GetEntry()->Get(syncable::IS_DIR); |
370 } | 369 } |
371 | 370 |
372 std::wstring BaseNode::GetTitle() const { | 371 std::string BaseNode::GetTitle() const { |
373 std::wstring result; | 372 std::string result; |
374 // TODO(zea): refactor bookmarks to not need this functionality. | 373 // TODO(zea): refactor bookmarks to not need this functionality. |
375 if (syncable::BOOKMARKS == GetModelType() && | 374 if (syncable::BOOKMARKS == GetModelType() && |
376 GetEntry()->Get(syncable::SPECIFICS).has_encrypted()) { | 375 GetEntry()->Get(syncable::SPECIFICS).has_encrypted()) { |
377 // Special case for legacy bookmarks dealing with encryption. | 376 // Special case for legacy bookmarks dealing with encryption. |
378 ServerNameToSyncAPIName(GetBookmarkSpecifics().title(), &result); | 377 ServerNameToSyncAPIName(GetBookmarkSpecifics().title(), &result); |
379 } else { | 378 } else { |
380 ServerNameToSyncAPIName(GetEntry()->Get(syncable::NON_UNIQUE_NAME), | 379 ServerNameToSyncAPIName(GetEntry()->Get(syncable::NON_UNIQUE_NAME), |
381 &result); | 380 &result); |
382 } | 381 } |
383 return result; | 382 return result; |
384 } | 383 } |
385 | 384 |
386 GURL BaseNode::GetURL() const { | 385 GURL BaseNode::GetURL() const { |
387 return GURL(GetBookmarkSpecifics().url()); | 386 return GURL(GetBookmarkSpecifics().url()); |
388 } | 387 } |
389 | 388 |
390 int64 BaseNode::GetPredecessorId() const { | 389 int64 BaseNode::GetPredecessorId() const { |
391 syncable::Id id_string = GetEntry()->Get(syncable::PREV_ID); | 390 syncable::Id id_string = GetEntry()->Get(syncable::PREV_ID); |
(...skipping 16 matching lines...) Expand all Loading... |
408 dir->GetFirstChildId(trans, GetEntry()->Get(syncable::ID)); | 407 dir->GetFirstChildId(trans, GetEntry()->Get(syncable::ID)); |
409 if (id_string.IsRoot()) | 408 if (id_string.IsRoot()) |
410 return kInvalidId; | 409 return kInvalidId; |
411 return IdToMetahandle(GetTransaction()->GetWrappedTrans(), id_string); | 410 return IdToMetahandle(GetTransaction()->GetWrappedTrans(), id_string); |
412 } | 411 } |
413 | 412 |
414 DictionaryValue* BaseNode::GetSummaryAsValue() const { | 413 DictionaryValue* BaseNode::GetSummaryAsValue() const { |
415 DictionaryValue* node_info = new DictionaryValue(); | 414 DictionaryValue* node_info = new DictionaryValue(); |
416 node_info->SetString("id", base::Int64ToString(GetId())); | 415 node_info->SetString("id", base::Int64ToString(GetId())); |
417 node_info->SetBoolean("isFolder", GetIsFolder()); | 416 node_info->SetBoolean("isFolder", GetIsFolder()); |
418 // TODO(akalin): Add a std::string accessor for the title. | 417 node_info->SetString("title", GetTitle()); |
419 node_info->SetString("title", WideToUTF8(GetTitle())); | |
420 node_info->Set("type", ModelTypeToValue(GetModelType())); | 418 node_info->Set("type", ModelTypeToValue(GetModelType())); |
421 return node_info; | 419 return node_info; |
422 } | 420 } |
423 | 421 |
424 DictionaryValue* BaseNode::GetDetailsAsValue() const { | 422 DictionaryValue* BaseNode::GetDetailsAsValue() const { |
425 DictionaryValue* node_info = GetSummaryAsValue(); | 423 DictionaryValue* node_info = GetSummaryAsValue(); |
426 // TODO(akalin): Return time in a better format. | 424 // TODO(akalin): Return time in a better format. |
427 node_info->SetString("modificationTime", | 425 node_info->SetString("modificationTime", |
428 base::Int64ToString(GetModificationTime())); | 426 base::Int64ToString(GetModificationTime())); |
429 node_info->SetString("parentId", base::Int64ToString(GetParentId())); | 427 node_info->SetString("parentId", base::Int64ToString(GetParentId())); |
(...skipping 2644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3074 void SyncManager::TriggerOnIncomingNotificationForTest( | 3072 void SyncManager::TriggerOnIncomingNotificationForTest( |
3075 const syncable::ModelTypeBitSet& model_types) { | 3073 const syncable::ModelTypeBitSet& model_types) { |
3076 syncable::ModelTypePayloadMap model_types_with_payloads = | 3074 syncable::ModelTypePayloadMap model_types_with_payloads = |
3077 syncable::ModelTypePayloadMapFromBitSet(model_types, | 3075 syncable::ModelTypePayloadMapFromBitSet(model_types, |
3078 std::string()); | 3076 std::string()); |
3079 | 3077 |
3080 data_->OnIncomingNotification(model_types_with_payloads); | 3078 data_->OnIncomingNotification(model_types_with_payloads); |
3081 } | 3079 } |
3082 | 3080 |
3083 } // namespace sync_api | 3081 } // namespace sync_api |
OLD | NEW |