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 #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 #include "chrome/browser/sync/util/fast_dump.h" | |
16 | 15 |
17 extern "C" { | 16 extern "C" { |
18 struct sqlite3; | 17 struct sqlite3; |
19 struct sqlite3_stmt; | 18 struct sqlite3_stmt; |
20 } | 19 } |
21 | 20 |
22 namespace syncable { | 21 namespace syncable { |
23 struct EntryKernel; | 22 struct EntryKernel; |
24 struct IdRowTraits; | 23 struct IdRowTraits; |
25 class Id; | 24 class Id; |
26 } // namespace syncable | 25 } // namespace syncable |
27 | 26 |
28 class MockConnectionManager; | 27 class MockConnectionManager; |
29 class SQLStatement; | 28 class SQLStatement; |
30 | 29 |
31 namespace syncable { | 30 namespace syncable { |
32 | 31 |
33 std::ostream& operator<<(std::ostream& out, const Id& id); | 32 std::ostream& operator<<(std::ostream& out, const Id& id); |
34 browser_sync::FastDump& operator<<(browser_sync::FastDump& out, const Id& id); | |
35 | 33 |
36 // For historical reasons, 3 concepts got everloaded into the Id: | 34 // For historical reasons, 3 concepts got everloaded into the Id: |
37 // 1. A unique, opaque identifier for the object. | 35 // 1. A unique, opaque identifier for the object. |
38 // 2. Flag specifing whether server know about this object. | 36 // 2. Flag specifing whether server know about this object. |
39 // 3. Flag for root. | 37 // 3. Flag for root. |
40 // | 38 // |
41 // 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 |
42 // string. It will have one of three forms: | 40 // string. It will have one of three forms: |
43 // 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. |
44 // 2. r for the root item. | 42 // 2. r for the root item. |
45 // 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. |
46 class Id { | 44 class Id { |
47 friend int UnpackEntry(SQLStatement* statement, | 45 friend int UnpackEntry(SQLStatement* statement, |
48 syncable::EntryKernel** kernel); | 46 syncable::EntryKernel** kernel); |
49 friend struct syncable::IdRowTraits; | 47 friend struct syncable::IdRowTraits; |
50 friend int BindFields(const EntryKernel& entry, SQLStatement* statement); | 48 friend int BindFields(const EntryKernel& entry, SQLStatement* statement); |
51 friend std::ostream& operator<<(std::ostream& out, const Id& id); | 49 friend std::ostream& operator<<(std::ostream& out, const Id& id); |
52 friend browser_sync::FastDump& operator<< | |
53 (browser_sync::FastDump& out, const Id& id); | |
54 friend class MockConnectionManager; | 50 friend class MockConnectionManager; |
55 friend class SyncableIdTest; | 51 friend class SyncableIdTest; |
56 public: | 52 public: |
57 // This constructor will be handy even when we move away from int64s, just | 53 // This constructor will be handy even when we move away from int64s, just |
58 // for unit tests. | 54 // for unit tests. |
59 inline Id() : s_("r") { } | 55 inline Id() : s_("r") { } |
60 inline Id(const Id& that) { | 56 inline Id(const Id& that) { |
61 Copy(that); | 57 Copy(that); |
62 } | 58 } |
63 inline Id& operator = (const Id& that) { | 59 inline Id& operator = (const Id& that) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 101 |
106 protected: | 102 protected: |
107 std::string s_; | 103 std::string s_; |
108 }; | 104 }; |
109 | 105 |
110 extern const Id kNullId; | 106 extern const Id kNullId; |
111 | 107 |
112 } // namespace syncable | 108 } // namespace syncable |
113 | 109 |
114 #endif // CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_ID_H_ | 110 #endif // CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_ID_H_ |
OLD | NEW |