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 "sync/syncable/syncable_id.h" | 5 #include "sync/syncable/syncable_id.h" |
| 6 | 6 |
| 7 #include <iosfwd> | 7 #include <iosfwd> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 // Currently root is the string "0". We need to decide on a true value. | 28 // Currently root is the string "0". We need to decide on a true value. |
| 29 // "" would be convenient here, as the IsRoot call would not be needed. | 29 // "" would be convenient here, as the IsRoot call would not be needed. |
| 30 DCHECK(!IsNull()); | 30 DCHECK(!IsNull()); |
| 31 if (IsRoot()) | 31 if (IsRoot()) |
| 32 return "0"; | 32 return "0"; |
| 33 return s_.substr(1); | 33 return s_.substr(1); |
| 34 } | 34 } |
| 35 | 35 |
| 36 Id Id::CreateFromServerId(const string& server_id) { | 36 Id Id::CreateFromServerId(const string& server_id) { |
| 37 Id id; | 37 Id id; |
| 38 if (server_id == "0") | 38 if (!server_id.empty()) { |
|
Nicolas Zea
2015/01/26 23:21:53
This just for testing right? Or was there another
stanisc
2015/01/28 07:30:06
Once the server transition is done, most of parent
| |
| 39 id.s_ = "r"; | 39 if (server_id == "0") |
| 40 else | 40 id.s_ = "r"; |
| 41 id.s_ = string("s") + server_id; | 41 else |
| 42 id.s_ = string("s") + server_id; | |
| 43 } | |
| 42 return id; | 44 return id; |
| 43 } | 45 } |
| 44 | 46 |
| 45 Id Id::CreateFromClientString(const string& local_id) { | 47 Id Id::CreateFromClientString(const string& local_id) { |
| 46 Id id; | 48 Id id; |
| 47 if (local_id == "0") | 49 if (!local_id.empty()) { |
| 48 id.s_ = "r"; | 50 if (local_id == "0") |
| 49 else | 51 id.s_ = "r"; |
| 50 id.s_ = string("c") + local_id; | 52 else |
| 53 id.s_ = string("c") + local_id; | |
| 54 } | |
| 51 return id; | 55 return id; |
| 52 } | 56 } |
| 53 | 57 |
| 54 Id Id::GetRoot() { | 58 Id Id::GetRoot() { |
| 55 Id id; | 59 Id id; |
| 56 id.s_ = "r"; | 60 id.s_ = "r"; |
| 57 return id; | 61 return id; |
| 58 } | 62 } |
| 59 | 63 |
| 60 Id Id::GetLexicographicSuccessor() const { | 64 Id Id::GetLexicographicSuccessor() const { |
| 61 // The successor of a string is given by appending the least | 65 // The successor of a string is given by appending the least |
| 62 // character in the alphabet. | 66 // character in the alphabet. |
| 63 Id id = *this; | 67 Id id = *this; |
| 64 id.s_.push_back(0); | 68 id.s_.push_back(0); |
| 65 return id; | 69 return id; |
| 66 } | 70 } |
| 67 | 71 |
| 68 // static | 72 // static |
| 69 Id Id::GetLeastIdForLexicographicComparison() { | 73 Id Id::GetLeastIdForLexicographicComparison() { |
| 70 Id id; | 74 Id id; |
| 71 id.s_.clear(); | 75 id.s_.clear(); |
| 72 return id; | 76 return id; |
| 73 } | 77 } |
| 74 | 78 |
| 75 } // namespace syncable | 79 } // namespace syncable |
| 76 } // namespace syncer | 80 } // namespace syncer |
| OLD | NEW |