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

Side by Side Diff: sync/internal_api/sync_manager.cc

Issue 10696087: [Sync] Move ModelType and related classes to 'syncer' namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sort headers, update copyrights Created 8 years, 5 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/internal_api/read_node.cc ('k') | sync/internal_api/syncapi_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/internal_api/public/sync_manager.h" 5 #include "sync/internal_api/public/sync_manager.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 // The maximum number of times we will automatically overwrite the nigori node 91 // The maximum number of times we will automatically overwrite the nigori node
92 // because the encryption keys don't match (per chrome instantiation). 92 // because the encryption keys don't match (per chrome instantiation).
93 static const int kNigoriOverwriteLimit = 10; 93 static const int kNigoriOverwriteLimit = 10;
94 94
95 } // namespace 95 } // namespace
96 96
97 namespace syncer { 97 namespace syncer {
98 98
99 using sessions::SyncSessionContext; 99 using sessions::SyncSessionContext;
100 using syncable::ImmutableWriteTransactionInfo; 100 using syncable::ImmutableWriteTransactionInfo;
101 using syncable::ModelType;
102 using syncable::ModelTypeSet;
103 using syncable::SPECIFICS; 101 using syncable::SPECIFICS;
104 102
105 const int SyncManager::kDefaultNudgeDelayMilliseconds = 200; 103 const int SyncManager::kDefaultNudgeDelayMilliseconds = 200;
106 const int SyncManager::kPreferencesNudgeDelayMilliseconds = 2000; 104 const int SyncManager::kPreferencesNudgeDelayMilliseconds = 2000;
107 105
108 // Maximum count and size for traffic recorder. 106 // Maximum count and size for traffic recorder.
109 const unsigned int kMaxMessagesToRecord = 10; 107 const unsigned int kMaxMessagesToRecord = 10;
110 const unsigned int kMaxMessageSizeToRecord = 5 * 1024; 108 const unsigned int kMaxMessageSizeToRecord = 5 * 1024;
111 109
112 ////////////////////////////////////////////////////////////////////////// 110 //////////////////////////////////////////////////////////////////////////
(...skipping 15 matching lines...) Expand all
128 testing_mode_(NON_TEST), 126 testing_mode_(NON_TEST),
129 observing_ip_address_changes_(false), 127 observing_ip_address_changes_(false),
130 throttled_data_type_tracker_(&allstatus_), 128 throttled_data_type_tracker_(&allstatus_),
131 traffic_recorder_(kMaxMessagesToRecord, kMaxMessageSizeToRecord), 129 traffic_recorder_(kMaxMessagesToRecord, kMaxMessageSizeToRecord),
132 encryptor_(NULL), 130 encryptor_(NULL),
133 unrecoverable_error_handler_(NULL), 131 unrecoverable_error_handler_(NULL),
134 report_unrecoverable_error_function_(NULL), 132 report_unrecoverable_error_function_(NULL),
135 created_on_loop_(MessageLoop::current()), 133 created_on_loop_(MessageLoop::current()),
136 nigori_overwrite_count_(0) { 134 nigori_overwrite_count_(0) {
137 // Pre-fill |notification_info_map_|. 135 // Pre-fill |notification_info_map_|.
138 for (int i = syncable::FIRST_REAL_MODEL_TYPE; 136 for (int i = syncer::FIRST_REAL_MODEL_TYPE;
139 i < syncable::MODEL_TYPE_COUNT; ++i) { 137 i < syncer::MODEL_TYPE_COUNT; ++i) {
140 notification_info_map_.insert( 138 notification_info_map_.insert(
141 std::make_pair(syncable::ModelTypeFromInt(i), NotificationInfo())); 139 std::make_pair(syncer::ModelTypeFromInt(i), NotificationInfo()));
142 } 140 }
143 141
144 // Bind message handlers. 142 // Bind message handlers.
145 BindJsMessageHandler( 143 BindJsMessageHandler(
146 "getNotificationState", 144 "getNotificationState",
147 &SyncManager::SyncInternal::GetNotificationState); 145 &SyncManager::SyncInternal::GetNotificationState);
148 BindJsMessageHandler( 146 BindJsMessageHandler(
149 "getNotificationInfo", 147 "getNotificationInfo",
150 &SyncManager::SyncInternal::GetNotificationInfo); 148 &SyncManager::SyncInternal::GetNotificationInfo);
151 BindJsMessageHandler( 149 BindJsMessageHandler(
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 syncable::BaseTransaction* trans) OVERRIDE; 288 syncable::BaseTransaction* trans) OVERRIDE;
291 virtual void HandleCalculateChangesChangeEventFromSyncer( 289 virtual void HandleCalculateChangesChangeEventFromSyncer(
292 const ImmutableWriteTransactionInfo& write_transaction_info, 290 const ImmutableWriteTransactionInfo& write_transaction_info,
293 syncable::BaseTransaction* trans) OVERRIDE; 291 syncable::BaseTransaction* trans) OVERRIDE;
294 292
295 // Open the directory named with username_for_share 293 // Open the directory named with username_for_share
296 bool OpenDirectory(); 294 bool OpenDirectory();
297 295
298 // Cryptographer::Observer implementation. 296 // Cryptographer::Observer implementation.
299 virtual void OnEncryptedTypesChanged( 297 virtual void OnEncryptedTypesChanged(
300 syncable::ModelTypeSet encrypted_types, 298 syncer::ModelTypeSet encrypted_types,
301 bool encrypt_everything) OVERRIDE; 299 bool encrypt_everything) OVERRIDE;
302 300
303 // SyncNotifierObserver implementation. 301 // SyncNotifierObserver implementation.
304 virtual void OnNotificationsEnabled() OVERRIDE; 302 virtual void OnNotificationsEnabled() OVERRIDE;
305 virtual void OnNotificationsDisabled( 303 virtual void OnNotificationsDisabled(
306 syncer::NotificationsDisabledReason reason) OVERRIDE; 304 syncer::NotificationsDisabledReason reason) OVERRIDE;
307 virtual void OnIncomingNotification( 305 virtual void OnIncomingNotification(
308 const syncable::ModelTypePayloadMap& type_payloads, 306 const syncer::ModelTypePayloadMap& type_payloads,
309 syncer::IncomingNotificationSource source) OVERRIDE; 307 syncer::IncomingNotificationSource source) OVERRIDE;
310 308
311 void AddObserver(SyncManager::Observer* observer); 309 void AddObserver(SyncManager::Observer* observer);
312 void RemoveObserver(SyncManager::Observer* observer); 310 void RemoveObserver(SyncManager::Observer* observer);
313 311
314 // Accessors for the private members. 312 // Accessors for the private members.
315 syncable::Directory* directory() { return share_.directory.get(); } 313 syncable::Directory* directory() { return share_.directory.get(); }
316 SyncAPIServerConnectionManager* connection_manager() { 314 SyncAPIServerConnectionManager* connection_manager() {
317 return connection_manager_.get(); 315 return connection_manager_.get();
318 } 316 }
(...skipping 23 matching lines...) Expand all
342 void NotifyCryptographerState(Cryptographer* cryptographer); 340 void NotifyCryptographerState(Cryptographer* cryptographer);
343 341
344 // See SyncManager::Shutdown* for information. 342 // See SyncManager::Shutdown* for information.
345 void StopSyncingForShutdown(const base::Closure& callback); 343 void StopSyncingForShutdown(const base::Closure& callback);
346 void ShutdownOnSyncThread(); 344 void ShutdownOnSyncThread();
347 345
348 // If this is a deletion for a password, sets the legacy 346 // If this is a deletion for a password, sets the legacy
349 // ExtraPasswordChangeRecordData field of |buffer|. Otherwise sets 347 // ExtraPasswordChangeRecordData field of |buffer|. Otherwise sets
350 // |buffer|'s specifics field to contain the unencrypted data. 348 // |buffer|'s specifics field to contain the unencrypted data.
351 void SetExtraChangeRecordData(int64 id, 349 void SetExtraChangeRecordData(int64 id,
352 syncable::ModelType type, 350 syncer::ModelType type,
353 ChangeReorderBuffer* buffer, 351 ChangeReorderBuffer* buffer,
354 Cryptographer* cryptographer, 352 Cryptographer* cryptographer,
355 const syncable::EntryKernel& original, 353 const syncable::EntryKernel& original,
356 bool existed_before, 354 bool existed_before,
357 bool exists_now); 355 bool exists_now);
358 356
359 // Called only by our NetworkChangeNotifier. 357 // Called only by our NetworkChangeNotifier.
360 virtual void OnIPAddressChanged() OVERRIDE; 358 virtual void OnIPAddressChanged() OVERRIDE;
361 359
362 syncable::ModelTypeSet InitialSyncEndedTypes() { 360 syncer::ModelTypeSet InitialSyncEndedTypes() {
363 DCHECK(initialized_); 361 DCHECK(initialized_);
364 return directory()->initial_sync_ended_types(); 362 return directory()->initial_sync_ended_types();
365 } 363 }
366 364
367 // SyncEngineEventListener implementation. 365 // SyncEngineEventListener implementation.
368 virtual void OnSyncEngineEvent(const SyncEngineEvent& event) OVERRIDE; 366 virtual void OnSyncEngineEvent(const SyncEngineEvent& event) OVERRIDE;
369 367
370 // ServerConnectionEventListener implementation. 368 // ServerConnectionEventListener implementation.
371 virtual void OnServerConnectionEvent( 369 virtual void OnServerConnectionEvent(
372 const ServerConnectionEvent& event) OVERRIDE; 370 const ServerConnectionEvent& event) OVERRIDE;
(...skipping 16 matching lines...) Expand all
389 387
390 // Returned pointer owned by the caller. 388 // Returned pointer owned by the caller.
391 DictionaryValue* ToValue() const { 389 DictionaryValue* ToValue() const {
392 DictionaryValue* value = new DictionaryValue(); 390 DictionaryValue* value = new DictionaryValue();
393 value->SetInteger("totalCount", total_count); 391 value->SetInteger("totalCount", total_count);
394 value->SetString("payload", payload); 392 value->SetString("payload", payload);
395 return value; 393 return value;
396 } 394 }
397 }; 395 };
398 396
399 typedef std::map<syncable::ModelType, NotificationInfo> NotificationInfoMap; 397 typedef std::map<syncer::ModelType, NotificationInfo> NotificationInfoMap;
400 typedef JsArgList 398 typedef JsArgList
401 (SyncManager::SyncInternal::*UnboundJsMessageHandler)(const JsArgList&); 399 (SyncManager::SyncInternal::*UnboundJsMessageHandler)(const JsArgList&);
402 typedef base::Callback<JsArgList(const JsArgList&)> JsMessageHandler; 400 typedef base::Callback<JsArgList(const JsArgList&)> JsMessageHandler;
403 typedef std::map<std::string, JsMessageHandler> JsMessageHandlerMap; 401 typedef std::map<std::string, JsMessageHandler> JsMessageHandlerMap;
404 402
405 // Internal callback of UpdateCryptographerAndNigoriCallback. 403 // Internal callback of UpdateCryptographerAndNigoriCallback.
406 void UpdateCryptographerAndNigoriCallback( 404 void UpdateCryptographerAndNigoriCallback(
407 const std::string& chrome_version, 405 const std::string& chrome_version,
408 const base::Closure& done_callback, 406 const base::Closure& done_callback,
409 const std::string& session_name); 407 const std::string& session_name);
410 408
411 // Determine if the parents or predecessors differ between the old and new 409 // Determine if the parents or predecessors differ between the old and new
412 // versions of an entry stored in |a| and |b|. Note that a node's index may 410 // versions of an entry stored in |a| and |b|. Note that a node's index may
413 // change without its NEXT_ID changing if the node at NEXT_ID also moved (but 411 // change without its NEXT_ID changing if the node at NEXT_ID also moved (but
414 // the relative order is unchanged). To handle such cases, we rely on the 412 // the relative order is unchanged). To handle such cases, we rely on the
415 // caller to treat a position update on any sibling as updating the positions 413 // caller to treat a position update on any sibling as updating the positions
416 // of all siblings. 414 // of all siblings.
417 static bool VisiblePositionsDiffer( 415 static bool VisiblePositionsDiffer(
418 const syncable::EntryKernelMutation& mutation) { 416 const syncable::EntryKernelMutation& mutation) {
419 const syncable::EntryKernel& a = mutation.original; 417 const syncable::EntryKernel& a = mutation.original;
420 const syncable::EntryKernel& b = mutation.mutated; 418 const syncable::EntryKernel& b = mutation.mutated;
421 // If the datatype isn't one where the browser model cares about position, 419 // If the datatype isn't one where the browser model cares about position,
422 // don't bother notifying that data model of position-only changes. 420 // don't bother notifying that data model of position-only changes.
423 if (!ShouldMaintainPosition( 421 if (!ShouldMaintainPosition(
424 syncable::GetModelTypeFromSpecifics(b.ref(SPECIFICS)))) 422 syncer::GetModelTypeFromSpecifics(b.ref(SPECIFICS))))
425 return false; 423 return false;
426 if (a.ref(syncable::NEXT_ID) != b.ref(syncable::NEXT_ID)) 424 if (a.ref(syncable::NEXT_ID) != b.ref(syncable::NEXT_ID))
427 return true; 425 return true;
428 if (a.ref(syncable::PARENT_ID) != b.ref(syncable::PARENT_ID)) 426 if (a.ref(syncable::PARENT_ID) != b.ref(syncable::PARENT_ID))
429 return true; 427 return true;
430 return false; 428 return false;
431 } 429 }
432 430
433 // Determine if any of the fields made visible to clients of the Sync API 431 // Determine if any of the fields made visible to clients of the Sync API
434 // differ between the versions of an entry stored in |a| and |b|. A return 432 // differ between the versions of an entry stored in |a| and |b|. A return
435 // value of false means that it should be OK to ignore this change. 433 // value of false means that it should be OK to ignore this change.
436 static bool VisiblePropertiesDiffer( 434 static bool VisiblePropertiesDiffer(
437 const syncable::EntryKernelMutation& mutation, 435 const syncable::EntryKernelMutation& mutation,
438 Cryptographer* cryptographer) { 436 Cryptographer* cryptographer) {
439 const syncable::EntryKernel& a = mutation.original; 437 const syncable::EntryKernel& a = mutation.original;
440 const syncable::EntryKernel& b = mutation.mutated; 438 const syncable::EntryKernel& b = mutation.mutated;
441 const sync_pb::EntitySpecifics& a_specifics = a.ref(SPECIFICS); 439 const sync_pb::EntitySpecifics& a_specifics = a.ref(SPECIFICS);
442 const sync_pb::EntitySpecifics& b_specifics = b.ref(SPECIFICS); 440 const sync_pb::EntitySpecifics& b_specifics = b.ref(SPECIFICS);
443 DCHECK_EQ(syncable::GetModelTypeFromSpecifics(a_specifics), 441 DCHECK_EQ(syncer::GetModelTypeFromSpecifics(a_specifics),
444 syncable::GetModelTypeFromSpecifics(b_specifics)); 442 syncer::GetModelTypeFromSpecifics(b_specifics));
445 syncable::ModelType model_type = 443 syncer::ModelType model_type =
446 syncable::GetModelTypeFromSpecifics(b_specifics); 444 syncer::GetModelTypeFromSpecifics(b_specifics);
447 // Suppress updates to items that aren't tracked by any browser model. 445 // Suppress updates to items that aren't tracked by any browser model.
448 if (model_type < syncable::FIRST_REAL_MODEL_TYPE || 446 if (model_type < syncer::FIRST_REAL_MODEL_TYPE ||
449 !a.ref(syncable::UNIQUE_SERVER_TAG).empty()) { 447 !a.ref(syncable::UNIQUE_SERVER_TAG).empty()) {
450 return false; 448 return false;
451 } 449 }
452 if (a.ref(syncable::IS_DIR) != b.ref(syncable::IS_DIR)) 450 if (a.ref(syncable::IS_DIR) != b.ref(syncable::IS_DIR))
453 return true; 451 return true;
454 if (!AreSpecificsEqual(cryptographer, 452 if (!AreSpecificsEqual(cryptographer,
455 a.ref(syncable::SPECIFICS), 453 a.ref(syncable::SPECIFICS),
456 b.ref(syncable::SPECIFICS))) { 454 b.ref(syncable::SPECIFICS))) {
457 return true; 455 return true;
458 } 456 }
459 // We only care if the name has changed if neither specifics is encrypted 457 // We only care if the name has changed if neither specifics is encrypted
460 // (encrypted nodes blow away the NON_UNIQUE_NAME). 458 // (encrypted nodes blow away the NON_UNIQUE_NAME).
461 if (!a_specifics.has_encrypted() && !b_specifics.has_encrypted() && 459 if (!a_specifics.has_encrypted() && !b_specifics.has_encrypted() &&
462 a.ref(syncable::NON_UNIQUE_NAME) != b.ref(syncable::NON_UNIQUE_NAME)) 460 a.ref(syncable::NON_UNIQUE_NAME) != b.ref(syncable::NON_UNIQUE_NAME))
463 return true; 461 return true;
464 if (VisiblePositionsDiffer(mutation)) 462 if (VisiblePositionsDiffer(mutation))
465 return true; 463 return true;
466 return false; 464 return false;
467 } 465 }
468 466
469 bool ChangeBuffersAreEmpty() { 467 bool ChangeBuffersAreEmpty() {
470 for (int i = 0; i < syncable::MODEL_TYPE_COUNT; ++i) { 468 for (int i = 0; i < syncer::MODEL_TYPE_COUNT; ++i) {
471 if (!change_buffers_[i].IsEmpty()) 469 if (!change_buffers_[i].IsEmpty())
472 return false; 470 return false;
473 } 471 }
474 return true; 472 return true;
475 } 473 }
476 474
477 void ReEncryptEverything(WriteTransaction* trans); 475 void ReEncryptEverything(WriteTransaction* trans);
478 476
479 // Called for every notification. This updates the notification statistics 477 // Called for every notification. This updates the notification statistics
480 // to be displayed in about:sync. 478 // to be displayed in about:sync.
481 void UpdateNotificationInfo( 479 void UpdateNotificationInfo(
482 const syncable::ModelTypePayloadMap& type_payloads); 480 const syncer::ModelTypePayloadMap& type_payloads);
483 481
484 // Checks for server reachabilty and requests a nudge. 482 // Checks for server reachabilty and requests a nudge.
485 void OnIPAddressChangedImpl(); 483 void OnIPAddressChangedImpl();
486 484
487 // Helper function used only by the constructor. 485 // Helper function used only by the constructor.
488 void BindJsMessageHandler( 486 void BindJsMessageHandler(
489 const std::string& name, UnboundJsMessageHandler unbound_message_handler); 487 const std::string& name, UnboundJsMessageHandler unbound_message_handler);
490 488
491 // Returned pointer is owned by the caller. 489 // Returned pointer is owned by the caller.
492 static DictionaryValue* NotificationInfoToValue( 490 static DictionaryValue* NotificationInfoToValue(
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 // A multi-purpose status watch object that aggregates stats from various 551 // A multi-purpose status watch object that aggregates stats from various
554 // sync components. 552 // sync components.
555 AllStatus allstatus_; 553 AllStatus allstatus_;
556 554
557 // Each element of this array is a store of change records produced by 555 // Each element of this array is a store of change records produced by
558 // HandleChangeEvent during the CALCULATE_CHANGES step. The changes are 556 // HandleChangeEvent during the CALCULATE_CHANGES step. The changes are
559 // segregated by model type, and are stored here to be processed and 557 // segregated by model type, and are stored here to be processed and
560 // forwarded to the observer slightly later, at the TRANSACTION_ENDING 558 // forwarded to the observer slightly later, at the TRANSACTION_ENDING
561 // step by HandleTransactionEndingChangeEvent. The list is cleared in the 559 // step by HandleTransactionEndingChangeEvent. The list is cleared in the
562 // TRANSACTION_COMPLETE step by HandleTransactionCompleteChangeEvent. 560 // TRANSACTION_COMPLETE step by HandleTransactionCompleteChangeEvent.
563 ChangeReorderBuffer change_buffers_[syncable::MODEL_TYPE_COUNT]; 561 ChangeReorderBuffer change_buffers_[syncer::MODEL_TYPE_COUNT];
564 562
565 SyncManager::ChangeDelegate* change_delegate_; 563 SyncManager::ChangeDelegate* change_delegate_;
566 564
567 // Set to true once Init has been called. 565 // Set to true once Init has been called.
568 bool initialized_; 566 bool initialized_;
569 567
570 // Controls the disabling of certain SyncManager features. 568 // Controls the disabling of certain SyncManager features.
571 // Can be used to disable communication with the server and the use of an 569 // Can be used to disable communication with the server and the use of an
572 // on-disk file for maintaining syncer state. 570 // on-disk file for maintaining syncer state.
573 // TODO(117836): Clean up implementation of SyncManager unit tests. 571 // TODO(117836): Clean up implementation of SyncManager unit tests.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 // Sync this change while syncing another change. 624 // Sync this change while syncing another change.
627 ACCOMPANY_ONLY, 625 ACCOMPANY_ONLY,
628 626
629 // The datatype does not use one of the predefined wait times but defines 627 // The datatype does not use one of the predefined wait times but defines
630 // its own wait time logic for nudge. 628 // its own wait time logic for nudge.
631 CUSTOM, 629 CUSTOM,
632 }; 630 };
633 631
634 static NudgeDelayStrategy GetNudgeDelayStrategy(const ModelType& type) { 632 static NudgeDelayStrategy GetNudgeDelayStrategy(const ModelType& type) {
635 switch (type) { 633 switch (type) {
636 case syncable::AUTOFILL: 634 case syncer::AUTOFILL:
637 return ACCOMPANY_ONLY; 635 return ACCOMPANY_ONLY;
638 case syncable::PREFERENCES: 636 case syncer::PREFERENCES:
639 case syncable::SESSIONS: 637 case syncer::SESSIONS:
640 return CUSTOM; 638 return CUSTOM;
641 default: 639 default:
642 return IMMEDIATE; 640 return IMMEDIATE;
643 } 641 }
644 } 642 }
645 643
646 static TimeDelta GetNudgeDelayTimeDeltaFromType( 644 static TimeDelta GetNudgeDelayTimeDeltaFromType(
647 const NudgeDelayStrategy& delay_type, const ModelType& model_type, 645 const NudgeDelayStrategy& delay_type, const ModelType& model_type,
648 const SyncManager::SyncInternal* core) { 646 const SyncManager::SyncInternal* core) {
649 CHECK(core); 647 CHECK(core);
650 TimeDelta delay = TimeDelta::FromMilliseconds( 648 TimeDelta delay = TimeDelta::FromMilliseconds(
651 SyncManager::kDefaultNudgeDelayMilliseconds); 649 SyncManager::kDefaultNudgeDelayMilliseconds);
652 switch (delay_type) { 650 switch (delay_type) {
653 case IMMEDIATE: 651 case IMMEDIATE:
654 delay = TimeDelta::FromMilliseconds( 652 delay = TimeDelta::FromMilliseconds(
655 SyncManager::kDefaultNudgeDelayMilliseconds); 653 SyncManager::kDefaultNudgeDelayMilliseconds);
656 break; 654 break;
657 case ACCOMPANY_ONLY: 655 case ACCOMPANY_ONLY:
658 delay = TimeDelta::FromSeconds( 656 delay = TimeDelta::FromSeconds(
659 syncer::kDefaultShortPollIntervalSeconds); 657 syncer::kDefaultShortPollIntervalSeconds);
660 break; 658 break;
661 case CUSTOM: 659 case CUSTOM:
662 switch (model_type) { 660 switch (model_type) {
663 case syncable::PREFERENCES: 661 case syncer::PREFERENCES:
664 delay = TimeDelta::FromMilliseconds( 662 delay = TimeDelta::FromMilliseconds(
665 SyncManager::kPreferencesNudgeDelayMilliseconds); 663 SyncManager::kPreferencesNudgeDelayMilliseconds);
666 break; 664 break;
667 case syncable::SESSIONS: 665 case syncer::SESSIONS:
668 delay = core->scheduler()->sessions_commit_delay(); 666 delay = core->scheduler()->sessions_commit_delay();
669 break; 667 break;
670 default: 668 default:
671 NOTREACHED(); 669 NOTREACHED();
672 } 670 }
673 break; 671 break;
674 default: 672 default:
675 NOTREACHED(); 673 NOTREACHED();
676 } 674 }
677 return delay; 675 return delay;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 data_->UpdateEnabledTypes(enabled_types); 738 data_->UpdateEnabledTypes(enabled_types);
741 } 739 }
742 740
743 void SyncManager::ThrowUnrecoverableError() { 741 void SyncManager::ThrowUnrecoverableError() {
744 DCHECK(thread_checker_.CalledOnValidThread()); 742 DCHECK(thread_checker_.CalledOnValidThread());
745 ReadTransaction trans(FROM_HERE, GetUserShare()); 743 ReadTransaction trans(FROM_HERE, GetUserShare());
746 trans.GetWrappedTrans()->OnUnrecoverableError( 744 trans.GetWrappedTrans()->OnUnrecoverableError(
747 FROM_HERE, "Simulating unrecoverable error for testing purposes."); 745 FROM_HERE, "Simulating unrecoverable error for testing purposes.");
748 } 746 }
749 747
750 syncable::ModelTypeSet SyncManager::InitialSyncEndedTypes() { 748 syncer::ModelTypeSet SyncManager::InitialSyncEndedTypes() {
751 return data_->InitialSyncEndedTypes(); 749 return data_->InitialSyncEndedTypes();
752 } 750 }
753 751
754 void SyncManager::StartSyncingNormally( 752 void SyncManager::StartSyncingNormally(
755 const syncer::ModelSafeRoutingInfo& routing_info) { 753 const syncer::ModelSafeRoutingInfo& routing_info) {
756 DCHECK(thread_checker_.CalledOnValidThread()); 754 DCHECK(thread_checker_.CalledOnValidThread());
757 data_->StartSyncingNormally(routing_info); 755 data_->StartSyncingNormally(routing_info);
758 } 756 }
759 757
760 void SyncManager::SetEncryptionPassphrase(const std::string& passphrase, 758 void SyncManager::SetEncryptionPassphrase(const std::string& passphrase,
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 cryptographer->UpdateNigoriFromEncryptedTypes(&nigori); 1004 cryptographer->UpdateNigoriFromEncryptedTypes(&nigori);
1007 1005
1008 // If nothing has changed, this is a no-op. 1006 // If nothing has changed, this is a no-op.
1009 nigori_node->SetNigoriSpecifics(nigori); 1007 nigori_node->SetNigoriSpecifics(nigori);
1010 } 1008 }
1011 1009
1012 void SyncManager::SyncInternal::UpdateCryptographerAndNigoriCallback( 1010 void SyncManager::SyncInternal::UpdateCryptographerAndNigoriCallback(
1013 const std::string& chrome_version, 1011 const std::string& chrome_version,
1014 const base::Closure& done_callback, 1012 const base::Closure& done_callback,
1015 const std::string& session_name) { 1013 const std::string& session_name) {
1016 if (!directory()->initial_sync_ended_for_type(syncable::NIGORI)) { 1014 if (!directory()->initial_sync_ended_for_type(syncer::NIGORI)) {
1017 done_callback.Run(); // Should only happen during first time sync. 1015 done_callback.Run(); // Should only happen during first time sync.
1018 return; 1016 return;
1019 } 1017 }
1020 1018
1021 bool success = false; 1019 bool success = false;
1022 { 1020 {
1023 WriteTransaction trans(FROM_HERE, GetUserShare()); 1021 WriteTransaction trans(FROM_HERE, GetUserShare());
1024 Cryptographer* cryptographer = trans.GetCryptographer(); 1022 Cryptographer* cryptographer = trans.GetCryptographer();
1025 WriteNode node(&trans); 1023 WriteNode node(&trans);
1026 1024
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
1546 } 1544 }
1547 1545
1548 // This function iterates over all encrypted types. There are many scenarios in 1546 // This function iterates over all encrypted types. There are many scenarios in
1549 // which data for some or all types is not currently available. In that case, 1547 // which data for some or all types is not currently available. In that case,
1550 // the lookup of the root node will fail and we will skip encryption for that 1548 // the lookup of the root node will fail and we will skip encryption for that
1551 // type. 1549 // type.
1552 void SyncManager::SyncInternal::ReEncryptEverything(WriteTransaction* trans) { 1550 void SyncManager::SyncInternal::ReEncryptEverything(WriteTransaction* trans) {
1553 Cryptographer* cryptographer = trans->GetCryptographer(); 1551 Cryptographer* cryptographer = trans->GetCryptographer();
1554 if (!cryptographer || !cryptographer->is_ready()) 1552 if (!cryptographer || !cryptographer->is_ready())
1555 return; 1553 return;
1556 syncable::ModelTypeSet encrypted_types = GetEncryptedTypes(trans); 1554 syncer::ModelTypeSet encrypted_types = GetEncryptedTypes(trans);
1557 for (syncable::ModelTypeSet::Iterator iter = encrypted_types.First(); 1555 for (syncer::ModelTypeSet::Iterator iter = encrypted_types.First();
1558 iter.Good(); iter.Inc()) { 1556 iter.Good(); iter.Inc()) {
1559 if (iter.Get() == syncable::PASSWORDS || 1557 if (iter.Get() == syncer::PASSWORDS || iter.Get() == syncer::NIGORI)
1560 iter.Get() == syncable::NIGORI)
1561 continue; // These types handle encryption differently. 1558 continue; // These types handle encryption differently.
1562 1559
1563 ReadNode type_root(trans); 1560 ReadNode type_root(trans);
1564 std::string tag = syncable::ModelTypeToRootTag(iter.Get()); 1561 std::string tag = syncer::ModelTypeToRootTag(iter.Get());
1565 if (type_root.InitByTagLookup(tag) != syncer::BaseNode::INIT_OK) 1562 if (type_root.InitByTagLookup(tag) != syncer::BaseNode::INIT_OK)
1566 continue; // Don't try to reencrypt if the type's data is unavailable. 1563 continue; // Don't try to reencrypt if the type's data is unavailable.
1567 1564
1568 // Iterate through all children of this datatype. 1565 // Iterate through all children of this datatype.
1569 std::queue<int64> to_visit; 1566 std::queue<int64> to_visit;
1570 int64 child_id = type_root.GetFirstChildId(); 1567 int64 child_id = type_root.GetFirstChildId();
1571 to_visit.push(child_id); 1568 to_visit.push(child_id);
1572 while (!to_visit.empty()) { 1569 while (!to_visit.empty()) {
1573 child_id = to_visit.front(); 1570 child_id = to_visit.front();
1574 to_visit.pop(); 1571 to_visit.pop();
(...skipping 13 matching lines...) Expand all
1588 // (only rewrite the non-unique folders). 1585 // (only rewrite the non-unique folders).
1589 child.ResetFromSpecifics(); 1586 child.ResetFromSpecifics();
1590 } 1587 }
1591 to_visit.push(child.GetSuccessorId()); 1588 to_visit.push(child.GetSuccessorId());
1592 } 1589 }
1593 } 1590 }
1594 1591
1595 // Passwords are encrypted with their own legacy scheme. Passwords are always 1592 // Passwords are encrypted with their own legacy scheme. Passwords are always
1596 // encrypted so we don't need to check GetEncryptedTypes() here. 1593 // encrypted so we don't need to check GetEncryptedTypes() here.
1597 ReadNode passwords_root(trans); 1594 ReadNode passwords_root(trans);
1598 std::string passwords_tag = 1595 std::string passwords_tag = syncer::ModelTypeToRootTag(syncer::PASSWORDS);
1599 syncable::ModelTypeToRootTag(syncable::PASSWORDS);
1600 if (passwords_root.InitByTagLookup(passwords_tag) == 1596 if (passwords_root.InitByTagLookup(passwords_tag) ==
1601 syncer::BaseNode::INIT_OK) { 1597 syncer::BaseNode::INIT_OK) {
1602 int64 child_id = passwords_root.GetFirstChildId(); 1598 int64 child_id = passwords_root.GetFirstChildId();
1603 while (child_id != kInvalidId) { 1599 while (child_id != kInvalidId) {
1604 WriteNode child(trans); 1600 WriteNode child(trans);
1605 if (child.InitByIdLookup(child_id) != syncer::BaseNode::INIT_OK) { 1601 if (child.InitByIdLookup(child_id) != syncer::BaseNode::INIT_OK) {
1606 NOTREACHED(); 1602 NOTREACHED();
1607 return; 1603 return;
1608 } 1604 }
1609 child.SetPasswordSpecifics(child.GetPasswordSpecifics()); 1605 child.SetPasswordSpecifics(child.GetPasswordSpecifics());
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
1767 if (!change_delegate_ || ChangeBuffersAreEmpty()) 1763 if (!change_delegate_ || ChangeBuffersAreEmpty())
1768 return ModelTypeSet(); 1764 return ModelTypeSet();
1769 1765
1770 // This will continue the WriteTransaction using a read only wrapper. 1766 // This will continue the WriteTransaction using a read only wrapper.
1771 // This is the last chance for read to occur in the WriteTransaction 1767 // This is the last chance for read to occur in the WriteTransaction
1772 // that's closing. This special ReadTransaction will not close the 1768 // that's closing. This special ReadTransaction will not close the
1773 // underlying transaction. 1769 // underlying transaction.
1774 ReadTransaction read_trans(GetUserShare(), trans); 1770 ReadTransaction read_trans(GetUserShare(), trans);
1775 1771
1776 ModelTypeSet models_with_changes; 1772 ModelTypeSet models_with_changes;
1777 for (int i = syncable::FIRST_REAL_MODEL_TYPE; 1773 for (int i = syncer::FIRST_REAL_MODEL_TYPE;
1778 i < syncable::MODEL_TYPE_COUNT; ++i) { 1774 i < syncer::MODEL_TYPE_COUNT; ++i) {
1779 const syncable::ModelType type = syncable::ModelTypeFromInt(i); 1775 const syncer::ModelType type = syncer::ModelTypeFromInt(i);
1780 if (change_buffers_[type].IsEmpty()) 1776 if (change_buffers_[type].IsEmpty())
1781 continue; 1777 continue;
1782 1778
1783 ImmutableChangeRecordList ordered_changes; 1779 ImmutableChangeRecordList ordered_changes;
1784 // TODO(akalin): Propagate up the error further (see 1780 // TODO(akalin): Propagate up the error further (see
1785 // http://crbug.com/100907). 1781 // http://crbug.com/100907).
1786 CHECK(change_buffers_[type].GetAllChangesInTreeOrder(&read_trans, 1782 CHECK(change_buffers_[type].GetAllChangesInTreeOrder(&read_trans,
1787 &ordered_changes)); 1783 &ordered_changes));
1788 if (!ordered_changes.Get().empty()) { 1784 if (!ordered_changes.Get().empty()) {
1789 change_delegate_-> 1785 change_delegate_->
(...skipping 13 matching lines...) Expand all
1803 syncable::BaseTransaction* trans) { 1799 syncable::BaseTransaction* trans) {
1804 if (!scheduler()) { 1800 if (!scheduler()) {
1805 return; 1801 return;
1806 } 1802 }
1807 1803
1808 // We have been notified about a user action changing a sync model. 1804 // We have been notified about a user action changing a sync model.
1809 LOG_IF(WARNING, !ChangeBuffersAreEmpty()) << 1805 LOG_IF(WARNING, !ChangeBuffersAreEmpty()) <<
1810 "CALCULATE_CHANGES called with unapplied old changes."; 1806 "CALCULATE_CHANGES called with unapplied old changes.";
1811 1807
1812 // The mutated model type, or UNSPECIFIED if nothing was mutated. 1808 // The mutated model type, or UNSPECIFIED if nothing was mutated.
1813 syncable::ModelTypeSet mutated_model_types; 1809 syncer::ModelTypeSet mutated_model_types;
1814 1810
1815 const syncable::ImmutableEntryKernelMutationMap& mutations = 1811 const syncable::ImmutableEntryKernelMutationMap& mutations =
1816 write_transaction_info.Get().mutations; 1812 write_transaction_info.Get().mutations;
1817 for (syncable::EntryKernelMutationMap::const_iterator it = 1813 for (syncable::EntryKernelMutationMap::const_iterator it =
1818 mutations.Get().begin(); it != mutations.Get().end(); ++it) { 1814 mutations.Get().begin(); it != mutations.Get().end(); ++it) {
1819 if (!it->second.mutated.ref(syncable::IS_UNSYNCED)) { 1815 if (!it->second.mutated.ref(syncable::IS_UNSYNCED)) {
1820 continue; 1816 continue;
1821 } 1817 }
1822 1818
1823 syncable::ModelType model_type = 1819 syncer::ModelType model_type =
1824 syncable::GetModelTypeFromSpecifics( 1820 syncer::GetModelTypeFromSpecifics(
1825 it->second.mutated.ref(SPECIFICS)); 1821 it->second.mutated.ref(SPECIFICS));
1826 if (model_type < syncable::FIRST_REAL_MODEL_TYPE) { 1822 if (model_type < syncer::FIRST_REAL_MODEL_TYPE) {
1827 NOTREACHED() << "Permanent or underspecified item changed via syncapi."; 1823 NOTREACHED() << "Permanent or underspecified item changed via syncapi.";
1828 continue; 1824 continue;
1829 } 1825 }
1830 1826
1831 // Found real mutation. 1827 // Found real mutation.
1832 if (model_type != syncable::UNSPECIFIED) { 1828 if (model_type != syncer::UNSPECIFIED) {
1833 mutated_model_types.Put(model_type); 1829 mutated_model_types.Put(model_type);
1834 } 1830 }
1835 } 1831 }
1836 1832
1837 // Nudge if necessary. 1833 // Nudge if necessary.
1838 if (!mutated_model_types.Empty()) { 1834 if (!mutated_model_types.Empty()) {
1839 if (weak_handle_this_.IsInitialized()) { 1835 if (weak_handle_this_.IsInitialized()) {
1840 weak_handle_this_.Call(FROM_HERE, 1836 weak_handle_this_.Call(FROM_HERE,
1841 &SyncInternal::RequestNudgeForDataTypes, 1837 &SyncInternal::RequestNudgeForDataTypes,
1842 FROM_HERE, 1838 FROM_HERE,
1843 mutated_model_types); 1839 mutated_model_types);
1844 } else { 1840 } else {
1845 NOTREACHED(); 1841 NOTREACHED();
1846 } 1842 }
1847 } 1843 }
1848 } 1844 }
1849 1845
1850 void SyncManager::SyncInternal::SetExtraChangeRecordData(int64 id, 1846 void SyncManager::SyncInternal::SetExtraChangeRecordData(int64 id,
1851 syncable::ModelType type, ChangeReorderBuffer* buffer, 1847 syncer::ModelType type, ChangeReorderBuffer* buffer,
1852 Cryptographer* cryptographer, const syncable::EntryKernel& original, 1848 Cryptographer* cryptographer, const syncable::EntryKernel& original,
1853 bool existed_before, bool exists_now) { 1849 bool existed_before, bool exists_now) {
1854 // If this is a deletion and the datatype was encrypted, we need to decrypt it 1850 // If this is a deletion and the datatype was encrypted, we need to decrypt it
1855 // and attach it to the buffer. 1851 // and attach it to the buffer.
1856 if (!exists_now && existed_before) { 1852 if (!exists_now && existed_before) {
1857 sync_pb::EntitySpecifics original_specifics(original.ref(SPECIFICS)); 1853 sync_pb::EntitySpecifics original_specifics(original.ref(SPECIFICS));
1858 if (type == syncable::PASSWORDS) { 1854 if (type == syncer::PASSWORDS) {
1859 // Passwords must use their own legacy ExtraPasswordChangeRecordData. 1855 // Passwords must use their own legacy ExtraPasswordChangeRecordData.
1860 scoped_ptr<sync_pb::PasswordSpecificsData> data( 1856 scoped_ptr<sync_pb::PasswordSpecificsData> data(
1861 DecryptPasswordSpecifics(original_specifics, cryptographer)); 1857 DecryptPasswordSpecifics(original_specifics, cryptographer));
1862 if (!data.get()) { 1858 if (!data.get()) {
1863 NOTREACHED(); 1859 NOTREACHED();
1864 return; 1860 return;
1865 } 1861 }
1866 buffer->SetExtraDataForId(id, new ExtraPasswordChangeRecordData(*data)); 1862 buffer->SetExtraDataForId(id, new ExtraPasswordChangeRecordData(*data));
1867 } else if (original_specifics.has_encrypted()) { 1863 } else if (original_specifics.has_encrypted()) {
1868 // All other datatypes can just create a new unencrypted specifics and 1864 // All other datatypes can just create a new unencrypted specifics and
(...skipping 18 matching lines...) Expand all
1887 1883
1888 Cryptographer* crypto = directory()->GetCryptographer(trans); 1884 Cryptographer* crypto = directory()->GetCryptographer(trans);
1889 const syncable::ImmutableEntryKernelMutationMap& mutations = 1885 const syncable::ImmutableEntryKernelMutationMap& mutations =
1890 write_transaction_info.Get().mutations; 1886 write_transaction_info.Get().mutations;
1891 for (syncable::EntryKernelMutationMap::const_iterator it = 1887 for (syncable::EntryKernelMutationMap::const_iterator it =
1892 mutations.Get().begin(); it != mutations.Get().end(); ++it) { 1888 mutations.Get().begin(); it != mutations.Get().end(); ++it) {
1893 bool existed_before = !it->second.original.ref(syncable::IS_DEL); 1889 bool existed_before = !it->second.original.ref(syncable::IS_DEL);
1894 bool exists_now = !it->second.mutated.ref(syncable::IS_DEL); 1890 bool exists_now = !it->second.mutated.ref(syncable::IS_DEL);
1895 1891
1896 // Omit items that aren't associated with a model. 1892 // Omit items that aren't associated with a model.
1897 syncable::ModelType type = 1893 syncer::ModelType type =
1898 syncable::GetModelTypeFromSpecifics( 1894 syncer::GetModelTypeFromSpecifics(
1899 it->second.mutated.ref(SPECIFICS)); 1895 it->second.mutated.ref(SPECIFICS));
1900 if (type < syncable::FIRST_REAL_MODEL_TYPE) 1896 if (type < syncer::FIRST_REAL_MODEL_TYPE)
1901 continue; 1897 continue;
1902 1898
1903 int64 handle = it->first; 1899 int64 handle = it->first;
1904 if (exists_now && !existed_before) 1900 if (exists_now && !existed_before)
1905 change_buffers_[type].PushAddedItem(handle); 1901 change_buffers_[type].PushAddedItem(handle);
1906 else if (!exists_now && existed_before) 1902 else if (!exists_now && existed_before)
1907 change_buffers_[type].PushDeletedItem(handle); 1903 change_buffers_[type].PushDeletedItem(handle);
1908 else if (exists_now && existed_before && 1904 else if (exists_now && existed_before &&
1909 VisiblePropertiesDiffer(it->second, crypto)) { 1905 VisiblePropertiesDiffer(it->second, crypto)) {
1910 change_buffers_[type].PushUpdatedItem( 1906 change_buffers_[type].PushUpdatedItem(
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1972 Cryptographer* cryptographer = trans.GetCryptographer(); 1968 Cryptographer* cryptographer = trans.GetCryptographer();
1973 // If we've completed a sync cycle and the cryptographer isn't ready 1969 // If we've completed a sync cycle and the cryptographer isn't ready
1974 // yet, prompt the user for a passphrase. 1970 // yet, prompt the user for a passphrase.
1975 if (cryptographer->has_pending_keys()) { 1971 if (cryptographer->has_pending_keys()) {
1976 DVLOG(1) << "OnPassPhraseRequired Sent"; 1972 DVLOG(1) << "OnPassPhraseRequired Sent";
1977 sync_pb::EncryptedData pending_keys = cryptographer->GetPendingKeys(); 1973 sync_pb::EncryptedData pending_keys = cryptographer->GetPendingKeys();
1978 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, 1974 FOR_EACH_OBSERVER(SyncManager::Observer, observers_,
1979 OnPassphraseRequired(syncer::REASON_DECRYPTION, 1975 OnPassphraseRequired(syncer::REASON_DECRYPTION,
1980 pending_keys)); 1976 pending_keys));
1981 } else if (!cryptographer->is_ready() && 1977 } else if (!cryptographer->is_ready() &&
1982 event.snapshot.initial_sync_ended().Has(syncable::NIGORI)) { 1978 event.snapshot.initial_sync_ended().Has(syncer::NIGORI)) {
1983 DVLOG(1) << "OnPassphraseRequired sent because cryptographer is not " 1979 DVLOG(1) << "OnPassphraseRequired sent because cryptographer is not "
1984 << "ready"; 1980 << "ready";
1985 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, 1981 FOR_EACH_OBSERVER(SyncManager::Observer, observers_,
1986 OnPassphraseRequired(syncer::REASON_ENCRYPTION, 1982 OnPassphraseRequired(syncer::REASON_ENCRYPTION,
1987 sync_pb::EncryptedData())); 1983 sync_pb::EncryptedData()));
1988 } 1984 }
1989 1985
1990 NotifyCryptographerState(cryptographer); 1986 NotifyCryptographerState(cryptographer);
1991 allstatus_.SetEncryptedTypes(cryptographer->GetEncryptedTypes()); 1987 allstatus_.SetEncryptedTypes(cryptographer->GetEncryptedTypes());
1992 } 1988 }
(...skipping 22 matching lines...) Expand all
2015 2011
2016 // This is here for tests, which are still using p2p notifications. 2012 // This is here for tests, which are still using p2p notifications.
2017 // 2013 //
2018 // TODO(chron): Consider changing this back to track has_more_to_sync 2014 // TODO(chron): Consider changing this back to track has_more_to_sync
2019 // only notify peers if a successful commit has occurred. 2015 // only notify peers if a successful commit has occurred.
2020 bool is_notifiable_commit = 2016 bool is_notifiable_commit =
2021 (event.snapshot.model_neutral_state().num_successful_commits > 0); 2017 (event.snapshot.model_neutral_state().num_successful_commits > 0);
2022 if (is_notifiable_commit) { 2018 if (is_notifiable_commit) {
2023 if (sync_notifier_.get()) { 2019 if (sync_notifier_.get()) {
2024 const ModelTypeSet changed_types = 2020 const ModelTypeSet changed_types =
2025 syncable::ModelTypePayloadMapToEnumSet( 2021 syncer::ModelTypePayloadMapToEnumSet(
2026 event.snapshot.source().types); 2022 event.snapshot.source().types);
2027 sync_notifier_->SendNotification(changed_types); 2023 sync_notifier_->SendNotification(changed_types);
2028 } else { 2024 } else {
2029 DVLOG(1) << "Not sending notification: sync_notifier_ is NULL"; 2025 DVLOG(1) << "Not sending notification: sync_notifier_ is NULL";
2030 } 2026 }
2031 } 2027 }
2032 } 2028 }
2033 2029
2034 if (event.what_happened == SyncEngineEvent::STOP_SYNCING_PERMANENTLY) { 2030 if (event.what_happened == SyncEngineEvent::STOP_SYNCING_PERMANENTLY) {
2035 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, 2031 FOR_EACH_OBSERVER(SyncManager::Observer, observers_,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
2093 base::Bind(unbound_message_handler, base::Unretained(this)); 2089 base::Bind(unbound_message_handler, base::Unretained(this));
2094 } 2090 }
2095 2091
2096 DictionaryValue* SyncManager::SyncInternal::NotificationInfoToValue( 2092 DictionaryValue* SyncManager::SyncInternal::NotificationInfoToValue(
2097 const NotificationInfoMap& notification_info) { 2093 const NotificationInfoMap& notification_info) {
2098 DictionaryValue* value = new DictionaryValue(); 2094 DictionaryValue* value = new DictionaryValue();
2099 2095
2100 for (NotificationInfoMap::const_iterator it = notification_info.begin(); 2096 for (NotificationInfoMap::const_iterator it = notification_info.begin();
2101 it != notification_info.end(); ++it) { 2097 it != notification_info.end(); ++it) {
2102 const std::string& model_type_str = 2098 const std::string& model_type_str =
2103 syncable::ModelTypeToString(it->first); 2099 syncer::ModelTypeToString(it->first);
2104 value->Set(model_type_str, it->second.ToValue()); 2100 value->Set(model_type_str, it->second.ToValue());
2105 } 2101 }
2106 2102
2107 return value; 2103 return value;
2108 } 2104 }
2109 2105
2110 JsArgList SyncManager::SyncInternal::GetNotificationState( 2106 JsArgList SyncManager::SyncInternal::GetNotificationState(
2111 const JsArgList& args) { 2107 const JsArgList& args) {
2112 bool notifications_enabled = allstatus_.status().notifications_enabled; 2108 bool notifications_enabled = allstatus_.status().notifications_enabled;
2113 ListValue return_args; 2109 ListValue return_args;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
2226 for (syncable::Directory::ChildHandles::const_iterator it = 2222 for (syncable::Directory::ChildHandles::const_iterator it =
2227 child_handles.begin(); it != child_handles.end(); ++it) { 2223 child_handles.begin(); it != child_handles.end(); ++it) {
2228 child_ids->Append(Value::CreateStringValue( 2224 child_ids->Append(Value::CreateStringValue(
2229 base::Int64ToString(*it))); 2225 base::Int64ToString(*it)));
2230 } 2226 }
2231 } 2227 }
2232 return JsArgList(&return_args); 2228 return JsArgList(&return_args);
2233 } 2229 }
2234 2230
2235 void SyncManager::SyncInternal::OnEncryptedTypesChanged( 2231 void SyncManager::SyncInternal::OnEncryptedTypesChanged(
2236 syncable::ModelTypeSet encrypted_types, 2232 syncer::ModelTypeSet encrypted_types,
2237 bool encrypt_everything) { 2233 bool encrypt_everything) {
2238 // NOTE: We're in a transaction. 2234 // NOTE: We're in a transaction.
2239 FOR_EACH_OBSERVER( 2235 FOR_EACH_OBSERVER(
2240 SyncManager::Observer, observers_, 2236 SyncManager::Observer, observers_,
2241 OnEncryptedTypesChanged(encrypted_types, encrypt_everything)); 2237 OnEncryptedTypesChanged(encrypted_types, encrypt_everything));
2242 } 2238 }
2243 2239
2244 void SyncManager::SyncInternal::UpdateNotificationInfo( 2240 void SyncManager::SyncInternal::UpdateNotificationInfo(
2245 const syncable::ModelTypePayloadMap& type_payloads) { 2241 const syncer::ModelTypePayloadMap& type_payloads) {
2246 for (syncable::ModelTypePayloadMap::const_iterator it = type_payloads.begin(); 2242 for (syncer::ModelTypePayloadMap::const_iterator it = type_payloads.begin();
2247 it != type_payloads.end(); ++it) { 2243 it != type_payloads.end(); ++it) {
2248 NotificationInfo* info = &notification_info_map_[it->first]; 2244 NotificationInfo* info = &notification_info_map_[it->first];
2249 info->total_count++; 2245 info->total_count++;
2250 info->payload = it->second; 2246 info->payload = it->second;
2251 } 2247 }
2252 } 2248 }
2253 2249
2254 void SyncManager::SyncInternal::OnNotificationsEnabled() { 2250 void SyncManager::SyncInternal::OnNotificationsEnabled() {
2255 DVLOG(1) << "Notifications enabled"; 2251 DVLOG(1) << "Notifications enabled";
2256 allstatus_.SetNotificationsEnabled(true); 2252 allstatus_.SetNotificationsEnabled(true);
(...skipping 26 matching lines...) Expand all
2283 js_event_handler_.Call(FROM_HERE, 2279 js_event_handler_.Call(FROM_HERE,
2284 &JsEventHandler::HandleJsEvent, 2280 &JsEventHandler::HandleJsEvent,
2285 "onNotificationStateChange", 2281 "onNotificationStateChange",
2286 JsEventDetails(&details)); 2282 JsEventDetails(&details));
2287 } 2283 }
2288 // TODO(akalin): Treat a CREDENTIALS_REJECTED state as an auth 2284 // TODO(akalin): Treat a CREDENTIALS_REJECTED state as an auth
2289 // error. 2285 // error.
2290 } 2286 }
2291 2287
2292 void SyncManager::SyncInternal::OnIncomingNotification( 2288 void SyncManager::SyncInternal::OnIncomingNotification(
2293 const syncable::ModelTypePayloadMap& type_payloads, 2289 const syncer::ModelTypePayloadMap& type_payloads,
2294 syncer::IncomingNotificationSource source) { 2290 syncer::IncomingNotificationSource source) {
2295 DCHECK(thread_checker_.CalledOnValidThread()); 2291 DCHECK(thread_checker_.CalledOnValidThread());
2296 if (source == syncer::LOCAL_NOTIFICATION) { 2292 if (source == syncer::LOCAL_NOTIFICATION) {
2297 if (scheduler()) { 2293 if (scheduler()) {
2298 scheduler()->ScheduleNudgeWithPayloadsAsync( 2294 scheduler()->ScheduleNudgeWithPayloadsAsync(
2299 TimeDelta::FromMilliseconds(kSyncRefreshDelayMsec), 2295 TimeDelta::FromMilliseconds(kSyncRefreshDelayMsec),
2300 syncer::NUDGE_SOURCE_LOCAL_REFRESH, 2296 syncer::NUDGE_SOURCE_LOCAL_REFRESH,
2301 type_payloads, FROM_HERE); 2297 type_payloads, FROM_HERE);
2302 } 2298 }
2303 } else if (!type_payloads.empty()) { 2299 } else if (!type_payloads.empty()) {
2304 if (scheduler()) { 2300 if (scheduler()) {
2305 scheduler()->ScheduleNudgeWithPayloadsAsync( 2301 scheduler()->ScheduleNudgeWithPayloadsAsync(
2306 TimeDelta::FromMilliseconds(kSyncSchedulerDelayMsec), 2302 TimeDelta::FromMilliseconds(kSyncSchedulerDelayMsec),
2307 syncer::NUDGE_SOURCE_NOTIFICATION, 2303 syncer::NUDGE_SOURCE_NOTIFICATION,
2308 type_payloads, FROM_HERE); 2304 type_payloads, FROM_HERE);
2309 } 2305 }
2310 allstatus_.IncrementNotificationsReceived(); 2306 allstatus_.IncrementNotificationsReceived();
2311 UpdateNotificationInfo(type_payloads); 2307 UpdateNotificationInfo(type_payloads);
2312 debug_info_event_listener_.OnIncomingNotification(type_payloads); 2308 debug_info_event_listener_.OnIncomingNotification(type_payloads);
2313 } else { 2309 } else {
2314 LOG(WARNING) << "Sync received notification without any type information."; 2310 LOG(WARNING) << "Sync received notification without any type information.";
2315 } 2311 }
2316 2312
2317 if (js_event_handler_.IsInitialized()) { 2313 if (js_event_handler_.IsInitialized()) {
2318 DictionaryValue details; 2314 DictionaryValue details;
2319 ListValue* changed_types = new ListValue(); 2315 ListValue* changed_types = new ListValue();
2320 details.Set("changedTypes", changed_types); 2316 details.Set("changedTypes", changed_types);
2321 for (syncable::ModelTypePayloadMap::const_iterator 2317 for (syncer::ModelTypePayloadMap::const_iterator
2322 it = type_payloads.begin(); 2318 it = type_payloads.begin();
2323 it != type_payloads.end(); ++it) { 2319 it != type_payloads.end(); ++it) {
2324 const std::string& model_type_str = 2320 const std::string& model_type_str =
2325 syncable::ModelTypeToString(it->first); 2321 syncer::ModelTypeToString(it->first);
2326 changed_types->Append(Value::CreateStringValue(model_type_str)); 2322 changed_types->Append(Value::CreateStringValue(model_type_str));
2327 } 2323 }
2328 details.SetString("source", (source == syncer::LOCAL_NOTIFICATION) ? 2324 details.SetString("source", (source == syncer::LOCAL_NOTIFICATION) ?
2329 "LOCAL_NOTIFICATION" : "REMOTE_NOTIFICATION"); 2325 "LOCAL_NOTIFICATION" : "REMOTE_NOTIFICATION");
2330 js_event_handler_.Call(FROM_HERE, 2326 js_event_handler_.Call(FROM_HERE,
2331 &JsEventHandler::HandleJsEvent, 2327 &JsEventHandler::HandleJsEvent,
2332 "onIncomingNotification", 2328 "onIncomingNotification",
2333 JsEventDetails(&details)); 2329 JsEventDetails(&details));
2334 } 2330 }
2335 } 2331 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2367 data_->UpdateCryptographerAndNigori( 2363 data_->UpdateCryptographerAndNigori(
2368 chrome_version, 2364 chrome_version,
2369 done_callback); 2365 done_callback);
2370 } 2366 }
2371 2367
2372 TimeDelta SyncManager::GetNudgeDelayTimeDelta( 2368 TimeDelta SyncManager::GetNudgeDelayTimeDelta(
2373 const ModelType& model_type) { 2369 const ModelType& model_type) {
2374 return data_->GetNudgeDelayTimeDelta(model_type); 2370 return data_->GetNudgeDelayTimeDelta(model_type);
2375 } 2371 }
2376 2372
2377 syncable::ModelTypeSet SyncManager::GetEncryptedDataTypesForTest() const { 2373 syncer::ModelTypeSet SyncManager::GetEncryptedDataTypesForTest() const {
2378 ReadTransaction trans(FROM_HERE, GetUserShare()); 2374 ReadTransaction trans(FROM_HERE, GetUserShare());
2379 return GetEncryptedTypes(&trans); 2375 return GetEncryptedTypes(&trans);
2380 } 2376 }
2381 2377
2382 bool SyncManager::ReceivedExperiment(syncer::Experiments* experiments) 2378 bool SyncManager::ReceivedExperiment(syncer::Experiments* experiments)
2383 const { 2379 const {
2384 ReadTransaction trans(FROM_HERE, GetUserShare()); 2380 ReadTransaction trans(FROM_HERE, GetUserShare());
2385 ReadNode node(&trans); 2381 ReadNode node(&trans);
2386 if (node.InitByTagLookup(kNigoriTag) != syncer::BaseNode::INIT_OK) { 2382 if (node.InitByTagLookup(kNigoriTag) != syncer::BaseNode::INIT_OK) {
2387 DVLOG(1) << "Couldn't find Nigori node."; 2383 DVLOG(1) << "Couldn't find Nigori node.";
(...skipping 19 matching lines...) Expand all
2407 2403
2408 void SyncManager::SimulateDisableNotificationsForTest(int reason) { 2404 void SyncManager::SimulateDisableNotificationsForTest(int reason) {
2409 DCHECK(thread_checker_.CalledOnValidThread()); 2405 DCHECK(thread_checker_.CalledOnValidThread());
2410 data_->OnNotificationsDisabled( 2406 data_->OnNotificationsDisabled(
2411 static_cast<syncer::NotificationsDisabledReason>(reason)); 2407 static_cast<syncer::NotificationsDisabledReason>(reason));
2412 } 2408 }
2413 2409
2414 void SyncManager::TriggerOnIncomingNotificationForTest( 2410 void SyncManager::TriggerOnIncomingNotificationForTest(
2415 ModelTypeSet model_types) { 2411 ModelTypeSet model_types) {
2416 DCHECK(thread_checker_.CalledOnValidThread()); 2412 DCHECK(thread_checker_.CalledOnValidThread());
2417 syncable::ModelTypePayloadMap model_types_with_payloads = 2413 syncer::ModelTypePayloadMap model_types_with_payloads =
2418 syncable::ModelTypePayloadMapFromEnumSet(model_types, 2414 syncer::ModelTypePayloadMapFromEnumSet(model_types,
2419 std::string()); 2415 std::string());
2420 2416
2421 data_->OnIncomingNotification(model_types_with_payloads, 2417 data_->OnIncomingNotification(model_types_with_payloads,
2422 syncer::REMOTE_NOTIFICATION); 2418 syncer::REMOTE_NOTIFICATION);
2423 } 2419 }
2424 2420
2425 const char* ConnectionStatusToString(ConnectionStatus status) { 2421 const char* ConnectionStatusToString(ConnectionStatus status) {
2426 switch (status) { 2422 switch (status) {
2427 case CONNECTION_OK: 2423 case CONNECTION_OK:
2428 return "CONNECTION_OK"; 2424 return "CONNECTION_OK";
(...skipping 17 matching lines...) Expand all
2446 return "REASON_ENCRYPTION"; 2442 return "REASON_ENCRYPTION";
2447 case REASON_DECRYPTION: 2443 case REASON_DECRYPTION:
2448 return "REASON_DECRYPTION"; 2444 return "REASON_DECRYPTION";
2449 default: 2445 default:
2450 NOTREACHED(); 2446 NOTREACHED();
2451 return "INVALID_REASON"; 2447 return "INVALID_REASON";
2452 } 2448 }
2453 } 2449 }
2454 2450
2455 // Helper function to determine if initial sync had ended for types. 2451 // Helper function to determine if initial sync had ended for types.
2456 bool InitialSyncEndedForTypes(syncable::ModelTypeSet types, 2452 bool InitialSyncEndedForTypes(syncer::ModelTypeSet types,
2457 syncer::UserShare* share) { 2453 syncer::UserShare* share) {
2458 for (syncable::ModelTypeSet::Iterator i = types.First(); 2454 for (syncer::ModelTypeSet::Iterator i = types.First();
2459 i.Good(); i.Inc()) { 2455 i.Good(); i.Inc()) {
2460 if (!share->directory->initial_sync_ended_for_type(i.Get())) 2456 if (!share->directory->initial_sync_ended_for_type(i.Get()))
2461 return false; 2457 return false;
2462 } 2458 }
2463 return true; 2459 return true;
2464 } 2460 }
2465 2461
2466 syncable::ModelTypeSet GetTypesWithEmptyProgressMarkerToken( 2462 syncer::ModelTypeSet GetTypesWithEmptyProgressMarkerToken(
2467 syncable::ModelTypeSet types, 2463 syncer::ModelTypeSet types,
2468 syncer::UserShare* share) { 2464 syncer::UserShare* share) {
2469 syncable::ModelTypeSet result; 2465 syncer::ModelTypeSet result;
2470 for (syncable::ModelTypeSet::Iterator i = types.First(); 2466 for (syncer::ModelTypeSet::Iterator i = types.First();
2471 i.Good(); i.Inc()) { 2467 i.Good(); i.Inc()) {
2472 sync_pb::DataTypeProgressMarker marker; 2468 sync_pb::DataTypeProgressMarker marker;
2473 share->directory->GetDownloadProgress(i.Get(), &marker); 2469 share->directory->GetDownloadProgress(i.Get(), &marker);
2474 2470
2475 if (marker.token().empty()) 2471 if (marker.token().empty())
2476 result.Put(i.Get()); 2472 result.Put(i.Get());
2477 2473
2478 } 2474 }
2479 return result; 2475 return result;
2480 } 2476 }
2481 2477
2482 } // namespace syncer 2478 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/internal_api/read_node.cc ('k') | sync/internal_api/syncapi_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698