OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 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 "chrome/browser/sync/syncable/syncable_id.h" |
| 6 |
| 7 #include <iosfwd> |
| 8 |
| 9 #include "base/string_util.h" |
| 10 #include "chrome/browser/sync/util/query_helpers.h" |
| 11 |
| 12 using std::ostream; |
| 13 using std::string; |
| 14 |
| 15 namespace syncable { |
| 16 const Id kNullId; // Currently == root. |
| 17 } // namespace syncable |
| 18 |
| 19 sqlite3_stmt* BindArg(sqlite3_stmt* statement, const syncable::Id& id, |
| 20 int index) { |
| 21 return BindArg(statement, id.s_.c_str(), index); |
| 22 } |
| 23 |
| 24 void GetColumn(sqlite3_stmt* statement, int index, syncable::Id* id) { |
| 25 GetColumn(statement, index, &id->s_); |
| 26 } |
| 27 |
| 28 ostream& operator << (ostream& out, const syncable::Id& id) { |
| 29 out << id.s_; |
| 30 return out; |
| 31 } |
| 32 |
| 33 using browser_sync::FastDump; |
| 34 FastDump& operator << (FastDump& dump, const syncable::Id& id) { |
| 35 dump.out_->sputn(id.s_.data(), id.s_.size()); |
| 36 return dump; |
| 37 } |
| 38 |
| 39 namespace syncable { |
| 40 |
| 41 string Id::AsQueryParam() const { |
| 42 if ('s' == s_[0]) |
| 43 return s_.c_str() + 1; |
| 44 return ""; |
| 45 } |
| 46 |
| 47 string Id::GetServerId() const { |
| 48 // Currently root is the string "0". We need to decide on a true value. |
| 49 // "" would be convenient here, as the IsRoot call would not be needed. |
| 50 if (IsRoot()) |
| 51 return "0"; |
| 52 return s_.substr(1); |
| 53 } |
| 54 |
| 55 Id Id::CreateFromServerId(const string& server_id) { |
| 56 Id id; |
| 57 if (server_id == "0") |
| 58 id.s_ = "r"; |
| 59 else |
| 60 id.s_ = string("s") + server_id; |
| 61 return id; |
| 62 } |
| 63 |
| 64 Id Id::CreateFromClientString(const string& local_id) { |
| 65 Id id; |
| 66 if (local_id == "0") |
| 67 id.s_ = "r"; |
| 68 else |
| 69 id.s_ = string("c") + local_id; |
| 70 return id; |
| 71 } |
| 72 } // namespace syncable |
OLD | NEW |