OLD | NEW |
1 // Copyright 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 COMPONENTS_SYNC_SYNCABLE_SYNCABLE_ID_H_ | 5 #ifndef COMPONENTS_SYNC_SYNCABLE_SYNCABLE_ID_H_ |
6 #define COMPONENTS_SYNC_SYNCABLE_SYNCABLE_ID_H_ | 6 #define COMPONENTS_SYNC_SYNCABLE_SYNCABLE_ID_H_ |
7 | 7 |
8 #include <iosfwd> | 8 #include <iosfwd> |
9 #include <limits> | 9 #include <limits> |
10 #include <memory> | 10 #include <memory> |
11 #include <sstream> | 11 #include <sstream> |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "base/containers/hash_tables.h" | 14 #include "base/containers/hash_tables.h" |
15 #include "components/sync/base/sync_export.h" | |
16 | 15 |
17 namespace base { | 16 namespace base { |
18 class StringValue; | 17 class StringValue; |
19 } | 18 } |
20 | 19 |
21 namespace sql { | 20 namespace sql { |
22 class Statement; | 21 class Statement; |
23 } | 22 } |
24 | 23 |
25 namespace syncer { | 24 namespace syncer { |
26 namespace syncable { | 25 namespace syncable { |
27 struct EntryKernel; | 26 struct EntryKernel; |
28 class Id; | 27 class Id; |
29 | 28 |
30 SYNC_EXPORT std::ostream& operator<<(std::ostream& out, const Id& id); | 29 std::ostream& operator<<(std::ostream& out, const Id& id); |
31 | 30 |
32 // For historical reasons, 3 concepts got everloaded into the Id: | 31 // For historical reasons, 3 concepts got everloaded into the Id: |
33 // 1. A unique, opaque identifier for the object. | 32 // 1. A unique, opaque identifier for the object. |
34 // 2. Flag specifing whether server know about this object. | 33 // 2. Flag specifing whether server know about this object. |
35 // 3. Flag for root. | 34 // 3. Flag for root. |
36 // | 35 // |
37 // We originally wrapped an integer for this information, but now we use a | 36 // We originally wrapped an integer for this information, but now we use a |
38 // string. It will have one of three forms: | 37 // string. It will have one of three forms: |
39 // 1. c<client only opaque id> for client items that have not been committed. | 38 // 1. c<client only opaque id> for client items that have not been committed. |
40 // 2. r for the root item. | 39 // 2. r for the root item. |
41 // 3. s<server provided opaque id> for items that the server knows about. | 40 // 3. s<server provided opaque id> for items that the server knows about. |
42 class SYNC_EXPORT Id { | 41 class Id { |
43 public: | 42 public: |
44 inline Id() {} | 43 inline Id() {} |
45 inline Id(const Id& that) { Copy(that); } | 44 inline Id(const Id& that) { Copy(that); } |
46 inline Id& operator=(const Id& that) { | 45 inline Id& operator=(const Id& that) { |
47 Copy(that); | 46 Copy(that); |
48 return *this; | 47 return *this; |
49 } | 48 } |
50 inline void Copy(const Id& that) { this->s_ = that.s_; } | 49 inline void Copy(const Id& that) { this->s_ = that.s_; } |
51 inline bool IsRoot() const { return "r" == s_; } | 50 inline bool IsRoot() const { return "r" == s_; } |
52 inline bool ServerKnows() const { | 51 inline bool ServerKnows() const { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 // computing lower bounds on std::sets that are ordered by operator<. | 83 // computing lower bounds on std::sets that are ordered by operator<. |
85 static Id GetLeastIdForLexicographicComparison(); | 84 static Id GetLeastIdForLexicographicComparison(); |
86 | 85 |
87 // Gets root ID. | 86 // Gets root ID. |
88 static Id GetRoot(); | 87 static Id GetRoot(); |
89 | 88 |
90 private: | 89 private: |
91 friend std::unique_ptr<EntryKernel> UnpackEntry(sql::Statement* statement, | 90 friend std::unique_ptr<EntryKernel> UnpackEntry(sql::Statement* statement, |
92 int* total_created_entries); | 91 int* total_created_entries); |
93 friend void BindFields(const EntryKernel& entry, sql::Statement* statement); | 92 friend void BindFields(const EntryKernel& entry, sql::Statement* statement); |
94 SYNC_EXPORT friend std::ostream& operator<<(std::ostream& out, const Id& id); | 93 friend std::ostream& operator<<(std::ostream& out, const Id& id); |
95 friend class SyncableIdTest; | 94 friend class SyncableIdTest; |
96 | 95 |
97 std::string s_; | 96 std::string s_; |
98 }; | 97 }; |
99 | 98 |
100 } // namespace syncable | 99 } // namespace syncable |
101 } // namespace syncer | 100 } // namespace syncer |
102 | 101 |
103 #endif // COMPONENTS_SYNC_SYNCABLE_SYNCABLE_ID_H_ | 102 #endif // COMPONENTS_SYNC_SYNCABLE_SYNCABLE_ID_H_ |
OLD | NEW |