| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 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/syncable/syncable_id.h" | 5 #include "chrome/browser/sync/syncable/syncable_id.h" |
| 6 | 6 |
| 7 #include <iosfwd> | 7 #include <iosfwd> |
| 8 | 8 |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 | 10 |
| 11 using std::ostream; | 11 using std::ostream; |
| 12 using std::string; | 12 using std::string; |
| 13 | 13 |
| 14 namespace syncable { | 14 namespace syncable { |
| 15 const Id kNullId; // Currently == root. | 15 const Id kNullId; // Currently == root. |
| 16 | 16 |
| 17 ostream& operator<<(ostream& out, const Id& id) { | 17 ostream& operator<<(ostream& out, const Id& id) { |
| 18 out << id.s_; | 18 out << id.s_; |
| 19 return out; | 19 return out; |
| 20 } | 20 } |
| 21 | 21 |
| 22 using browser_sync::FastDump; | |
| 23 FastDump& operator<<(FastDump& dump, const Id& id) { | |
| 24 dump.out_->sputn(id.s_.data(), id.s_.size()); | |
| 25 return dump; | |
| 26 } | |
| 27 | |
| 28 string Id::GetServerId() const { | 22 string Id::GetServerId() const { |
| 29 // Currently root is the string "0". We need to decide on a true value. | 23 // Currently root is the string "0". We need to decide on a true value. |
| 30 // "" would be convenient here, as the IsRoot call would not be needed. | 24 // "" would be convenient here, as the IsRoot call would not be needed. |
| 31 if (IsRoot()) | 25 if (IsRoot()) |
| 32 return "0"; | 26 return "0"; |
| 33 return s_.substr(1); | 27 return s_.substr(1); |
| 34 } | 28 } |
| 35 | 29 |
| 36 Id Id::CreateFromServerId(const string& server_id) { | 30 Id Id::CreateFromServerId(const string& server_id) { |
| 37 Id id; | 31 Id id; |
| 38 if (server_id == "0") | 32 if (server_id == "0") |
| 39 id.s_ = "r"; | 33 id.s_ = "r"; |
| 40 else | 34 else |
| 41 id.s_ = string("s") + server_id; | 35 id.s_ = string("s") + server_id; |
| 42 return id; | 36 return id; |
| 43 } | 37 } |
| 44 | 38 |
| 45 Id Id::CreateFromClientString(const string& local_id) { | 39 Id Id::CreateFromClientString(const string& local_id) { |
| 46 Id id; | 40 Id id; |
| 47 if (local_id == "0") | 41 if (local_id == "0") |
| 48 id.s_ = "r"; | 42 id.s_ = "r"; |
| 49 else | 43 else |
| 50 id.s_ = string("c") + local_id; | 44 id.s_ = string("c") + local_id; |
| 51 return id; | 45 return id; |
| 52 } | 46 } |
| 53 | 47 |
| 54 } // namespace syncable | 48 } // namespace syncable |
| OLD | NEW |