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