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

Side by Side Diff: sync/engine/process_commit_response_command.h

Issue 25638003: sync: Implement per-type commit interface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Small fixes from first review Created 7 years, 2 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 | Annotate | Revision Log
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_ENGINE_PROCESS_COMMIT_RESPONSE_COMMAND_H_ 5 #ifndef SYNC_ENGINE_PROCESS_COMMIT_RESPONSE_COMMAND_H_
6 #define SYNC_ENGINE_PROCESS_COMMIT_RESPONSE_COMMAND_H_ 6 #define SYNC_ENGINE_PROCESS_COMMIT_RESPONSE_COMMAND_H_
7 7
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "sync/base/sync_export.h" 13 #include "sync/base/sync_export.h"
14 #include "sync/engine/syncer_command.h" 14 #include "sync/engine/syncer_command.h"
15 #include "sync/protocol/sync.pb.h" 15 #include "sync/protocol/sync.pb.h"
16 16
17 namespace syncer { 17 namespace syncer {
18 18
19 namespace sessions {
20 class OrderedCommitSet;
21 }
22
23 namespace syncable { 19 namespace syncable {
24 class Id; 20 class Id;
25 class ModelNeutralWriteTransaction; 21 class ModelNeutralWriteTransaction;
26 class ModelNeutralMutableEntry; 22 class ModelNeutralMutableEntry;
27 class Directory; 23 class Directory;
28 } 24 }
29 25
30 // A class that processes the server's response to our commmit attempt. Note 26 // A class that processes the server's response to our commmit attempt. Note
31 // that some of the preliminary processing is performed in 27 // that some of the preliminary processing is performed in
32 // PostClientToServerMessage command. 28 // PostClientToServerMessage command.
33 // 29 //
34 // As part of processing the commit response, this command will modify sync 30 // As part of processing the commit response, this command will modify sync
35 // entries. It can change their IDs, update their versions, etc. 31 // entries. It can change their IDs, update their versions, etc.
36 // 32 //
37 // This command will return a non-SYNCER_OK value if an error occurred while 33 // This command will return a non-SYNCER_OK value if an error occurred while
38 // processing the response, or if the server's response indicates that it had 34 // processing the response, or if the server's response indicates that it had
39 // trouble processing the request. 35 // trouble processing the request.
40 // 36 //
41 // See SyncerCommand documentation for more info. 37 // See SyncerCommand documentation for more info.
42 class SYNC_EXPORT_PRIVATE ProcessCommitResponseCommand : public SyncerCommand { 38 class SYNC_EXPORT_PRIVATE ProcessCommitResponseCommand {
43 public: 39 public:
44 40 static sync_pb::CommitResponse::ResponseType ProcessSingleCommitResponse(
Nicolas Zea 2013/10/09 00:17:39 Again, seems odd to have a class with nothing but
rlarocque 2013/10/09 20:00:19 I agree. I could make these functions standalone,
45 // The commit_set parameter contains references to all the items which were
46 // to be committed in this batch.
47 //
48 // The commmit_message parameter contains the message that was sent to the
49 // server.
50 //
51 // The commit_response parameter contains the response received from the
52 // server. This may be uninitialized if we were unable to contact the server
53 // or a serious error was encountered.
54 ProcessCommitResponseCommand(
55 const sessions::OrderedCommitSet& commit_set,
56 const sync_pb::ClientToServerMessage& commit_message,
57 const sync_pb::ClientToServerResponse& commit_response);
58 virtual ~ProcessCommitResponseCommand();
59
60 protected:
61 // SyncerCommand implementation.
62 virtual SyncerError ExecuteImpl(sessions::SyncSession* session) OVERRIDE;
63
64 private:
65 sync_pb::CommitResponse::ResponseType ProcessSingleCommitResponse(
66 syncable::ModelNeutralWriteTransaction* trans, 41 syncable::ModelNeutralWriteTransaction* trans,
67 const sync_pb::CommitResponse_EntryResponse& pb_commit_response, 42 const sync_pb::CommitResponse_EntryResponse& pb_commit_response,
68 const sync_pb::SyncEntity& pb_committed_entry, 43 const sync_pb::SyncEntity& pb_committed_entry,
69 int64 metahandle, 44 int64 metahandle,
70 std::set<syncable::Id>* deleted_folders); 45 std::set<syncable::Id>* deleted_folders);
71 46
72 void ProcessSuccessfulCommitResponse( 47 private:
48 static void ProcessSuccessfulCommitResponse(
73 const sync_pb::SyncEntity& committed_entry, 49 const sync_pb::SyncEntity& committed_entry,
74 const sync_pb::CommitResponse_EntryResponse& entry_response, 50 const sync_pb::CommitResponse_EntryResponse& entry_response,
75 const syncable::Id& pre_commit_id, 51 const syncable::Id& pre_commit_id,
76 syncable::ModelNeutralMutableEntry* local_entry, 52 syncable::ModelNeutralMutableEntry* local_entry,
77 bool syncing_was_set, std::set<syncable::Id>* deleted_folders); 53 bool syncing_was_set, std::set<syncable::Id>* deleted_folders);
78 54
79 // Update the BASE_VERSION and SERVER_VERSION, post-commit. 55 // Update the BASE_VERSION and SERVER_VERSION, post-commit.
80 // Helper for ProcessSuccessfulCommitResponse. 56 // Helper for ProcessSuccessfulCommitResponse.
81 bool UpdateVersionAfterCommit( 57 static bool UpdateVersionAfterCommit(
82 const sync_pb::SyncEntity& committed_entry, 58 const sync_pb::SyncEntity& committed_entry,
83 const sync_pb::CommitResponse_EntryResponse& entry_response, 59 const sync_pb::CommitResponse_EntryResponse& entry_response,
84 const syncable::Id& pre_commit_id, 60 const syncable::Id& pre_commit_id,
85 syncable::ModelNeutralMutableEntry* local_entry); 61 syncable::ModelNeutralMutableEntry* local_entry);
86 62
87 // If the server generated an ID for us during a commit, apply the new ID. 63 // If the server generated an ID for us during a commit, apply the new ID.
88 // Helper for ProcessSuccessfulCommitResponse. 64 // Helper for ProcessSuccessfulCommitResponse.
89 bool ChangeIdAfterCommit( 65 static bool ChangeIdAfterCommit(
90 const sync_pb::CommitResponse_EntryResponse& entry_response, 66 const sync_pb::CommitResponse_EntryResponse& entry_response,
91 const syncable::Id& pre_commit_id, 67 const syncable::Id& pre_commit_id,
92 syncable::ModelNeutralMutableEntry* local_entry); 68 syncable::ModelNeutralMutableEntry* local_entry);
93 69
94 // Update the SERVER_ fields to reflect the server state after committing. 70 // Update the SERVER_ fields to reflect the server state after committing.
95 // Helper for ProcessSuccessfulCommitResponse. 71 // Helper for ProcessSuccessfulCommitResponse.
96 void UpdateServerFieldsAfterCommit( 72 static void UpdateServerFieldsAfterCommit(
97 const sync_pb::SyncEntity& committed_entry, 73 const sync_pb::SyncEntity& committed_entry,
98 const sync_pb::CommitResponse_EntryResponse& entry_response, 74 const sync_pb::CommitResponse_EntryResponse& entry_response,
99 syncable::ModelNeutralMutableEntry* local_entry); 75 syncable::ModelNeutralMutableEntry* local_entry);
100 76
101 // Helper to extract the final name from the protobufs. 77 // Helper to extract the final name from the protobufs.
102 const std::string& GetResultingPostCommitName( 78 static const std::string& GetResultingPostCommitName(
103 const sync_pb::SyncEntity& committed_entry, 79 const sync_pb::SyncEntity& committed_entry,
104 const sync_pb::CommitResponse_EntryResponse& entry_response); 80 const sync_pb::CommitResponse_EntryResponse& entry_response);
105 81
106 // Helper to clean up in case of failure. 82 DISALLOW_IMPLICIT_CONSTRUCTORS(ProcessCommitResponseCommand);
107 void ClearSyncingBits(
108 syncable::Directory *dir,
109 const std::vector<syncable::Id>& commit_ids);
110
111 const sessions::OrderedCommitSet& commit_set_;
112 const sync_pb::ClientToServerMessage& commit_message_;
113 const sync_pb::ClientToServerResponse& commit_response_;
114
115 DISALLOW_COPY_AND_ASSIGN(ProcessCommitResponseCommand);
116 }; 83 };
117 84
118 } // namespace syncer 85 } // namespace syncer
119 86
120 #endif // SYNC_ENGINE_PROCESS_COMMIT_RESPONSE_COMMAND_H_ 87 #endif // SYNC_ENGINE_PROCESS_COMMIT_RESPONSE_COMMAND_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698