Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(474)

Side by Side Diff: sync/api/sync_data.h

Issue 187303006: Update sync API to support attachments. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@attachmentapi
Patch Set: Rename GetAttachments to GetLocalAttachmentsForUpload. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sync/api/sync_change_processor.h ('k') | sync/api/sync_data.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 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 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 SYNC_API_SYNC_DATA_H_ 5 #ifndef SYNC_API_SYNC_DATA_H_
6 #define SYNC_API_SYNC_DATA_H_ 6 #define SYNC_API_SYNC_DATA_H_
7 7
8 #include <iosfwd> 8 #include <iosfwd>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/callback.h"
14 #include "base/stl_util.h"
13 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "sync/api/attachments/attachment.h"
17 #include "sync/api/attachments/attachment_service_proxy.h"
14 #include "sync/base/sync_export.h" 18 #include "sync/base/sync_export.h"
15 #include "sync/internal_api/public/base/model_type.h" 19 #include "sync/internal_api/public/base/model_type.h"
16 #include "sync/internal_api/public/util/immutable.h" 20 #include "sync/internal_api/public/util/immutable.h"
21 #include "sync/internal_api/public/util/weak_handle.h"
17 22
18 namespace sync_pb { 23 namespace sync_pb {
19 class EntitySpecifics; 24 class EntitySpecifics;
20 class SyncEntity; 25 class SyncEntity;
21 } // namespace sync_pb 26 } // namespace sync_pb
22 27
23 namespace syncer { 28 namespace syncer {
24 29
30 class AttachmentService;
31
25 // A light-weight container for immutable sync data. Pass-by-value and storage 32 // A light-weight container for immutable sync data. Pass-by-value and storage
26 // in STL containers are supported and encouraged if helpful. 33 // in STL containers are supported and encouraged if helpful.
27 class SYNC_EXPORT SyncData { 34 class SYNC_EXPORT SyncData {
28 public: 35 public:
29 // Creates an empty and invalid SyncData. 36 // Creates an empty and invalid SyncData.
30 SyncData(); 37 SyncData();
31 ~SyncData(); 38 ~SyncData();
32 39
33 // Default copy and assign welcome. 40 // Default copy and assign welcome.
34 41
35 // Helper methods for creating SyncData objects for local data. 42 // Helper methods for creating SyncData objects for local data.
36 // The sync tag must be a string unique to this datatype and is used as a node 43 // The sync tag must be a string unique to this datatype and is used as a node
37 // identifier server-side. 44 // identifier server-side.
38 // For deletes: |datatype| must specify the datatype who node is being 45 // For deletes: |datatype| must specify the datatype who node is being
39 // deleted. 46 // deleted.
40 // For adds/updates: the specifics must be valid and the non-unique title (can 47 // For adds/updates: the specifics must be valid and the non-unique title (can
41 // be the same as sync tag) must be specfied. 48 // be the same as sync tag) must be specfied.
42 // Note: the non_unique_title is primarily for debug purposes, and will be 49 // Note: the non_unique_title is primarily for debug purposes, and will be
43 // overwritten if the datatype is encrypted. 50 // overwritten if the datatype is encrypted.
44 static SyncData CreateLocalDelete( 51 static SyncData CreateLocalDelete(
45 const std::string& sync_tag, 52 const std::string& sync_tag,
46 ModelType datatype); 53 ModelType datatype);
47 static SyncData CreateLocalData( 54 static SyncData CreateLocalData(
48 const std::string& sync_tag, 55 const std::string& sync_tag,
49 const std::string& non_unique_title, 56 const std::string& non_unique_title,
50 const sync_pb::EntitySpecifics& specifics); 57 const sync_pb::EntitySpecifics& specifics);
58 static SyncData CreateLocalDataWithAttachments(
59 const std::string& sync_tag,
60 const std::string& non_unique_title,
61 const sync_pb::EntitySpecifics& specifics,
62 const AttachmentList& attachments);
51 63
52 // Helper method for creating SyncData objects originating from the syncer. 64 // Helper method for creating SyncData objects originating from the syncer.
65 //
66 // TODO(maniscalco): Replace all calls to 3-arg CreateRemoteData with calls to
67 // the 5-arg version (bug 353296).
53 static SyncData CreateRemoteData( 68 static SyncData CreateRemoteData(
54 int64 id, 69 int64 id,
55 const sync_pb::EntitySpecifics& specifics, 70 const sync_pb::EntitySpecifics& specifics,
56 const base::Time& last_modified_time); 71 const base::Time& last_modified_time,
72 const AttachmentIdList& attachment_ids,
73 const syncer::AttachmentServiceProxy& attachment_service);
74 static SyncData CreateRemoteData(int64 id,
75 const sync_pb::EntitySpecifics& specifics,
76 const base::Time& last_modified_time);
57 77
58 // Whether this SyncData holds valid data. The only way to have a SyncData 78 // Whether this SyncData holds valid data. The only way to have a SyncData
59 // without valid data is to use the default constructor. 79 // without valid data is to use the default constructor.
60 bool IsValid() const; 80 bool IsValid() const;
61 81
62 // Return the datatype we're holding information about. Derived from the sync 82 // Return the datatype we're holding information about. Derived from the sync
63 // datatype specifics. 83 // datatype specifics.
64 ModelType GetDataType() const; 84 ModelType GetDataType() const;
65 85
66 // Return the current sync datatype specifics. 86 // Return the current sync datatype specifics.
(...skipping 11 matching lines...) Expand all
78 // only valid if IsLocal() is false, and may be null if the SyncData 98 // only valid if IsLocal() is false, and may be null if the SyncData
79 // represents a deleted item. 99 // represents a deleted item.
80 const base::Time& GetRemoteModifiedTime() const; 100 const base::Time& GetRemoteModifiedTime() const;
81 101
82 // Should only be called by sync code when IsLocal() is false. 102 // Should only be called by sync code when IsLocal() is false.
83 int64 GetRemoteId() const; 103 int64 GetRemoteId() const;
84 104
85 // Whether this sync data is for local data or data coming from the syncer. 105 // Whether this sync data is for local data or data coming from the syncer.
86 bool IsLocal() const; 106 bool IsLocal() const;
87 107
108 // TODO(maniscalco): Reduce the dependence on knowing whether a SyncData is
109 // local (in the IsLocal() == true sense) or remote. Make it harder for users
110 // of SyncData to accidentally call local-only methods on a remote SyncData
111 // (bug 357305).
112
88 std::string ToString() const; 113 std::string ToString() const;
89 114
115 // Return a list of this SyncData's attachment ids.
116 //
117 // The attachments may or may not be present on this device.
118 AttachmentIdList GetAttachmentIds() const;
119
120 // Return a list of this SyncData's attachments.
121 //
122 // May only be called when IsLocal() is true.
123 const AttachmentList& GetLocalAttachmentsForUpload() const;
124
125 // Retrieve the attachments indentified by |attachment_ids|. Invoke |callback|
126 // with the requested attachments.
127 //
128 // May only be called when IsLocal() is false.
129 //
130 // |callback| will be invoked when the operation is complete (successfully or
131 // otherwise).
132 //
133 // Retrieving the requested attachments may require reading local storage or
134 // requesting the attachments from the network.
135 //
136 void GetOrDownloadAttachments(
137 const AttachmentIdList& attachment_ids,
138 const AttachmentService::GetOrDownloadCallback& callback);
139
140 // Drop (delete from local storage) the attachments associated with this
141 // SyncData specified in |attachment_ids|. This method will not delete
142 // attachments from the server.
143 //
144 // May only be called when IsLocal() is false.
145 //
146 // |callback| will be invoked when the operation is complete (successfully or
147 // otherwise).
148 void DropAttachments(const AttachmentIdList& attachment_ids,
149 const AttachmentService::DropCallback& callback);
150
90 // TODO(zea): Query methods for other sync properties: parent, successor, etc. 151 // TODO(zea): Query methods for other sync properties: parent, successor, etc.
91 152
92 private: 153 private:
93 // Necessary since we forward-declare sync_pb::SyncEntity; see 154 // Necessary since we forward-declare sync_pb::SyncEntity; see
94 // comments in immutable.h. 155 // comments in immutable.h.
95 struct ImmutableSyncEntityTraits { 156 struct ImmutableSyncEntityTraits {
96 typedef sync_pb::SyncEntity* Wrapper; 157 typedef sync_pb::SyncEntity* Wrapper;
97 158
98 static void InitializeWrapper(Wrapper* wrapper); 159 static void InitializeWrapper(Wrapper* wrapper);
99 160
100 static void DestroyWrapper(Wrapper* wrapper); 161 static void DestroyWrapper(Wrapper* wrapper);
101 162
102 static const sync_pb::SyncEntity& Unwrap(const Wrapper& wrapper); 163 static const sync_pb::SyncEntity& Unwrap(const Wrapper& wrapper);
103 164
104 static sync_pb::SyncEntity* UnwrapMutable(Wrapper* wrapper); 165 static sync_pb::SyncEntity* UnwrapMutable(Wrapper* wrapper);
105 166
106 static void Swap(sync_pb::SyncEntity* t1, sync_pb::SyncEntity* t2); 167 static void Swap(sync_pb::SyncEntity* t1, sync_pb::SyncEntity* t2);
107 }; 168 };
108 169
109 typedef Immutable<sync_pb::SyncEntity, ImmutableSyncEntityTraits> 170 typedef Immutable<sync_pb::SyncEntity, ImmutableSyncEntityTraits>
110 ImmutableSyncEntity; 171 ImmutableSyncEntity;
111 172
112 // Clears |entity|. 173 // Clears |entity| and |attachments|.
113 SyncData(int64 id, 174 SyncData(
114 sync_pb::SyncEntity* entity, 175 int64 id,
115 const base::Time& remote_modification_time); 176 sync_pb::SyncEntity* entity,
177 AttachmentList* attachments,
178 const base::Time& remote_modification_time,
179 const syncer::AttachmentServiceProxy& attachment_service);
116 180
117 // Whether this SyncData holds valid data. 181 // Whether this SyncData holds valid data.
118 bool is_valid_; 182 bool is_valid_;
119 183
120 // Equal to kInvalidId iff this is local. 184 // Equal to kInvalidId iff this is local.
121 int64 id_; 185 int64 id_;
122 186
123 // This is only valid if IsLocal() is false, and may be null if the 187 // This is only valid if IsLocal() is false, and may be null if the
124 // SyncData represents a deleted item. 188 // SyncData represents a deleted item.
125 base::Time remote_modification_time_; 189 base::Time remote_modification_time_;
126 190
127 // The actual shared sync entity being held. 191 // The actual shared sync entity being held.
128 ImmutableSyncEntity immutable_entity_; 192 ImmutableSyncEntity immutable_entity_;
193
194 Immutable<AttachmentList> attachments_;
195
196 AttachmentServiceProxy attachment_service_;
129 }; 197 };
130 198
131 // gmock printer helper. 199 // gmock printer helper.
132 void PrintTo(const SyncData& sync_data, std::ostream* os); 200 void PrintTo(const SyncData& sync_data, std::ostream* os);
133 201
134 typedef std::vector<SyncData> SyncDataList; 202 typedef std::vector<SyncData> SyncDataList;
135 203
136 } // namespace syncer 204 } // namespace syncer
137 205
138 #endif // SYNC_API_SYNC_DATA_H_ 206 #endif // SYNC_API_SYNC_DATA_H_
OLDNEW
« no previous file with comments | « sync/api/sync_change_processor.h ('k') | sync/api/sync_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698