| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_ID_H_ | 5 #ifndef CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_ID_H_ |
| 6 #define CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_ID_H_ | 6 #define CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_ID_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <iosfwd> | 9 #include <iosfwd> |
| 10 #include <limits> | 10 #include <limits> |
| 11 #include <sstream> | 11 #include <sstream> |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/hash_tables.h" | 14 #include "base/hash_tables.h" |
| 15 | 15 |
| 16 class MockConnectionManager; |
| 17 |
| 16 namespace base { | 18 namespace base { |
| 17 class StringValue; | 19 class StringValue; |
| 18 } | 20 } |
| 19 | 21 |
| 22 namespace sqlite_utils { |
| 23 class SQLStatement; |
| 24 } |
| 25 |
| 20 namespace syncable { | 26 namespace syncable { |
| 21 struct EntryKernel; | 27 struct EntryKernel; |
| 22 class Id; | 28 class Id; |
| 23 } | 29 } |
| 24 | 30 |
| 25 class MockConnectionManager; | |
| 26 class SQLStatement; | |
| 27 | |
| 28 namespace syncable { | 31 namespace syncable { |
| 29 | 32 |
| 30 std::ostream& operator<<(std::ostream& out, const Id& id); | 33 std::ostream& operator<<(std::ostream& out, const Id& id); |
| 31 | 34 |
| 32 // For historical reasons, 3 concepts got everloaded into the Id: | 35 // For historical reasons, 3 concepts got everloaded into the Id: |
| 33 // 1. A unique, opaque identifier for the object. | 36 // 1. A unique, opaque identifier for the object. |
| 34 // 2. Flag specifing whether server know about this object. | 37 // 2. Flag specifing whether server know about this object. |
| 35 // 3. Flag for root. | 38 // 3. Flag for root. |
| 36 // | 39 // |
| 37 // We originally wrapped an integer for this information, but now we use a | 40 // We originally wrapped an integer for this information, but now we use a |
| 38 // string. It will have one of three forms: | 41 // string. It will have one of three forms: |
| 39 // 1. c<client only opaque id> for client items that have not been committed. | 42 // 1. c<client only opaque id> for client items that have not been committed. |
| 40 // 2. r for the root item. | 43 // 2. r for the root item. |
| 41 // 3. s<server provided opaque id> for items that the server knows about. | 44 // 3. s<server provided opaque id> for items that the server knows about. |
| 42 class Id { | 45 class Id { |
| 43 friend int UnpackEntry(SQLStatement* statement, | |
| 44 syncable::EntryKernel** kernel); | |
| 45 friend int BindFields(const EntryKernel& entry, SQLStatement* statement); | |
| 46 friend std::ostream& operator<<(std::ostream& out, const Id& id); | |
| 47 friend class MockConnectionManager; | |
| 48 friend class SyncableIdTest; | |
| 49 public: | 46 public: |
| 50 // This constructor will be handy even when we move away from int64s, just | 47 // This constructor will be handy even when we move away from int64s, just |
| 51 // for unit tests. | 48 // for unit tests. |
| 52 inline Id() : s_("r") { } | 49 inline Id() : s_("r") { } |
| 53 inline Id(const Id& that) { | 50 inline Id(const Id& that) { |
| 54 Copy(that); | 51 Copy(that); |
| 55 } | 52 } |
| 56 inline Id& operator = (const Id& that) { | 53 inline Id& operator = (const Id& that) { |
| 57 Copy(that); | 54 Copy(that); |
| 58 return *this; | 55 return *this; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 // This should only be used if you get back a reference to a local | 105 // This should only be used if you get back a reference to a local |
| 109 // id from the server. Returns a client only opaque id. | 106 // id from the server. Returns a client only opaque id. |
| 110 static Id CreateFromClientString(const std::string& local_id); | 107 static Id CreateFromClientString(const std::string& local_id); |
| 111 | 108 |
| 112 // This method returns an ID that will compare less than any valid ID. | 109 // This method returns an ID that will compare less than any valid ID. |
| 113 // The returned ID is not a valid ID itself. This is useful for | 110 // The returned ID is not a valid ID itself. This is useful for |
| 114 // computing lower bounds on std::sets that are ordered by operator<. | 111 // computing lower bounds on std::sets that are ordered by operator<. |
| 115 static Id GetLeastIdForLexicographicComparison(); | 112 static Id GetLeastIdForLexicographicComparison(); |
| 116 | 113 |
| 117 private: | 114 private: |
| 115 friend int UnpackEntry(sqlite_utils::SQLStatement* statement, |
| 116 syncable::EntryKernel** kernel); |
| 117 friend int BindFields(const EntryKernel& entry, |
| 118 sqlite_utils::SQLStatement* statement); |
| 119 friend std::ostream& operator<<(std::ostream& out, const Id& id); |
| 120 friend class MockConnectionManager; |
| 121 friend class SyncableIdTest; |
| 122 |
| 118 std::string s_; | 123 std::string s_; |
| 119 }; | 124 }; |
| 120 | 125 |
| 121 extern const Id kNullId; | 126 extern const Id kNullId; |
| 122 | 127 |
| 123 } // namespace syncable | 128 } // namespace syncable |
| 124 | 129 |
| 125 #endif // CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_ID_H_ | 130 #endif // CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_ID_H_ |
| OLD | NEW |