Chromium Code Reviews| 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_API_SYNC_DATA_H_ | 5 #ifndef CHROME_BROWSER_SYNC_API_SYNC_DATA_H_ |
| 6 #define CHROME_BROWSER_SYNC_API_SYNC_DATA_H_ | 6 #define CHROME_BROWSER_SYNC_API_SYNC_DATA_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
|
Nicolas Zea
2011/09/15 23:39:46
can we get rid of this now?
akalin
2011/09/16 00:59:59
Done.
| |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "chrome/browser/sync/syncable/model_type.h" | 13 #include "chrome/browser/sync/syncable/model_type.h" |
| 14 #include "chrome/browser/sync/util/immutable.h" | |
| 15 | 15 |
| 16 namespace sync_pb { | 16 namespace sync_pb { |
| 17 class EntitySpecifics; | 17 class EntitySpecifics; |
| 18 class SyncEntity; | 18 class SyncEntity; |
| 19 } | 19 } // namespace sync_pb |
| 20 | 20 |
| 21 typedef syncable::ModelType SyncDataType; | 21 typedef syncable::ModelType SyncDataType; |
| 22 | 22 |
| 23 // A light-weight container for immutable sync data. Pass-by-value and storage | 23 // A light-weight container for immutable sync data. Pass-by-value and storage |
| 24 // in STL containers are supported and encouraged if helpful. | 24 // in STL containers are supported and encouraged if helpful. |
| 25 class SyncData { | 25 class SyncData { |
| 26 public: | 26 public: |
| 27 // Creates an empty and invalid SyncData. | 27 // Creates an empty and invalid SyncData. |
| 28 SyncData(); | 28 SyncData(); |
| 29 ~SyncData(); | 29 ~SyncData(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 // Returns the non unique title (for debugging). Currently only set for data | 70 // Returns the non unique title (for debugging). Currently only set for data |
| 71 // going TO the syncer, not from. | 71 // going TO the syncer, not from. |
| 72 const std::string& GetTitle() const; | 72 const std::string& GetTitle() const; |
| 73 | 73 |
| 74 // Whether this sync data is for local data or data coming from the syncer. | 74 // Whether this sync data is for local data or data coming from the syncer. |
| 75 bool IsLocal() const; | 75 bool IsLocal() const; |
| 76 | 76 |
| 77 // TODO(zea): Query methods for other sync properties: parent, successor, etc. | 77 // TODO(zea): Query methods for other sync properties: parent, successor, etc. |
| 78 | 78 |
| 79 private: | 79 private: |
| 80 // A reference counted immutable SyncEntity. | 80 // Necessary since we forward-declare sync_pb::SyncEntity; see |
| 81 class SharedSyncEntity : public | 81 // comments in immutable.h. |
| 82 base::RefCountedThreadSafe<SharedSyncEntity> { | 82 struct ImmutableSyncEntityTraits { |
| 83 public: | 83 typedef sync_pb::SyncEntity* Container; |
| 84 // Takes ownership of |sync_entity|'s contents. | |
| 85 explicit SharedSyncEntity(sync_pb::SyncEntity* sync_entity); | |
| 86 | 84 |
| 87 // Returns immutable reference to local sync entity. | 85 static void CreateAndDefaultInitialize(Container* container); |
| 88 const sync_pb::SyncEntity& sync_entity() const; | |
| 89 | 86 |
| 90 private: | 87 static void Destroy(Container* container); |
| 91 friend class base::RefCountedThreadSafe<SharedSyncEntity>; | |
| 92 | 88 |
| 93 // Private due to ref counting. | 89 static const sync_pb::SyncEntity& Unwrap(const Container& container); |
| 94 ~SharedSyncEntity(); | |
| 95 | 90 |
| 96 scoped_ptr<sync_pb::SyncEntity> sync_entity_; | 91 static sync_pb::SyncEntity* UnwrapMutable(Container* container); |
| 92 | |
| 93 static void Swap(sync_pb::SyncEntity* t1, sync_pb::SyncEntity* t2); | |
| 97 }; | 94 }; |
| 98 | 95 |
| 99 // The actual shared sync entity being held. | 96 typedef browser_sync::Immutable< |
| 100 scoped_refptr<SharedSyncEntity> shared_entity_; | 97 sync_pb::SyncEntity, ImmutableSyncEntityTraits> |
| 98 ImmutableSyncEntity; | |
| 99 | |
| 100 // Clears |entity|. | |
| 101 SyncData(sync_pb::SyncEntity* entity, bool is_local); | |
| 102 | |
| 103 // Whether this SyncData holds valid data. | |
| 104 bool is_valid_; | |
| 101 | 105 |
| 102 // Whether this data originated locally or from the syncer (remote data). | 106 // Whether this data originated locally or from the syncer (remote data). |
| 103 bool is_local_; | 107 bool is_local_; |
| 108 | |
| 109 // The actual shared sync entity being held. | |
| 110 ImmutableSyncEntity immutable_entity_; | |
| 104 }; | 111 }; |
| 105 | 112 |
| 106 #endif // CHROME_BROWSER_SYNC_API_SYNC_DATA_H_ | 113 #endif // CHROME_BROWSER_SYNC_API_SYNC_DATA_H_ |
| OLD | NEW |