ServiceWorker: Consolidate version manipulation functions in SWProviderContext
[chromium-blink-merge.git] / sync / syncable / syncable_id.cc
blob5cd777ff2eff81f67f70b519eda98417eecd5c60
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.
5 #include "sync/syncable/syncable_id.h"
7 #include <iosfwd>
9 #include "base/logging.h"
10 #include "base/values.h"
12 using std::ostream;
13 using std::string;
15 namespace syncer {
16 namespace syncable {
18 ostream& operator<<(ostream& out, const Id& id) {
19 out << id.s_;
20 return out;
23 base::StringValue* Id::ToValue() const {
24 return new base::StringValue(s_);
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);
36 Id Id::CreateFromServerId(const string& server_id) {
37 Id id;
38 if (server_id == "0")
39 id.s_ = "r";
40 else
41 id.s_ = string("s") + server_id;
42 return id;
45 Id Id::CreateFromClientString(const string& local_id) {
46 Id id;
47 if (local_id == "0")
48 id.s_ = "r";
49 else
50 id.s_ = string("c") + local_id;
51 return id;
54 Id Id::GetRoot() {
55 Id id;
56 id.s_ = "r";
57 return id;
60 Id Id::GetLexicographicSuccessor() const {
61 // The successor of a string is given by appending the least
62 // character in the alphabet.
63 Id id = *this;
64 id.s_.push_back(0);
65 return id;
68 // static
69 Id Id::GetLeastIdForLexicographicComparison() {
70 Id id;
71 id.s_.clear();
72 return id;
75 } // namespace syncable
76 } // namespace syncer