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/19 00:58:45
replace with fwd declare
Nicolas Zea
2011/05/19 21:17:45
Done.
| |
| 15 #include "chrome/browser/sync/syncable/model_type.h" | |
| 16 | |
| 17 typedef syncable::ModelType SyncDataType; | |
| 18 | |
| 19 // A reference counted immutable SyncEntity. | |
| 20 class RefCountedSyncEntity : public | |
|
akalin
2011/05/19 00:58:45
consider making this a private inner class of Sync
Nicolas Zea
2011/05/19 21:17:45
Done.
| |
| 21 base::RefCountedThreadSafe<RefCountedSyncEntity> { | |
| 22 public: | |
| 23 // Takes ownership of data. | |
| 24 explicit RefCountedSyncEntity(sync_pb::SyncEntity* sync_entity); | |
| 25 | |
| 26 // Returns immutable reference to local sync entity. | |
| 27 const sync_pb::SyncEntity& sync_entity(); | |
|
akalin
2011/05/19 00:58:45
function should be const
Nicolas Zea
2011/05/19 21:17:45
Done.
| |
| 28 | |
| 29 private: | |
| 30 friend class base::RefCountedThreadSafe<RefCountedSyncEntity>; | |
| 31 | |
| 32 // Private due to ref counting. | |
| 33 ~RefCountedSyncEntity(); | |
| 34 | |
| 35 scoped_ptr<sync_pb::SyncEntity> sync_entity_; | |
| 36 }; | |
| 37 | |
| 38 // A light-weight container for immutable sync data. Pass-by-value and storage | |
| 39 // in STL containers are supported and encouraged if helpful. | |
| 40 class SyncData { | |
| 41 public: | |
| 42 // Creates an empty and invalid SyncData. | |
| 43 SyncData(); | |
| 44 ~SyncData(); | |
| 45 | |
| 46 // Default copy and assign welcome. | |
| 47 | |
| 48 // Helper methods for creating SyncData objects for local data. | |
| 49 // Local sync data must always at least set the sync tag. | |
| 50 static SyncData CreateLocalData(const std::string& sync_tag); | |
|
akalin
2011/05/19 00:58:45
What do you think about making these (possibly-fri
Nicolas Zea
2011/05/19 21:17:45
Because we are in the global namespace, I think it
| |
| 51 static SyncData CreateLocalData( | |
| 52 const std::string& sync_tag, | |
| 53 const sync_pb::EntitySpecifics& specifics); | |
| 54 | |
| 55 // Helper method for creating SyncData objects originating from the syncer. | |
|
akalin
2011/05/19 00:58:45
I think we should find some way to not expose this
Nicolas Zea
2011/05/19 21:17:45
Now that we have explicit validity rules/checking
| |
| 56 static SyncData CreateRemoteData( | |
| 57 const sync_pb::SyncEntity& entity); | |
| 58 static SyncData CreateRemoteData( | |
| 59 const sync_pb::EntitySpecifics& specifics); | |
| 60 | |
| 61 // Whether this SyncData holds valid data. The only way to have a SyncData | |
| 62 // without valid data is to use the default constructor. | |
| 63 bool IsValid() const; | |
| 64 // Return the datatype modified by this sync event. Derived from the sync | |
| 65 // datatype specifics. | |
| 66 SyncDataType GetDataType() const; | |
| 67 // Return the current sync datatype specifics. | |
| 68 const sync_pb::EntitySpecifics& GetSpecifics() const; | |
| 69 // Returns the value of the unique client tag. This is only set for data going | |
|
akalin
2011/05/19 00:58:45
Did we end up needing this?
Nicolas Zea
2011/05/19 21:17:45
Yes, all changes coming from a local syncableservi
akalin
2011/05/20 00:08:05
I mean is this accessor specifically needed? Does
Nicolas Zea
2011/05/20 02:00:28
The sync code creates the hash from this field, so
| |
| 70 // TO the syncer, not coming from. | |
| 71 const std::string& GetTag() const; | |
| 72 // Whether this sync data is for local data or data coming from the syncer. | |
| 73 bool IsLocal() const; | |
| 74 | |
| 75 // TODO(zea): Query methods for other sync properties: title, parent, | |
| 76 // successor, etc. Possibly support for hashed tag and sync id? | |
| 77 | |
| 78 protected: | |
| 79 // The actual shared sync entity being held. | |
| 80 scoped_refptr<RefCountedSyncEntity> shared_entity_; | |
| 81 | |
| 82 // Whether this data originated locally or from the syncer (remote data). | |
| 83 bool is_local_; | |
| 84 }; | |
| 85 | |
| 86 #endif // CHROME_BROWSER_SYNC_API_SYNC_DATA_H_ | |
| OLD | NEW |