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

Side by Side Diff: sync/internal_api/public/sync_manager.h

Issue 10701085: Revert "Revert 142517 - [Sync] Refactor sync configuration logic." (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix deps 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
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 #ifndef SYNC_INTERNAL_API_PUBLIC_SYNC_MANAGER_H_ 5 #ifndef SYNC_INTERNAL_API_PUBLIC_SYNC_MANAGER_H_
6 #define SYNC_INTERNAL_API_PUBLIC_SYNC_MANAGER_H_ 6 #define SYNC_INTERNAL_API_PUBLIC_SYNC_MANAGER_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 13 matching lines...) Expand all
24 #include "sync/internal_api/public/util/unrecoverable_error_handler.h" 24 #include "sync/internal_api/public/util/unrecoverable_error_handler.h"
25 #include "sync/internal_api/public/util/weak_handle.h" 25 #include "sync/internal_api/public/util/weak_handle.h"
26 #include "sync/protocol/sync_protocol_error.h" 26 #include "sync/protocol/sync_protocol_error.h"
27 27
28 namespace syncer { 28 namespace syncer {
29 class Encryptor; 29 class Encryptor;
30 struct Experiments; 30 struct Experiments;
31 class ExtensionsActivityMonitor; 31 class ExtensionsActivityMonitor;
32 class JsBackend; 32 class JsBackend;
33 class JsEventHandler; 33 class JsEventHandler;
34 class SyncScheduler;
34 35
35 namespace sessions { 36 namespace sessions {
36 class SyncSessionSnapshot; 37 class SyncSessionSnapshot;
37 } // namespace sessions 38 } // namespace sessions
38 } // namespace syncer 39 } // namespace syncer
39 40
40 namespace syncer { 41 namespace syncer {
41 class SyncNotifier; 42 class SyncNotifier;
42 } // namespace syncer 43 } // namespace syncer
43 44
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 // |post_factory| will be owned internally and used to create 365 // |post_factory| will be owned internally and used to create
365 // instances of an HttpPostProvider. 366 // instances of an HttpPostProvider.
366 // |model_safe_worker| ownership is given to the SyncManager. 367 // |model_safe_worker| ownership is given to the SyncManager.
367 // |user_agent| is a 7-bit ASCII string suitable for use as the User-Agent 368 // |user_agent| is a 7-bit ASCII string suitable for use as the User-Agent
368 // HTTP header. Used internally when collecting stats to classify clients. 369 // HTTP header. Used internally when collecting stats to classify clients.
369 // |sync_notifier| is owned and used to listen for notifications. 370 // |sync_notifier| is owned and used to listen for notifications.
370 // |report_unrecoverable_error_function| may be NULL. 371 // |report_unrecoverable_error_function| may be NULL.
371 // 372 //
372 // TODO(akalin): Replace the |post_factory| parameter with a 373 // TODO(akalin): Replace the |post_factory| parameter with a
373 // URLFetcher parameter. 374 // URLFetcher parameter.
374 bool Init(const FilePath& database_location, 375 virtual bool Init(
375 const syncer::WeakHandle<syncer::JsEventHandler>& 376 const FilePath& database_location,
376 event_handler, 377 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler,
377 const std::string& sync_server_and_path, 378 const std::string& sync_server_and_path,
378 int sync_server_port, 379 int sync_server_port,
379 bool use_ssl, 380 bool use_ssl,
380 const scoped_refptr<base::TaskRunner>& blocking_task_runner, 381 const scoped_refptr<base::TaskRunner>& blocking_task_runner,
381 HttpPostProviderFactory* post_factory, 382 scoped_ptr<HttpPostProviderFactory> post_factory,
382 const syncer::ModelSafeRoutingInfo& model_safe_routing_info, 383 const syncer::ModelSafeRoutingInfo& model_safe_routing_info,
383 const std::vector<syncer::ModelSafeWorker*>& workers, 384 const std::vector<syncer::ModelSafeWorker*>& workers,
384 syncer::ExtensionsActivityMonitor* 385 syncer::ExtensionsActivityMonitor* extensions_activity_monitor,
385 extensions_activity_monitor, 386 ChangeDelegate* change_delegate,
386 ChangeDelegate* change_delegate, 387 const SyncCredentials& credentials,
387 const SyncCredentials& credentials, 388 scoped_ptr<syncer::SyncNotifier> sync_notifier,
388 syncer::SyncNotifier* sync_notifier, 389 const std::string& restored_key_for_bootstrapping,
389 const std::string& restored_key_for_bootstrapping, 390 TestingMode testing_mode,
390 TestingMode testing_mode, 391 syncer::Encryptor* encryptor,
391 syncer::Encryptor* encryptor, 392 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler,
392 syncer::UnrecoverableErrorHandler* 393 syncer::ReportUnrecoverableErrorFunction
393 unrecoverable_error_handler, 394 report_unrecoverable_error_function);
394 syncer::ReportUnrecoverableErrorFunction
395 report_unrecoverable_error_function);
396 395
397 // Throw an unrecoverable error from a transaction (mostly used for 396 // Throw an unrecoverable error from a transaction (mostly used for
398 // testing). 397 // testing).
399 void ThrowUnrecoverableError(); 398 void ThrowUnrecoverableError();
400 399
401 // Returns the set of types for which we have stored some sync data. 400 virtual syncer::ModelTypeSet InitialSyncEndedTypes();
402 syncer::ModelTypeSet InitialSyncEndedTypes(); 401
402 // Returns those types within |types| that have an empty progress marker
403 // token.
404 virtual syncer::ModelTypeSet GetTypesWithEmptyProgressMarkerToken(
405 syncer::ModelTypeSet types);
403 406
404 // Update tokens that we're using in Sync. Email must stay the same. 407 // Update tokens that we're using in Sync. Email must stay the same.
405 void UpdateCredentials(const SyncCredentials& credentials); 408 void UpdateCredentials(const SyncCredentials& credentials);
406 409
407 // Called when the user disables or enables a sync type. 410 // Called when the user disables or enables a sync type.
408 void UpdateEnabledTypes(const syncer::ModelTypeSet& enabled_types); 411 virtual void UpdateEnabledTypes(const syncer::ModelTypeSet& enabled_types);
409 412
410 // Put the syncer in normal mode ready to perform nudges and polls. 413 // Put the syncer in normal mode ready to perform nudges and polls.
411 void StartSyncingNormally( 414 void StartSyncingNormally(
412 const syncer::ModelSafeRoutingInfo& routing_info); 415 const syncer::ModelSafeRoutingInfo& routing_info);
413 416
414 // Attempts to re-encrypt encrypted data types using the passphrase provided. 417 // Attempts to re-encrypt encrypted data types using the passphrase provided.
415 // Notifies observers of the result of the operation via OnPassphraseAccepted 418 // Notifies observers of the result of the operation via OnPassphraseAccepted
416 // or OnPassphraseRequired, updates the nigori node, and does re-encryption as 419 // or OnPassphraseRequired, updates the nigori node, and does re-encryption as
417 // appropriate. If an explicit password has been set previously, we drop 420 // appropriate. If an explicit password has been set previously, we drop
418 // subsequent requests to set a passphrase. If the cryptographer has pending 421 // subsequent requests to set a passphrase. If the cryptographer has pending
419 // keys, and a new implicit passphrase is provided, we try decrypting the 422 // keys, and a new implicit passphrase is provided, we try decrypting the
420 // pending keys with it, and if that fails, we cache the passphrase for 423 // pending keys with it, and if that fails, we cache the passphrase for
421 // re-encryption once the pending keys are decrypted. 424 // re-encryption once the pending keys are decrypted.
422 void SetEncryptionPassphrase(const std::string& passphrase, bool is_explicit); 425 void SetEncryptionPassphrase(const std::string& passphrase, bool is_explicit);
423 426
424 // Provides a passphrase for decrypting the user's existing sync data. 427 // Provides a passphrase for decrypting the user's existing sync data.
425 // Notifies observers of the result of the operation via OnPassphraseAccepted 428 // Notifies observers of the result of the operation via OnPassphraseAccepted
426 // or OnPassphraseRequired, updates the nigori node, and does re-encryption as 429 // or OnPassphraseRequired, updates the nigori node, and does re-encryption as
427 // appropriate if there is a previously cached encryption passphrase. It is an 430 // appropriate if there is a previously cached encryption passphrase. It is an
428 // error to call this when we don't have pending keys. 431 // error to call this when we don't have pending keys.
429 void SetDecryptionPassphrase(const std::string& passphrase); 432 void SetDecryptionPassphrase(const std::string& passphrase);
430 433
431 // Puts the SyncScheduler into a mode where no normal nudge or poll traffic 434 // Switches the mode of operation to CONFIGURATION_MODE and performs
432 // will occur, but calls to RequestConfig will be supported. If |callback| 435 // any configuration tasks needed as determined by the params. Once complete,
433 // is provided, it will be invoked (from the internal SyncScheduler) when 436 // syncer will remain in CONFIGURATION_MODE until StartSyncingNormally is
434 // the thread has changed to configuration mode. 437 // called.
435 void StartConfigurationMode(const base::Closure& callback); 438 // |ready_task| is invoked when the configuration completes.
436 439 // |retry_task| is invoked if the configuration job could not immediately
437 // Switches the mode of operation to CONFIGURATION_MODE and 440 // execute. |ready_task| will still be called when it eventually
438 // schedules a config task to fetch updates for |types|. 441 // does finish.
439 void RequestConfig(const syncer::ModelSafeRoutingInfo& routing_info, 442 virtual void ConfigureSyncer(
440 const syncer::ModelTypeSet& types, 443 ConfigureReason reason,
441 syncer::ConfigureReason reason); 444 const syncer::ModelTypeSet& types_to_config,
442 445 const syncer::ModelSafeRoutingInfo& new_routing_info,
443 void RequestCleanupDisabledTypes( 446 const base::Closure& ready_task,
444 const syncer::ModelSafeRoutingInfo& routing_info); 447 const base::Closure& retry_task);
445 448
446 // Adds a listener to be notified of sync events. 449 // Adds a listener to be notified of sync events.
447 // NOTE: It is OK (in fact, it's probably a good idea) to call this before 450 // NOTE: It is OK (in fact, it's probably a good idea) to call this before
448 // having received OnInitializationCompleted. 451 // having received OnInitializationCompleted.
449 void AddObserver(Observer* observer); 452 virtual void AddObserver(Observer* observer);
450 453
451 // Remove the given observer. Make sure to call this if the 454 // Remove the given observer. Make sure to call this if the
452 // Observer is being destroyed so the SyncManager doesn't 455 // Observer is being destroyed so the SyncManager doesn't
453 // potentially dereference garbage. 456 // potentially dereference garbage.
454 void RemoveObserver(Observer* observer); 457 virtual void RemoveObserver(Observer* observer);
455 458
456 // Status-related getter. May be called on any thread. 459 // Status-related getter. May be called on any thread.
457 SyncStatus GetDetailedStatus() const; 460 SyncStatus GetDetailedStatus() const;
458 461
459 // Whether or not the Nigori node is encrypted using an explicit passphrase. 462 // Whether or not the Nigori node is encrypted using an explicit passphrase.
460 // May be called on any thread. 463 // May be called on any thread.
461 bool IsUsingExplicitPassphrase(); 464 bool IsUsingExplicitPassphrase();
462 465
463 // Call periodically from a database-safe thread to persist recent changes 466 // Call periodically from a database-safe thread to persist recent changes
464 // to the syncapi model. 467 // to the syncapi model.
465 void SaveChanges(); 468 void SaveChanges();
466 469
467 // Initiates shutdown of various components in the sync engine. Must be 470 // Initiates shutdown of various components in the sync engine. Must be
468 // called from the main thread to allow preempting ongoing tasks on the sync 471 // called from the main thread to allow preempting ongoing tasks on the sync
469 // loop (that may be blocked on I/O). The semantics of |callback| are the 472 // loop (that may be blocked on I/O). The semantics of |callback| are the
470 // same as with StartConfigurationMode. If provided and a scheduler / sync 473 // same as with StartConfigurationMode. If provided and a scheduler / sync
471 // loop exists, it will be invoked from the sync loop by the scheduler to 474 // loop exists, it will be invoked from the sync loop by the scheduler to
472 // notify that all work has been flushed + cancelled, and it is idle. 475 // notify that all work has been flushed + cancelled, and it is idle.
473 // If no scheduler exists, the callback is run immediately (from the loop 476 // If no scheduler exists, the callback is run immediately (from the loop
474 // this was created on, which is the sync loop), as sync is effectively 477 // this was created on, which is the sync loop), as sync is effectively
475 // stopped. 478 // stopped.
476 void StopSyncingForShutdown(const base::Closure& callback); 479 void StopSyncingForShutdown(const base::Closure& callback);
477 480
478 // Issue a final SaveChanges, and close sqlite handles. 481 // Issue a final SaveChanges, and close sqlite handles.
479 void ShutdownOnSyncThread(); 482 virtual void ShutdownOnSyncThread();
480 483
481 // May be called from any thread. 484 // May be called from any thread.
482 UserShare* GetUserShare() const; 485 UserShare* GetUserShare() const;
483 486
484 // Inform the cryptographer of the most recent passphrase and set of 487 // Inform the cryptographer of the most recent passphrase and set of
485 // encrypted types (from nigori node), then ensure all data that 488 // encrypted types (from nigori node), then ensure all data that
486 // needs encryption is encrypted with the appropriate passphrase. 489 // needs encryption is encrypted with the appropriate passphrase.
487 // 490 //
488 // May trigger OnPassphraseRequired(). Otherwise, it will trigger 491 // May trigger OnPassphraseRequired(). Otherwise, it will trigger
489 // OnEncryptedTypesChanged() if necessary (see comments for 492 // OnEncryptedTypesChanged() if necessary (see comments for
490 // OnEncryptedTypesChanged()), and then OnEncryptionComplete(). 493 // OnEncryptedTypesChanged()), and then OnEncryptionComplete().
491 // 494 //
492 // Also updates or adds device information to the nigori node. 495 // Also updates or adds device information to the nigori node.
493 // 496 //
494 // Note: opens a transaction, so must only be called after syncapi 497 // Note: opens a transaction, so must only be called after syncapi
495 // has been initialized. 498 // has been initialized.
496 void RefreshNigori(const std::string& chrome_version, 499 virtual void RefreshNigori(const std::string& chrome_version,
497 const base::Closure& done_callback); 500 const base::Closure& done_callback);
498 501
499 // Enable encryption of all sync data. Once enabled, it can never be 502 // Enable encryption of all sync data. Once enabled, it can never be
500 // disabled without clearing the server data. 503 // disabled without clearing the server data.
501 // 504 //
502 // This will trigger OnEncryptedTypesChanged() if necessary (see 505 // This will trigger OnEncryptedTypesChanged() if necessary (see
503 // comments for OnEncryptedTypesChanged()). It then may trigger 506 // comments for OnEncryptedTypesChanged()). It then may trigger
504 // OnPassphraseRequired(), but otherwise it will trigger 507 // OnPassphraseRequired(), but otherwise it will trigger
505 // OnEncryptionComplete(). 508 // OnEncryptionComplete().
506 void EnableEncryptEverything(); 509 void EnableEncryptEverything();
507 510
508 // Returns true if we are currently encrypting all sync data. May 511 // Returns true if we are currently encrypting all sync data. May
509 // be called on any thread. 512 // be called on any thread.
510 bool EncryptEverythingEnabledForTest() const; 513 bool EncryptEverythingEnabledForTest() const;
511 514
512 // Gets the set of encrypted types from the cryptographer 515 // Gets the set of encrypted types from the cryptographer
513 // Note: opens a transaction. May be called from any thread. 516 // Note: opens a transaction. May be called from any thread.
514 syncer::ModelTypeSet GetEncryptedDataTypesForTest() const; 517 syncer::ModelTypeSet GetEncryptedDataTypesForTest() const;
515 518
516 // Reads the nigori node to determine if any experimental features should 519 // Reads the nigori node to determine if any experimental features should
517 // be enabled. 520 // be enabled.
518 // Note: opens a transaction. May be called on any thread. 521 // Note: opens a transaction. May be called on any thread.
519 bool ReceivedExperiment(syncer::Experiments* experiments) const; 522 virtual bool ReceivedExperiment(syncer::Experiments* experiments) const;
520 523
521 // Uses a read-only transaction to determine if the directory being synced has 524 // Uses a read-only transaction to determine if the directory being synced has
522 // any remaining unsynced items. May be called on any thread. 525 // any remaining unsynced items. May be called on any thread.
523 bool HasUnsyncedItems() const; 526 bool HasUnsyncedItems() const;
524 527
525 // Functions used for testing. 528 // Functions used for testing.
526 529
527 void SimulateEnableNotificationsForTest(); 530 void SimulateEnableNotificationsForTest();
528 531
529 void SimulateDisableNotificationsForTest(int reason); 532 void SimulateDisableNotificationsForTest(int reason);
530 533
531 void TriggerOnIncomingNotificationForTest( 534 void TriggerOnIncomingNotificationForTest(
532 syncer::ModelTypeSet model_types); 535 syncer::ModelTypeSet model_types);
533 536
534 static const int kDefaultNudgeDelayMilliseconds; 537 static const int kDefaultNudgeDelayMilliseconds;
535 static const int kPreferencesNudgeDelayMilliseconds; 538 static const int kPreferencesNudgeDelayMilliseconds;
536 static const int kPiggybackNudgeDelay; 539 static const int kPiggybackNudgeDelay;
537 540
538 static const FilePath::CharType kSyncDatabaseFilename[]; 541 static const FilePath::CharType kSyncDatabaseFilename[];
539 542
540 private: 543 private:
544 friend class SyncManagerTest;
541 FRIEND_TEST_ALL_PREFIXES(SyncManagerTest, NudgeDelayTest); 545 FRIEND_TEST_ALL_PREFIXES(SyncManagerTest, NudgeDelayTest);
542 546
543 // For unit tests. 547 // For unit tests.
544 base::TimeDelta GetNudgeDelayTimeDelta(const syncer::ModelType& model_type); 548 base::TimeDelta GetNudgeDelayTimeDelta(const syncer::ModelType& model_type);
545 549
550 // Set the internal scheduler for testing purposes.
551 // TODO(sync): Use dependency injection instead. crbug.com/133061
552 void SetSyncSchedulerForTest(
553 scoped_ptr<syncer::SyncScheduler> scheduler);
554
546 base::ThreadChecker thread_checker_; 555 base::ThreadChecker thread_checker_;
547 556
548 // An opaque pointer to the nested private class. 557 // An opaque pointer to the nested private class.
549 SyncInternal* data_; 558 SyncInternal* data_;
550 559
551 DISALLOW_COPY_AND_ASSIGN(SyncManager); 560 DISALLOW_COPY_AND_ASSIGN(SyncManager);
552 }; 561 };
553 562
554 bool InitialSyncEndedForTypes(syncer::ModelTypeSet types, UserShare* share); 563 bool InitialSyncEndedForTypes(syncer::ModelTypeSet types, UserShare* share);
555 564
556 syncer::ModelTypeSet GetTypesWithEmptyProgressMarkerToken(
557 syncer::ModelTypeSet types,
558 syncer::UserShare* share);
559
560 const char* ConnectionStatusToString(ConnectionStatus status); 565 const char* ConnectionStatusToString(ConnectionStatus status);
561 566
562 // Returns the string representation of a PassphraseRequiredReason value. 567 // Returns the string representation of a PassphraseRequiredReason value.
563 const char* PassphraseRequiredReasonToString(PassphraseRequiredReason reason); 568 const char* PassphraseRequiredReasonToString(PassphraseRequiredReason reason);
564 569
565 } // namespace syncer 570 } // namespace syncer
566 571
567 #endif // SYNC_INTERNAL_API_PUBLIC_SYNC_MANAGER_H_ 572 #endif // SYNC_INTERNAL_API_PUBLIC_SYNC_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698