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

Side by Side Diff: sync/engine/commit.cc

Issue 15764010: Experimental functionize patch (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync: Expose sync functionality as functions Created 7 years, 6 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
« no previous file with comments | « sync/engine/commit.h ('k') | sync/engine/download.h » ('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 #include "sync/engine/commit.h" 5 #include "sync/engine/commit.h"
6 6
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "sync/engine/build_commit_command.h" 8 #include "sync/engine/build_commit_command.h"
9 #include "sync/engine/get_commit_ids_command.h" 9 #include "sync/engine/get_commit_ids_command.h"
10 #include "sync/engine/process_commit_response_command.h" 10 #include "sync/engine/process_commit_response_command.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 // The OrderedCommitSet parameter is an output parameter which will contain 56 // The OrderedCommitSet parameter is an output parameter which will contain
57 // the set of all items which are to be committed. The number of items in 57 // the set of all items which are to be committed. The number of items in
58 // the set shall not exceed the maximum batch size. (The default batch size 58 // the set shall not exceed the maximum batch size. (The default batch size
59 // is currently 25, though it can be overwritten by the server.) 59 // is currently 25, though it can be overwritten by the server.)
60 // 60 //
61 // The ClientToServerMessage parameter is an output parameter which will contain 61 // The ClientToServerMessage parameter is an output parameter which will contain
62 // the commit message which should be sent to the server. It is valid iff the 62 // the commit message which should be sent to the server. It is valid iff the
63 // return value of this function is true. 63 // return value of this function is true.
64 bool PrepareCommitMessage( 64 bool PrepareCommitMessage(
65 sessions::SyncSession* session, 65 sessions::SyncSession* session,
66 ModelTypeSet requested_types,
66 sessions::OrderedCommitSet* commit_set, 67 sessions::OrderedCommitSet* commit_set,
67 sync_pb::ClientToServerMessage* commit_message, 68 sync_pb::ClientToServerMessage* commit_message,
68 ExtensionsActivityMonitor::Records* extensions_activity_buffer) { 69 ExtensionsActivityMonitor::Records* extensions_activity_buffer) {
69 TRACE_EVENT0("sync", "PrepareCommitMessage"); 70 TRACE_EVENT0("sync", "PrepareCommitMessage");
70 71
71 commit_set->Clear(); 72 commit_set->Clear();
72 commit_message->Clear(); 73 commit_message->Clear();
73 74
74 WriteTransaction trans(FROM_HERE, SYNCER, session->context()->directory()); 75 WriteTransaction trans(FROM_HERE, SYNCER, session->context()->directory());
75 76
76 // Fetch the items to commit. 77 // Fetch the items to commit.
77 const size_t batch_size = session->context()->max_commit_batch_size(); 78 const size_t batch_size = session->context()->max_commit_batch_size();
78 GetCommitIdsCommand get_commit_ids_command(&trans, batch_size, commit_set); 79 GetCommitIdsCommand get_commit_ids_command(&trans,
80 requested_types,
81 batch_size,
82 commit_set);
79 get_commit_ids_command.Execute(session); 83 get_commit_ids_command.Execute(session);
80 84
81 DVLOG(1) << "Commit message will contain " << commit_set->Size() << " items."; 85 DVLOG(1) << "Commit message will contain " << commit_set->Size() << " items.";
82 if (commit_set->Empty()) { 86 if (commit_set->Empty()) {
83 return false; 87 return false;
84 } 88 }
85 89
86 // Serialize the message. 90 // Serialize the message.
87 BuildCommitCommand build_commit_command(&trans, 91 BuildCommitCommand build_commit_command(&trans,
88 *commit_set, 92 *commit_set,
89 commit_message, 93 commit_message,
90 extensions_activity_buffer); 94 extensions_activity_buffer);
91 build_commit_command.Execute(session); 95 build_commit_command.Execute(session);
92 96
93 SetSyncingBits(&trans, *commit_set); 97 SetSyncingBits(&trans, *commit_set);
94 return true; 98 return true;
95 } 99 }
96 100
97 SyncerError BuildAndPostCommitsImpl(Syncer* syncer, 101 SyncerError BuildAndPostCommitsImpl(ModelTypeSet requested_types,
102 Syncer* syncer,
98 sessions::SyncSession* session, 103 sessions::SyncSession* session,
99 sessions::OrderedCommitSet* commit_set) { 104 sessions::OrderedCommitSet* commit_set) {
100 while (!syncer->ExitRequested()) { 105 while (!syncer->ExitRequested()) {
101 sync_pb::ClientToServerMessage commit_message; 106 sync_pb::ClientToServerMessage commit_message;
102 ExtensionsActivityMonitor::Records extensions_activity_buffer; 107 ExtensionsActivityMonitor::Records extensions_activity_buffer;
103 108
104 if (!PrepareCommitMessage(session, 109 if (!PrepareCommitMessage(session,
110 requested_types,
105 commit_set, 111 commit_set,
106 &commit_message, 112 &commit_message,
107 &extensions_activity_buffer)) { 113 &extensions_activity_buffer)) {
108 break; 114 break;
109 } 115 }
110 116
111 sync_pb::ClientToServerResponse commit_response; 117 sync_pb::ClientToServerResponse commit_response;
112 118
113 DVLOG(1) << "Sending commit message."; 119 DVLOG(1) << "Sending commit message.";
114 TRACE_EVENT_BEGIN0("sync", "PostCommit"); 120 TRACE_EVENT_BEGIN0("sync", "PostCommit");
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 } 164 }
159 session->SendEventNotification(SyncEngineEvent::STATUS_CHANGED); 165 session->SendEventNotification(SyncEngineEvent::STATUS_CHANGED);
160 } 166 }
161 167
162 return SYNCER_OK; 168 return SYNCER_OK;
163 } 169 }
164 170
165 } // namespace 171 } // namespace
166 172
167 173
168 SyncerError BuildAndPostCommits(Syncer* syncer, 174 SyncerError BuildAndPostCommits(ModelTypeSet requested_types,
175 Syncer* syncer,
169 sessions::SyncSession* session) { 176 sessions::SyncSession* session) {
170 sessions::OrderedCommitSet commit_set(session->context()->routing_info()); 177 sessions::OrderedCommitSet commit_set(session->context()->routing_info());
171 SyncerError result = BuildAndPostCommitsImpl(syncer, session, &commit_set); 178 SyncerError result =
179 BuildAndPostCommitsImpl(requested_types, syncer, session, &commit_set);
172 if (result != SYNCER_OK) { 180 if (result != SYNCER_OK) {
173 ClearSyncingBits(session->context()->directory(), commit_set); 181 ClearSyncingBits(session->context()->directory(), commit_set);
174 } 182 }
175 return result; 183 return result;
176 } 184 }
177 185
178 } // namespace syncer 186 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/commit.h ('k') | sync/engine/download.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698