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