Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(595)

Side by Side Diff: sync/syncable/syncable_id.cc

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sync/syncable/syncable_id.h ('k') | sync/syncable/syncable_id_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "sync/syncable/syncable_id.h"
6
7 #include <iosfwd>
8
9 #include "base/logging.h"
10 #include "base/values.h"
11
12 using std::ostream;
13 using std::string;
14
15 namespace syncer {
16 namespace syncable {
17
18 ostream& operator<<(ostream& out, const Id& id) {
19 out << id.s_;
20 return out;
21 }
22
23 base::StringValue* Id::ToValue() const {
24 return new base::StringValue(s_);
25 }
26
27 string Id::GetServerId() const {
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.
30 DCHECK(!IsNull());
31 if (IsRoot())
32 return "0";
33 return s_.substr(1);
34 }
35
36 Id Id::CreateFromServerId(const string& server_id) {
37 Id id;
38 if (!server_id.empty()) {
39 if (server_id == "0")
40 id.s_ = "r";
41 else
42 id.s_ = string("s") + server_id;
43 }
44 return id;
45 }
46
47 Id Id::CreateFromClientString(const string& local_id) {
48 Id id;
49 if (!local_id.empty()) {
50 if (local_id == "0")
51 id.s_ = "r";
52 else
53 id.s_ = string("c") + local_id;
54 }
55 return id;
56 }
57
58 Id Id::GetRoot() {
59 Id id;
60 id.s_ = "r";
61 return id;
62 }
63
64 Id Id::GetLexicographicSuccessor() const {
65 // The successor of a string is given by appending the least
66 // character in the alphabet.
67 Id id = *this;
68 id.s_.push_back(0);
69 return id;
70 }
71
72 // static
73 Id Id::GetLeastIdForLexicographicComparison() {
74 Id id;
75 id.s_.clear();
76 return id;
77 }
78
79 } // namespace syncable
80 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/syncable/syncable_id.h ('k') | sync/syncable/syncable_id_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698