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

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

Issue 10210009: sync: Loop committing items without downloading updates (v2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 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/build_commit_command.h ('k') | sync/engine/build_commit_command_unittest.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/build_commit_command.h" 5 #include "sync/engine/build_commit_command.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "sync/engine/syncer_proto_util.h" 13 #include "sync/engine/syncer_proto_util.h"
14 #include "sync/protocol/bookmark_specifics.pb.h" 14 #include "sync/protocol/bookmark_specifics.pb.h"
15 #include "sync/sessions/ordered_commit_set.h"
15 #include "sync/sessions/sync_session.h" 16 #include "sync/sessions/sync_session.h"
17 #include "sync/syncable/syncable_changes_version.h"
16 #include "sync/syncable/syncable.h" 18 #include "sync/syncable/syncable.h"
17 #include "sync/syncable/syncable_changes_version.h"
18 #include "sync/util/time.h" 19 #include "sync/util/time.h"
19 20
20 using std::set; 21 using std::set;
21 using std::string; 22 using std::string;
22 using std::vector; 23 using std::vector;
23 using syncable::Entry; 24 using syncable::Entry;
24 using syncable::IS_DEL; 25 using syncable::IS_DEL;
25 using syncable::SERVER_POSITION_IN_PARENT; 26 using syncable::SERVER_POSITION_IN_PARENT;
26 using syncable::IS_UNAPPLIED_UPDATE; 27 using syncable::IS_UNAPPLIED_UPDATE;
27 using syncable::IS_UNSYNCED; 28 using syncable::IS_UNSYNCED;
(...skipping 14 matching lines...) Expand all
42 // static 43 // static
43 int64 BuildCommitCommand::GetLastPosition() { 44 int64 BuildCommitCommand::GetLastPosition() {
44 return std::numeric_limits<int64>::max(); 45 return std::numeric_limits<int64>::max();
45 } 46 }
46 47
47 // static 48 // static
48 int64 BuildCommitCommand::GetGap() { 49 int64 BuildCommitCommand::GetGap() {
49 return 1LL << 20; 50 return 1LL << 20;
50 } 51 }
51 52
52 BuildCommitCommand::BuildCommitCommand() {} 53 BuildCommitCommand::BuildCommitCommand(
54 const sessions::OrderedCommitSet& batch_commit_set,
55 ClientToServerMessage* commit_message)
56 : batch_commit_set_(batch_commit_set), commit_message_(commit_message) {
57 }
58
53 BuildCommitCommand::~BuildCommitCommand() {} 59 BuildCommitCommand::~BuildCommitCommand() {}
54 60
55 void BuildCommitCommand::AddExtensionsActivityToMessage( 61 void BuildCommitCommand::AddExtensionsActivityToMessage(
56 SyncSession* session, CommitMessage* message) { 62 SyncSession* session, CommitMessage* message) {
57 // We only send ExtensionsActivity to the server if bookmarks are being 63 // We only send ExtensionsActivity to the server if bookmarks are being
58 // committed. 64 // committed.
59 ExtensionsActivityMonitor* monitor = session->context()->extensions_monitor(); 65 ExtensionsActivityMonitor* monitor = session->context()->extensions_monitor();
60 if (!session->status_controller().HasBookmarkCommitActivity()) { 66 if (batch_commit_set_.HasBookmarkCommitId()) {
61 // Return the records to the activity monitor. 67 // This isn't perfect, since the set of extensions activity may not
62 monitor->PutRecords(session->extensions_activity()); 68 // correlate exactly with the items being committed. That's OK as
63 session->mutable_extensions_activity()->clear(); 69 // long as we're looking for a rough estimate of extensions activity,
64 return; 70 // not an precise mapping of which commits were triggered by which
65 } 71 // extension.
66 const ExtensionsActivityMonitor::Records& records = 72 //
67 session->extensions_activity(); 73 // We will push this list of extensions activity back into the
68 for (ExtensionsActivityMonitor::Records::const_iterator it = records.begin(); 74 // ExtensionsActivityMonitor if this commit fails. That's why we must keep
69 it != records.end(); ++it) { 75 // a copy of these records in the session.
70 sync_pb::ChromiumExtensionsActivity* activity_message = 76 monitor->GetAndClearRecords(session->mutable_extensions_activity());
71 message->add_extensions_activity(); 77
72 activity_message->set_extension_id(it->second.extension_id); 78 const ExtensionsActivityMonitor::Records& records =
73 activity_message->set_bookmark_writes_since_last_commit( 79 session->extensions_activity();
74 it->second.bookmark_write_count); 80 for (ExtensionsActivityMonitor::Records::const_iterator it =
81 records.begin();
82 it != records.end(); ++it) {
83 sync_pb::ChromiumExtensionsActivity* activity_message =
84 message->add_extensions_activity();
85 activity_message->set_extension_id(it->second.extension_id);
86 activity_message->set_bookmark_writes_since_last_commit(
87 it->second.bookmark_write_count);
88 }
75 } 89 }
76 } 90 }
77 91
78 namespace { 92 namespace {
79 void SetEntrySpecifics(MutableEntry* meta_entry, SyncEntity* sync_entry) { 93 void SetEntrySpecifics(MutableEntry* meta_entry, SyncEntity* sync_entry) {
80 // Add the new style extension and the folder bit. 94 // Add the new style extension and the folder bit.
81 sync_entry->mutable_specifics()->CopyFrom(meta_entry->Get(SPECIFICS)); 95 sync_entry->mutable_specifics()->CopyFrom(meta_entry->Get(SPECIFICS));
82 sync_entry->set_folder(meta_entry->Get(syncable::IS_DIR)); 96 sync_entry->set_folder(meta_entry->Get(syncable::IS_DIR));
83 97
84 DCHECK(meta_entry->GetModelType() == sync_entry->GetModelType()); 98 DCHECK(meta_entry->GetModelType() == sync_entry->GetModelType());
85 } 99 }
86 } // namespace 100 } // namespace
87 101
88 SyncerError BuildCommitCommand::ExecuteImpl(SyncSession* session) { 102 SyncerError BuildCommitCommand::ExecuteImpl(SyncSession* session) {
89 ClientToServerMessage message; 103 commit_message_->set_share(session->context()->account_name());
90 message.set_share(session->context()->account_name()); 104 commit_message_->set_message_contents(ClientToServerMessage::COMMIT);
91 message.set_message_contents(ClientToServerMessage::COMMIT);
92 105
93 CommitMessage* commit_message = message.mutable_commit(); 106 CommitMessage* commit_message = commit_message_->mutable_commit();
94 commit_message->set_cache_guid( 107 commit_message->set_cache_guid(
95 session->write_transaction()->directory()->cache_guid()); 108 session->write_transaction()->directory()->cache_guid());
96 AddExtensionsActivityToMessage(session, commit_message); 109 AddExtensionsActivityToMessage(session, commit_message);
97 SyncerProtoUtil::AddRequestBirthday( 110 SyncerProtoUtil::AddRequestBirthday(
98 session->write_transaction()->directory(), &message); 111 session->write_transaction()->directory(), commit_message_);
99 112
100 // Cache previously computed position values. Because |commit_ids| 113 // Cache previously computed position values. Because |commit_ids|
101 // is already in sibling order, we should always hit this map after 114 // is already in sibling order, we should always hit this map after
102 // the first sibling in a consecutive run of commit items. The 115 // the first sibling in a consecutive run of commit items. The
103 // entries in this map are (low, high) values describing the 116 // entries in this map are (low, high) values describing the
104 // space of positions that are immediate successors of the item 117 // space of positions that are immediate successors of the item
105 // whose ID is the map's key. 118 // whose ID is the map's key.
106 std::map<Id, std::pair<int64, int64> > position_map; 119 std::map<Id, std::pair<int64, int64> > position_map;
107 120
108 const vector<Id>& commit_ids = session->status_controller().commit_ids(); 121 for (size_t i = 0; i < batch_commit_set_.Size(); i++) {
109 for (size_t i = 0; i < commit_ids.size(); i++) { 122 Id id = batch_commit_set_.GetCommitIdAt(i);
110 Id id = commit_ids[i];
111 SyncEntity* sync_entry = 123 SyncEntity* sync_entry =
112 static_cast<SyncEntity*>(commit_message->add_entries()); 124 static_cast<SyncEntity*>(commit_message->add_entries());
113 sync_entry->set_id(id); 125 sync_entry->set_id(id);
114 MutableEntry meta_entry(session->write_transaction(), 126 MutableEntry meta_entry(session->write_transaction(),
115 syncable::GET_BY_ID, 127 syncable::GET_BY_ID,
116 id); 128 id);
117 CHECK(meta_entry.good()); 129 CHECK(meta_entry.good());
118 // This is the only change we make to the entry in this function. 130 // This is the only change we make to the entry in this function.
119 meta_entry.Put(syncable::SYNCING, true); 131 meta_entry.Put(syncable::SYNCING, true);
120 132
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 } 213 }
202 position_block.first = InterpolatePosition(position_block.first, 214 position_block.first = InterpolatePosition(position_block.first,
203 position_block.second); 215 position_block.second);
204 216
205 position_map[id] = position_block; 217 position_map[id] = position_block;
206 sync_entry->set_position_in_parent(position_block.first); 218 sync_entry->set_position_in_parent(position_block.first);
207 } 219 }
208 SetEntrySpecifics(&meta_entry, sync_entry); 220 SetEntrySpecifics(&meta_entry, sync_entry);
209 } 221 }
210 } 222 }
211 session->mutable_status_controller()->
212 mutable_commit_message()->CopyFrom(message);
213 223
214 return SYNCER_OK; 224 return SYNCER_OK;
215 } 225 }
216 226
217 int64 BuildCommitCommand::FindAnchorPosition(syncable::IdField direction, 227 int64 BuildCommitCommand::FindAnchorPosition(syncable::IdField direction,
218 const syncable::Entry& entry) { 228 const syncable::Entry& entry) {
219 Id next_id = entry.Get(direction); 229 Id next_id = entry.Get(direction);
220 while (!next_id.IsRoot()) { 230 while (!next_id.IsRoot()) {
221 Entry next_entry(entry.trans(), 231 Entry next_entry(entry.trans(),
222 syncable::GET_BY_ID, 232 syncable::GET_BY_ID,
(...skipping 23 matching lines...) Expand all
246 if (delta <= static_cast<uint64>(GetGap()*2)) 256 if (delta <= static_cast<uint64>(GetGap()*2))
247 return lo + (static_cast<int64>(delta) + 7) / 8; // Interpolate. 257 return lo + (static_cast<int64>(delta) + 7) / 8; // Interpolate.
248 else if (lo == GetFirstPosition()) 258 else if (lo == GetFirstPosition())
249 return hi - GetGap(); // Extend range just before successor. 259 return hi - GetGap(); // Extend range just before successor.
250 else 260 else
251 return lo + GetGap(); // Use or extend range just after predecessor. 261 return lo + GetGap(); // Use or extend range just after predecessor.
252 } 262 }
253 263
254 264
255 } // namespace browser_sync 265 } // namespace browser_sync
OLDNEW
« no previous file with comments | « sync/engine/build_commit_command.h ('k') | sync/engine/build_commit_command_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698