Android Chromoting: Remove exit-fullscreen button.
[chromium-blink-merge.git] / sync / syncable / syncable_id.h
blob3691d77b8ac0a9e79a76822530f949c8e41bc633
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
3 // found in the LICENSE file.
5 #ifndef SYNC_SYNCABLE_SYNCABLE_ID_H_
6 #define SYNC_SYNCABLE_SYNCABLE_ID_H_
8 #include <iosfwd>
9 #include <limits>
10 #include <sstream>
11 #include <string>
13 #include "base/containers/hash_tables.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "sync/base/sync_export.h"
17 class MockConnectionManager;
19 namespace base {
20 class StringValue;
23 namespace sql {
24 class Statement;
27 namespace syncer {
28 namespace syncable {
29 struct EntryKernel;
30 class Id;
32 SYNC_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& out, const Id& id);
34 // For historical reasons, 3 concepts got everloaded into the Id:
35 // 1. A unique, opaque identifier for the object.
36 // 2. Flag specifing whether server know about this object.
37 // 3. Flag for root.
39 // We originally wrapped an integer for this information, but now we use a
40 // string. It will have one of three forms:
41 // 1. c<client only opaque id> for client items that have not been committed.
42 // 2. r for the root item.
43 // 3. s<server provided opaque id> for items that the server knows about.
44 class SYNC_EXPORT Id {
45 public:
46 inline Id() {}
47 inline Id(const Id& that) {
48 Copy(that);
50 inline Id& operator = (const Id& that) {
51 Copy(that);
52 return *this;
54 inline void Copy(const Id& that) {
55 this->s_ = that.s_;
57 inline bool IsRoot() const {
58 return "r" == s_;
60 inline bool ServerKnows() const {
61 return !IsNull() && (s_[0] == 's' || s_ == "r");
64 inline bool IsNull() const { return s_.empty(); }
65 inline void Clear() { s_.clear(); }
66 inline int compare(const Id& that) const {
67 return s_.compare(that.s_);
69 inline bool operator == (const Id& that) const {
70 return s_ == that.s_;
72 inline bool operator != (const Id& that) const {
73 return s_ != that.s_;
75 inline bool operator < (const Id& that) const {
76 return s_ < that.s_;
78 inline bool operator > (const Id& that) const {
79 return s_ > that.s_;
82 const std::string& value() const {
83 return s_;
86 // Return the next highest ID in the lexicographic ordering. This is
87 // useful for computing upper bounds on std::sets that are ordered
88 // by operator<.
89 Id GetLexicographicSuccessor() const;
91 // Dumps the ID as a value and returns it. Transfers ownership of
92 // the StringValue to the caller.
93 base::StringValue* ToValue() const;
95 // Three functions are used to work with our proto buffers.
96 std::string GetServerId() const;
97 static Id CreateFromServerId(const std::string& server_id);
98 // This should only be used if you get back a reference to a local
99 // id from the server. Returns a client only opaque id.
100 static Id CreateFromClientString(const std::string& local_id);
102 // This method returns an ID that will compare less than any valid ID.
103 // The returned ID is not a valid ID itself. This is useful for
104 // computing lower bounds on std::sets that are ordered by operator<.
105 static Id GetLeastIdForLexicographicComparison();
107 // Gets root ID.
108 static Id GetRoot();
110 private:
111 friend scoped_ptr<EntryKernel> UnpackEntry(sql::Statement* statement);
112 friend void BindFields(const EntryKernel& entry,
113 sql::Statement* statement);
114 SYNC_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& out,
115 const Id& id);
116 friend class MockConnectionManager;
117 friend class SyncableIdTest;
119 std::string s_;
122 } // namespace syncable
123 } // namespace syncer
125 #endif // SYNC_SYNCABLE_SYNCABLE_ID_H_