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

Side by Side Diff: chrome/browser/sync/engine/syncer.cc

Issue 371029: Remove unique naming. (Closed)
Patch Set: Ready and about to go in! Created 11 years, 1 month 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 | « chrome/browser/sync/engine/syncer.h ('k') | chrome/browser/sync/engine/syncer_proto_util.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 (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 entry. 3 // found in the LICENSE entry.
4 4
5 #include "chrome/browser/sync/engine/syncer.h" 5 #include "chrome/browser/sync/engine/syncer.h"
6 6
7 #include "base/format_macros.h" 7 #include "base/format_macros.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "chrome/browser/chrome_thread.h" 9 #include "chrome/browser/chrome_thread.h"
10 #include "chrome/browser/sync/engine/apply_updates_command.h" 10 #include "chrome/browser/sync/engine/apply_updates_command.h"
11 #include "chrome/browser/sync/engine/build_and_process_conflict_sets_command.h" 11 #include "chrome/browser/sync/engine/build_and_process_conflict_sets_command.h"
12 #include "chrome/browser/sync/engine/build_commit_command.h" 12 #include "chrome/browser/sync/engine/build_commit_command.h"
13 #include "chrome/browser/sync/engine/conflict_resolver.h" 13 #include "chrome/browser/sync/engine/conflict_resolver.h"
14 #include "chrome/browser/sync/engine/download_updates_command.h" 14 #include "chrome/browser/sync/engine/download_updates_command.h"
15 #include "chrome/browser/sync/engine/get_commit_ids_command.h" 15 #include "chrome/browser/sync/engine/get_commit_ids_command.h"
16 #include "chrome/browser/sync/engine/net/server_connection_manager.h" 16 #include "chrome/browser/sync/engine/net/server_connection_manager.h"
17 #include "chrome/browser/sync/engine/post_commit_message_command.h" 17 #include "chrome/browser/sync/engine/post_commit_message_command.h"
18 #include "chrome/browser/sync/engine/process_commit_response_command.h" 18 #include "chrome/browser/sync/engine/process_commit_response_command.h"
19 #include "chrome/browser/sync/engine/process_updates_command.h" 19 #include "chrome/browser/sync/engine/process_updates_command.h"
20 #include "chrome/browser/sync/engine/resolve_conflicts_command.h" 20 #include "chrome/browser/sync/engine/resolve_conflicts_command.h"
21 #include "chrome/browser/sync/engine/syncer_end_command.h" 21 #include "chrome/browser/sync/engine/syncer_end_command.h"
22 #include "chrome/browser/sync/engine/syncer_types.h" 22 #include "chrome/browser/sync/engine/syncer_types.h"
23 #include "chrome/browser/sync/engine/syncer_util.h" 23 #include "chrome/browser/sync/engine/syncer_util.h"
24 #include "chrome/browser/sync/engine/syncproto.h" 24 #include "chrome/browser/sync/engine/syncproto.h"
25 #include "chrome/browser/sync/engine/verify_updates_command.h" 25 #include "chrome/browser/sync/engine/verify_updates_command.h"
26 #include "chrome/browser/sync/syncable/directory_manager.h" 26 #include "chrome/browser/sync/syncable/directory_manager.h"
27 #include "chrome/browser/sync/syncable/syncable-inl.h" 27 #include "chrome/browser/sync/syncable/syncable-inl.h"
28 #include "chrome/browser/sync/syncable/syncable.h" 28 #include "chrome/browser/sync/syncable/syncable.h"
29 #include "chrome/browser/sync/util/closure.h"
29 30
30 using sync_pb::ClientCommand; 31 using sync_pb::ClientCommand;
31 using syncable::Blob; 32 using syncable::Blob;
32 using syncable::IS_UNAPPLIED_UPDATE; 33 using syncable::IS_UNAPPLIED_UPDATE;
33 using syncable::SERVER_BOOKMARK_FAVICON; 34 using syncable::SERVER_BOOKMARK_FAVICON;
34 using syncable::SERVER_BOOKMARK_URL; 35 using syncable::SERVER_BOOKMARK_URL;
35 using syncable::SERVER_CTIME; 36 using syncable::SERVER_CTIME;
36 using syncable::SERVER_IS_BOOKMARK_OBJECT; 37 using syncable::SERVER_IS_BOOKMARK_OBJECT;
37 using syncable::SERVER_IS_DEL; 38 using syncable::SERVER_IS_DEL;
38 using syncable::SERVER_IS_DIR; 39 using syncable::SERVER_IS_DIR;
39 using syncable::SERVER_MTIME; 40 using syncable::SERVER_MTIME;
40 using syncable::SERVER_NAME;
41 using syncable::SERVER_NON_UNIQUE_NAME; 41 using syncable::SERVER_NON_UNIQUE_NAME;
42 using syncable::SERVER_PARENT_ID; 42 using syncable::SERVER_PARENT_ID;
43 using syncable::SERVER_POSITION_IN_PARENT; 43 using syncable::SERVER_POSITION_IN_PARENT;
44 using syncable::SERVER_VERSION; 44 using syncable::SERVER_VERSION;
45 using syncable::SYNCER; 45 using syncable::SYNCER;
46 using syncable::ScopedDirLookup; 46 using syncable::ScopedDirLookup;
47 using syncable::WriteTransaction; 47 using syncable::WriteTransaction;
48 48
49 namespace browser_sync { 49 namespace browser_sync {
50 50
51 Syncer::Syncer( 51 Syncer::Syncer(
52 syncable::DirectoryManager* dirman, 52 syncable::DirectoryManager* dirman,
53 const PathString& account_name, 53 const PathString& account_name,
54 ServerConnectionManager* connection_manager, 54 ServerConnectionManager* connection_manager,
55 ModelSafeWorker* model_safe_worker) 55 ModelSafeWorker* model_safe_worker)
56 : account_name_(account_name), 56 : account_name_(account_name),
57 early_exit_requested_(false), 57 early_exit_requested_(false),
58 max_commit_batch_size_(kDefaultMaxCommitBatchSize), 58 max_commit_batch_size_(kDefaultMaxCommitBatchSize),
59 connection_manager_(connection_manager), 59 connection_manager_(connection_manager),
60 dirman_(dirman), 60 dirman_(dirman),
61 command_channel_(NULL), 61 command_channel_(NULL),
62 model_safe_worker_(model_safe_worker), 62 model_safe_worker_(model_safe_worker),
63 updates_source_(sync_pb::GetUpdatesCallerInfo::UNKNOWN), 63 updates_source_(sync_pb::GetUpdatesCallerInfo::UNKNOWN),
64 notifications_enabled_(false), 64 notifications_enabled_(false),
65 pre_conflict_resolution_function_(NULL) { 65 pre_conflict_resolution_closure_(NULL) {
66 SyncerEvent shutdown = { SyncerEvent::SHUTDOWN_USE_WITH_CARE }; 66 SyncerEvent shutdown = { SyncerEvent::SHUTDOWN_USE_WITH_CARE };
67 syncer_event_channel_.reset(new SyncerEventChannel(shutdown)); 67 syncer_event_channel_.reset(new SyncerEventChannel(shutdown));
68 shutdown_channel_.reset(new ShutdownChannel(this)); 68 shutdown_channel_.reset(new ShutdownChannel(this));
69 69
70 extensions_monitor_ = new ExtensionsActivityMonitor(); 70 extensions_monitor_ = new ExtensionsActivityMonitor();
71 71
72 ScopedDirLookup dir(dirman_, account_name_); 72 ScopedDirLookup dir(dirman_, account_name_);
73 // The directory must be good here. 73 // The directory must be good here.
74 CHECK(dir.good()); 74 CHECK(dir.good());
75 } 75 }
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 build_process_conflict_sets.Execute(session); 238 build_process_conflict_sets.Execute(session);
239 if (session->conflict_sets_built()) 239 if (session->conflict_sets_built())
240 next_step = SYNCER_END; 240 next_step = SYNCER_END;
241 else 241 else
242 next_step = RESOLVE_CONFLICTS; 242 next_step = RESOLVE_CONFLICTS;
243 break; 243 break;
244 } 244 }
245 case RESOLVE_CONFLICTS: { 245 case RESOLVE_CONFLICTS: {
246 LOG(INFO) << "Resolving Conflicts"; 246 LOG(INFO) << "Resolving Conflicts";
247 247
248 // Trigger the pre_conflict_resolution_function_, which is a testing 248 // Trigger the pre_conflict_resolution_closure_, which is a testing
249 // hook for the unit tests, if it is non-NULL. 249 // hook for the unit tests, if it is non-NULL.
250 if (pre_conflict_resolution_function_) { 250 if (pre_conflict_resolution_closure_) {
251 ScopedDirLookup dir(dirman_, account_name_); 251 pre_conflict_resolution_closure_->Run();
252 if (!dir.good()) {
253 LOG(ERROR) << "Bad dir lookup in syncer loop";
254 return;
255 }
256 pre_conflict_resolution_function_(dir);
257 } 252 }
258 253
259 ResolveConflictsCommand resolve_conflicts_command; 254 ResolveConflictsCommand resolve_conflicts_command;
260 resolve_conflicts_command.Execute(session); 255 resolve_conflicts_command.Execute(session);
261 if (session->HasConflictingUpdates()) 256 if (session->HasConflictingUpdates())
262 next_step = APPLY_UPDATES_TO_RESOLVE_CONFLICTS; 257 next_step = APPLY_UPDATES_TO_RESOLVE_CONFLICTS;
263 else 258 else
264 next_step = SYNCER_END; 259 next_step = SYNCER_END;
265 break; 260 break;
266 } 261 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 const ClientCommand command = session->update_response().client_command(); 300 const ClientCommand command = session->update_response().client_command();
306 if (command_channel_) 301 if (command_channel_)
307 command_channel_->NotifyListeners(&command); 302 command_channel_->NotifyListeners(&command);
308 303
309 // The server limits the number of items a client can commit in one batch. 304 // The server limits the number of items a client can commit in one batch.
310 if (command.has_max_commit_batch_size()) 305 if (command.has_max_commit_batch_size())
311 max_commit_batch_size_ = command.max_commit_batch_size(); 306 max_commit_batch_size_ = command.max_commit_batch_size();
312 } 307 }
313 308
314 void CopyServerFields(syncable::Entry* src, syncable::MutableEntry* dest) { 309 void CopyServerFields(syncable::Entry* src, syncable::MutableEntry* dest) {
315 dest->Put(SERVER_NAME, src->Get(SERVER_NAME));
316 dest->Put(SERVER_NON_UNIQUE_NAME, src->Get(SERVER_NON_UNIQUE_NAME)); 310 dest->Put(SERVER_NON_UNIQUE_NAME, src->Get(SERVER_NON_UNIQUE_NAME));
317 dest->Put(SERVER_PARENT_ID, src->Get(SERVER_PARENT_ID)); 311 dest->Put(SERVER_PARENT_ID, src->Get(SERVER_PARENT_ID));
318 dest->Put(SERVER_MTIME, src->Get(SERVER_MTIME)); 312 dest->Put(SERVER_MTIME, src->Get(SERVER_MTIME));
319 dest->Put(SERVER_CTIME, src->Get(SERVER_CTIME)); 313 dest->Put(SERVER_CTIME, src->Get(SERVER_CTIME));
320 dest->Put(SERVER_VERSION, src->Get(SERVER_VERSION)); 314 dest->Put(SERVER_VERSION, src->Get(SERVER_VERSION));
321 dest->Put(SERVER_IS_DIR, src->Get(SERVER_IS_DIR)); 315 dest->Put(SERVER_IS_DIR, src->Get(SERVER_IS_DIR));
322 dest->Put(SERVER_IS_DEL, src->Get(SERVER_IS_DEL)); 316 dest->Put(SERVER_IS_DEL, src->Get(SERVER_IS_DEL));
323 dest->Put(SERVER_IS_BOOKMARK_OBJECT, src->Get(SERVER_IS_BOOKMARK_OBJECT)); 317 dest->Put(SERVER_IS_BOOKMARK_OBJECT, src->Get(SERVER_IS_BOOKMARK_OBJECT));
324 dest->Put(IS_UNAPPLIED_UPDATE, src->Get(IS_UNAPPLIED_UPDATE)); 318 dest->Put(IS_UNAPPLIED_UPDATE, src->Get(IS_UNAPPLIED_UPDATE));
325 dest->Put(SERVER_BOOKMARK_URL, src->Get(SERVER_BOOKMARK_URL)); 319 dest->Put(SERVER_BOOKMARK_URL, src->Get(SERVER_BOOKMARK_URL));
326 dest->Put(SERVER_BOOKMARK_FAVICON, src->Get(SERVER_BOOKMARK_FAVICON)); 320 dest->Put(SERVER_BOOKMARK_FAVICON, src->Get(SERVER_BOOKMARK_FAVICON));
327 dest->Put(SERVER_POSITION_IN_PARENT, src->Get(SERVER_POSITION_IN_PARENT)); 321 dest->Put(SERVER_POSITION_IN_PARENT, src->Get(SERVER_POSITION_IN_PARENT));
328 } 322 }
329 323
330 void ClearServerData(syncable::MutableEntry* entry) { 324 void ClearServerData(syncable::MutableEntry* entry) {
331 entry->Put(SERVER_NAME, PSTR(""));
332 entry->Put(SERVER_NON_UNIQUE_NAME, PSTR("")); 325 entry->Put(SERVER_NON_UNIQUE_NAME, PSTR(""));
333 entry->Put(SERVER_PARENT_ID, syncable::kNullId); 326 entry->Put(SERVER_PARENT_ID, syncable::kNullId);
334 entry->Put(SERVER_MTIME, 0); 327 entry->Put(SERVER_MTIME, 0);
335 entry->Put(SERVER_CTIME, 0); 328 entry->Put(SERVER_CTIME, 0);
336 entry->Put(SERVER_VERSION, 0); 329 entry->Put(SERVER_VERSION, 0);
337 entry->Put(SERVER_IS_DIR, false); 330 entry->Put(SERVER_IS_DIR, false);
338 entry->Put(SERVER_IS_DEL, false); 331 entry->Put(SERVER_IS_DEL, false);
339 entry->Put(SERVER_IS_BOOKMARK_OBJECT, false); 332 entry->Put(SERVER_IS_BOOKMARK_OBJECT, false);
340 entry->Put(IS_UNAPPLIED_UPDATE, false); 333 entry->Put(IS_UNAPPLIED_UPDATE, false);
341 entry->Put(SERVER_BOOKMARK_URL, PSTR("")); 334 entry->Put(SERVER_BOOKMARK_URL, PSTR(""));
(...skipping 11 matching lines...) Expand all
353 entry.id_string().c_str(), 346 entry.id_string().c_str(),
354 entry.parent_id_string().c_str(), 347 entry.parent_id_string().c_str(),
355 entry.version(), 348 entry.version(),
356 entry.mtime(), ServerTimeToClientTime(entry.mtime()), 349 entry.mtime(), ServerTimeToClientTime(entry.mtime()),
357 entry.ctime(), ServerTimeToClientTime(entry.ctime()), 350 entry.ctime(), ServerTimeToClientTime(entry.ctime()),
358 entry.name().c_str(), entry.sync_timestamp(), 351 entry.name().c_str(), entry.sync_timestamp(),
359 entry.deleted() ? "deleted, ":""); 352 entry.deleted() ? "deleted, ":"");
360 } 353 }
361 354
362 } // namespace browser_sync 355 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/syncer.h ('k') | chrome/browser/sync/engine/syncer_proto_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698