Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_SYNC_API_SYNC_DATA_H_ | |
| 6 #define CHROME_BROWSER_SYNC_API_SYNC_DATA_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "chrome/browser/sync/protocol/sync.pb.h" | |
|
akalin
2011/05/20 00:19:39
remove this header since you forward-declare now
Nicolas Zea
2011/05/20 02:00:28
Done.
| |
| 15 #include "chrome/browser/sync/syncable/model_type.h" | |
| 16 | |
| 17 namespace sync_pb { | |
| 18 class EntitySpecifics; | |
| 19 class SyncEntity; | |
| 20 } | |
| 21 | |
| 22 typedef syncable::ModelType SyncDataType; | |
| 23 | |
| 24 // A light-weight container for immutable sync data. Pass-by-value and storage | |
| 25 // in STL containers are supported and encouraged if helpful. | |
| 26 class SyncData { | |
| 27 public: | |
| 28 // Creates an empty and invalid SyncData. | |
| 29 SyncData(); | |
| 30 ~SyncData(); | |
| 31 | |
| 32 // Default copy and assign welcome. | |
| 33 | |
| 34 // Helper methods for creating SyncData objects for local data. | |
| 35 // Local sync data must always at least set the sync tag. | |
| 36 static SyncData CreateLocalData(const std::string& sync_tag); | |
| 37 static SyncData CreateLocalData( | |
| 38 const std::string& sync_tag, | |
| 39 const sync_pb::EntitySpecifics& specifics); | |
| 40 | |
| 41 // Helper method for creating SyncData objects originating from the syncer. | |
| 42 static SyncData CreateRemoteData( | |
| 43 const sync_pb::SyncEntity& entity); | |
| 44 static SyncData CreateRemoteData( | |
| 45 const sync_pb::EntitySpecifics& specifics); | |
| 46 | |
| 47 // Whether this SyncData holds valid data. The only way to have a SyncData | |
| 48 // without valid data is to use the default constructor. | |
| 49 bool IsValid() const; | |
| 50 // Return the datatype we're holding information about. Derived from the sync | |
| 51 // datatype specifics. | |
| 52 SyncDataType GetDataType() const; | |
| 53 // Return the current sync datatype specifics. | |
| 54 const sync_pb::EntitySpecifics& GetSpecifics() const; | |
| 55 // Returns the value of the unique client tag. This is only set for data going | |
| 56 // TO the syncer, not coming from. | |
| 57 const std::string& GetTag() const; | |
| 58 // Whether this sync data is for local data or data coming from the syncer. | |
| 59 bool IsLocal() const; | |
| 60 | |
| 61 // TODO(zea): Query methods for other sync properties: title, parent, | |
| 62 // successor, etc. Possibly support for hashed tag and sync id? | |
| 63 | |
| 64 protected: | |
|
akalin
2011/05/20 00:19:39
why not private?
Nicolas Zea
2011/05/20 02:00:28
Done.
| |
| 65 // A reference counted immutable SyncEntity. | |
| 66 class SharedSyncEntity : public | |
| 67 base::RefCountedThreadSafe<SharedSyncEntity> { | |
| 68 public: | |
| 69 // Takes ownership of |sync_entity|'s contents. | |
| 70 explicit SharedSyncEntity(scoped_ptr<sync_pb::SyncEntity>* sync_entity); | |
| 71 | |
| 72 // Returns immutable reference to local sync entity. | |
| 73 const sync_pb::SyncEntity& sync_entity() const; | |
| 74 | |
| 75 private: | |
| 76 friend class base::RefCountedThreadSafe<SharedSyncEntity>; | |
| 77 | |
| 78 // Private due to ref counting. | |
| 79 ~SharedSyncEntity(); | |
| 80 | |
| 81 scoped_ptr<sync_pb::SyncEntity> sync_entity_; | |
| 82 }; | |
| 83 | |
| 84 // The actual shared sync entity being held. | |
| 85 scoped_refptr<SharedSyncEntity> shared_entity_; | |
| 86 | |
| 87 // Whether this data originated locally or from the syncer (remote data). | |
| 88 bool is_local_; | |
| 89 }; | |
| 90 | |
| 91 #endif // CHROME_BROWSER_SYNC_API_SYNC_DATA_H_ | |
| OLD | NEW |