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/build_commit_command.cc

Issue 10038041: sync: Loop committing items without downloading updates (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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 (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 // Return the records to the activity monitor.
62 monitor->PutRecords(session->extensions_activity()); 68 monitor->PutRecords(session->extensions_activity());
63 session->mutable_extensions_activity()->clear(); 69 session->mutable_extensions_activity()->clear();
64 return; 70 return;
65 } 71 }
66 const ExtensionsActivityMonitor::Records& records = 72 const ExtensionsActivityMonitor::Records& records =
67 session->extensions_activity(); 73 session->extensions_activity();
68 for (ExtensionsActivityMonitor::Records::const_iterator it = records.begin(); 74 for (ExtensionsActivityMonitor::Records::const_iterator it = records.begin();
69 it != records.end(); ++it) { 75 it != records.end(); ++it) {
70 sync_pb::ChromiumExtensionsActivity* activity_message = 76 sync_pb::ChromiumExtensionsActivity* activity_message =
71 message->add_extensions_activity(); 77 message->add_extensions_activity();
72 activity_message->set_extension_id(it->second.extension_id); 78 activity_message->set_extension_id(it->second.extension_id);
73 activity_message->set_bookmark_writes_since_last_commit( 79 activity_message->set_bookmark_writes_since_last_commit(
74 it->second.bookmark_write_count); 80 it->second.bookmark_write_count);
75 } 81 }
76 } 82 }
77 83
78 namespace { 84 namespace {
79 void SetEntrySpecifics(MutableEntry* meta_entry, SyncEntity* sync_entry) { 85 void SetEntrySpecifics(MutableEntry* meta_entry, SyncEntity* sync_entry) {
80 // Add the new style extension and the folder bit. 86 // Add the new style extension and the folder bit.
81 sync_entry->mutable_specifics()->CopyFrom(meta_entry->Get(SPECIFICS)); 87 sync_entry->mutable_specifics()->CopyFrom(meta_entry->Get(SPECIFICS));
82 sync_entry->set_folder(meta_entry->Get(syncable::IS_DIR)); 88 sync_entry->set_folder(meta_entry->Get(syncable::IS_DIR));
83 89
84 DCHECK(meta_entry->GetModelType() == sync_entry->GetModelType()); 90 DCHECK(meta_entry->GetModelType() == sync_entry->GetModelType());
85 } 91 }
86 } // namespace 92 } // namespace
87 93
88 SyncerError BuildCommitCommand::ExecuteImpl(SyncSession* session) { 94 SyncerError BuildCommitCommand::ExecuteImpl(SyncSession* session) {
89 ClientToServerMessage message; 95 commit_message_->set_share(session->context()->account_name());
90 message.set_share(session->context()->account_name()); 96 commit_message_->set_message_contents(ClientToServerMessage::COMMIT);
91 message.set_message_contents(ClientToServerMessage::COMMIT);
92 97
93 CommitMessage* commit_message = message.mutable_commit(); 98 CommitMessage* commit_message = commit_message_->mutable_commit();
94 commit_message->set_cache_guid( 99 commit_message->set_cache_guid(
95 session->write_transaction()->directory()->cache_guid()); 100 session->write_transaction()->directory()->cache_guid());
96 AddExtensionsActivityToMessage(session, commit_message); 101 AddExtensionsActivityToMessage(session, commit_message);
97 SyncerProtoUtil::AddRequestBirthday( 102 SyncerProtoUtil::AddRequestBirthday(
98 session->write_transaction()->directory(), &message); 103 session->write_transaction()->directory(), commit_message_);
99 104
100 // Cache previously computed position values. Because |commit_ids| 105 // Cache previously computed position values. Because |commit_ids|
101 // is already in sibling order, we should always hit this map after 106 // is already in sibling order, we should always hit this map after
102 // the first sibling in a consecutive run of commit items. The 107 // the first sibling in a consecutive run of commit items. The
103 // entries in this map are (low, high) values describing the 108 // entries in this map are (low, high) values describing the
104 // space of positions that are immediate successors of the item 109 // space of positions that are immediate successors of the item
105 // whose ID is the map's key. 110 // whose ID is the map's key.
106 std::map<Id, std::pair<int64, int64> > position_map; 111 std::map<Id, std::pair<int64, int64> > position_map;
107 112
108 const vector<Id>& commit_ids = session->status_controller().commit_ids(); 113 for (size_t i = 0; i < batch_commit_set_.Size(); i++) {
109 for (size_t i = 0; i < commit_ids.size(); i++) { 114 Id id = batch_commit_set_.GetCommitIdAt(i);
110 Id id = commit_ids[i];
111 SyncEntity* sync_entry = 115 SyncEntity* sync_entry =
112 static_cast<SyncEntity*>(commit_message->add_entries()); 116 static_cast<SyncEntity*>(commit_message->add_entries());
113 sync_entry->set_id(id); 117 sync_entry->set_id(id);
114 MutableEntry meta_entry(session->write_transaction(), 118 MutableEntry meta_entry(session->write_transaction(),
115 syncable::GET_BY_ID, 119 syncable::GET_BY_ID,
116 id); 120 id);
117 CHECK(meta_entry.good()); 121 CHECK(meta_entry.good());
118 // This is the only change we make to the entry in this function. 122 // This is the only change we make to the entry in this function.
119 meta_entry.Put(syncable::SYNCING, true); 123 meta_entry.Put(syncable::SYNCING, true);
120 124
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 } 205 }
202 position_block.first = InterpolatePosition(position_block.first, 206 position_block.first = InterpolatePosition(position_block.first,
203 position_block.second); 207 position_block.second);
204 208
205 position_map[id] = position_block; 209 position_map[id] = position_block;
206 sync_entry->set_position_in_parent(position_block.first); 210 sync_entry->set_position_in_parent(position_block.first);
207 } 211 }
208 SetEntrySpecifics(&meta_entry, sync_entry); 212 SetEntrySpecifics(&meta_entry, sync_entry);
209 } 213 }
210 } 214 }
211 session->mutable_status_controller()->
212 mutable_commit_message()->CopyFrom(message);
213 215
214 return SYNCER_OK; 216 return SYNCER_OK;
215 } 217 }
216 218
217 int64 BuildCommitCommand::FindAnchorPosition(syncable::IdField direction, 219 int64 BuildCommitCommand::FindAnchorPosition(syncable::IdField direction,
218 const syncable::Entry& entry) { 220 const syncable::Entry& entry) {
219 Id next_id = entry.Get(direction); 221 Id next_id = entry.Get(direction);
220 while (!next_id.IsRoot()) { 222 while (!next_id.IsRoot()) {
221 Entry next_entry(entry.trans(), 223 Entry next_entry(entry.trans(),
222 syncable::GET_BY_ID, 224 syncable::GET_BY_ID,
(...skipping 23 matching lines...) Expand all
246 if (delta <= static_cast<uint64>(GetGap()*2)) 248 if (delta <= static_cast<uint64>(GetGap()*2))
247 return lo + (static_cast<int64>(delta) + 7) / 8; // Interpolate. 249 return lo + (static_cast<int64>(delta) + 7) / 8; // Interpolate.
248 else if (lo == GetFirstPosition()) 250 else if (lo == GetFirstPosition())
249 return hi - GetGap(); // Extend range just before successor. 251 return hi - GetGap(); // Extend range just before successor.
250 else 252 else
251 return lo + GetGap(); // Use or extend range just after predecessor. 253 return lo + GetGap(); // Use or extend range just after predecessor.
252 } 254 }
253 255
254 256
255 } // namespace browser_sync 257 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698