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

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 compile/test 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 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 // |post_factory| will be owned internally and used to create 365 // |post_factory| will be owned internally and used to create
366 // instances of an HttpPostProvider. 366 // instances of an HttpPostProvider.
367 // |model_safe_worker| ownership is given to the SyncManager. 367 // |model_safe_worker| ownership is given to the SyncManager.
368 // |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
369 // HTTP header. Used internally when collecting stats to classify clients. 369 // HTTP header. Used internally when collecting stats to classify clients.
370 // |sync_notifier| is owned and used to listen for notifications. 370 // |sync_notifier| is owned and used to listen for notifications.
371 // |report_unrecoverable_error_function| may be NULL. 371 // |report_unrecoverable_error_function| may be NULL.
372 // 372 //
373 // TODO(akalin): Replace the |post_factory| parameter with a 373 // TODO(akalin): Replace the |post_factory| parameter with a
374 // URLFetcher parameter. 374 // URLFetcher parameter.
375 bool Init(const FilePath& database_location, 375 virtual bool Init(
376 const syncer::WeakHandle<syncer::JsEventHandler>& 376 const FilePath& database_location,
377 event_handler, 377 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler,
378 const std::string& sync_server_and_path, 378 const std::string& sync_server_and_path,
379 int sync_server_port, 379 int sync_server_port,
380 bool use_ssl, 380 bool use_ssl,
381 const scoped_refptr<base::TaskRunner>& blocking_task_runner, 381 const scoped_refptr<base::TaskRunner>& blocking_task_runner,
382 HttpPostProviderFactory* post_factory, 382 scoped_ptr<HttpPostProviderFactory> post_factory,
383 const syncer::ModelSafeRoutingInfo& model_safe_routing_info, 383 const syncer::ModelSafeRoutingInfo& model_safe_routing_info,
384 const std::vector<syncer::ModelSafeWorker*>& workers, 384 const std::vector<syncer::ModelSafeWorker*>& workers,
385 syncer::ExtensionsActivityMonitor* 385 syncer::ExtensionsActivityMonitor* extensions_activity_monitor,
386 extensions_activity_monitor, 386 ChangeDelegate* change_delegate,
387 ChangeDelegate* change_delegate, 387 const SyncCredentials& credentials,
388 const SyncCredentials& credentials, 388 scoped_ptr<syncer::SyncNotifier> sync_notifier,
389 syncer::SyncNotifier* sync_notifier, 389 const std::string& restored_key_for_bootstrapping,
390 const std::string& restored_key_for_bootstrapping, 390 TestingMode testing_mode,
391 TestingMode testing_mode, 391 syncer::Encryptor* encryptor,
392 syncer::Encryptor* encryptor, 392 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler,
393 syncer::UnrecoverableErrorHandler* 393 syncer::ReportUnrecoverableErrorFunction
394 unrecoverable_error_handler, 394 report_unrecoverable_error_function);
395 syncer::ReportUnrecoverableErrorFunction
396 report_unrecoverable_error_function);
397 395
398 // Throw an unrecoverable error from a transaction (mostly used for 396 // Throw an unrecoverable error from a transaction (mostly used for
399 // testing). 397 // testing).
400 void ThrowUnrecoverableError(); 398 void ThrowUnrecoverableError();
401 399
402 // Returns the set of types for which we have stored some sync data. 400 virtual syncer::ModelTypeSet InitialSyncEndedTypes();
403 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);
404 406
405 // 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.
406 void UpdateCredentials(const SyncCredentials& credentials); 408 void UpdateCredentials(const SyncCredentials& credentials);
407 409
408 // Called when the user disables or enables a sync type. 410 // Called when the user disables or enables a sync type.
409 void UpdateEnabledTypes(const syncer::ModelTypeSet& enabled_types); 411 virtual void UpdateEnabledTypes(const syncer::ModelTypeSet& enabled_types);
410 412
411 // 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.
412 void StartSyncingNormally( 414 void StartSyncingNormally(
413 const syncer::ModelSafeRoutingInfo& routing_info); 415 const syncer::ModelSafeRoutingInfo& routing_info);
414 416
415 // Attempts to re-encrypt encrypted data types using the passphrase provided. 417 // Attempts to re-encrypt encrypted data types using the passphrase provided.
416 // Notifies observers of the result of the operation via OnPassphraseAccepted 418 // Notifies observers of the result of the operation via OnPassphraseAccepted
417 // or OnPassphraseRequired, updates the nigori node, and does re-encryption as 419 // or OnPassphraseRequired, updates the nigori node, and does re-encryption as
418 // appropriate. If an explicit password has been set previously, we drop 420 // appropriate. If an explicit password has been set previously, we drop
419 // subsequent requests to set a passphrase. If the cryptographer has pending 421 // subsequent requests to set a passphrase. If the cryptographer has pending
(...skipping 10 matching lines...) Expand all
430 void SetDecryptionPassphrase(const std::string& passphrase); 432 void SetDecryptionPassphrase(const std::string& passphrase);
431 433
432 // Switches the mode of operation to CONFIGURATION_MODE and performs 434 // Switches the mode of operation to CONFIGURATION_MODE and performs
433 // any configuration tasks needed as determined by the params. Once complete, 435 // any configuration tasks needed as determined by the params. Once complete,
434 // syncer will remain in CONFIGURATION_MODE until StartSyncingNormally is 436 // syncer will remain in CONFIGURATION_MODE until StartSyncingNormally is
435 // called. 437 // called.
436 // |ready_task| is invoked when the configuration completes. 438 // |ready_task| is invoked when the configuration completes.
437 // |retry_task| is invoked if the configuration job could not immediately 439 // |retry_task| is invoked if the configuration job could not immediately
438 // execute. |ready_task| will still be called when it eventually 440 // execute. |ready_task| will still be called when it eventually
439 // does finish. 441 // does finish.
440 void ConfigureSyncer( 442 virtual void ConfigureSyncer(
441 ConfigureReason reason, 443 ConfigureReason reason,
442 const syncer::ModelTypeSet& types_to_config, 444 const syncer::ModelTypeSet& types_to_config,
443 const syncer::ModelSafeRoutingInfo& new_routing_info, 445 const syncer::ModelSafeRoutingInfo& new_routing_info,
444 const base::Closure& ready_task, 446 const base::Closure& ready_task,
445 const base::Closure& retry_task); 447 const base::Closure& retry_task);
446 448
447 // Adds a listener to be notified of sync events. 449 // Adds a listener to be notified of sync events.
448 // 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
449 // having received OnInitializationCompleted. 451 // having received OnInitializationCompleted.
450 void AddObserver(Observer* observer); 452 virtual void AddObserver(Observer* observer);
451 453
452 // Remove the given observer. Make sure to call this if the 454 // Remove the given observer. Make sure to call this if the
453 // Observer is being destroyed so the SyncManager doesn't 455 // Observer is being destroyed so the SyncManager doesn't
454 // potentially dereference garbage. 456 // potentially dereference garbage.
455 void RemoveObserver(Observer* observer); 457 virtual void RemoveObserver(Observer* observer);
456 458
457 // Status-related getter. May be called on any thread. 459 // Status-related getter. May be called on any thread.
458 SyncStatus GetDetailedStatus() const; 460 SyncStatus GetDetailedStatus() const;
459 461
460 // 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.
461 // May be called on any thread. 463 // May be called on any thread.
462 bool IsUsingExplicitPassphrase(); 464 bool IsUsingExplicitPassphrase();
463 465
464 // Call periodically from a database-safe thread to persist recent changes 466 // Call periodically from a database-safe thread to persist recent changes
465 // to the syncapi model. 467 // to the syncapi model.
466 void SaveChanges(); 468 void SaveChanges();
467 469
468 // Initiates shutdown of various components in the sync engine. Must be 470 // Initiates shutdown of various components in the sync engine. Must be
469 // 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
470 // 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
471 // same as with StartConfigurationMode. If provided and a scheduler / sync 473 // same as with StartConfigurationMode. If provided and a scheduler / sync
472 // 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
473 // 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.
474 // 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
475 // 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
476 // stopped. 478 // stopped.
477 void StopSyncingForShutdown(const base::Closure& callback); 479 void StopSyncingForShutdown(const base::Closure& callback);
478 480
479 // Issue a final SaveChanges, and close sqlite handles. 481 // Issue a final SaveChanges, and close sqlite handles.
480 void ShutdownOnSyncThread(); 482 virtual void ShutdownOnSyncThread();
481 483
482 // May be called from any thread. 484 // May be called from any thread.
483 UserShare* GetUserShare() const; 485 UserShare* GetUserShare() const;
484 486
485 // Inform the cryptographer of the most recent passphrase and set of 487 // Inform the cryptographer of the most recent passphrase and set of
486 // encrypted types (from nigori node), then ensure all data that 488 // encrypted types (from nigori node), then ensure all data that
487 // needs encryption is encrypted with the appropriate passphrase. 489 // needs encryption is encrypted with the appropriate passphrase.
488 // 490 //
489 // May trigger OnPassphraseRequired(). Otherwise, it will trigger 491 // May trigger OnPassphraseRequired(). Otherwise, it will trigger
490 // OnEncryptedTypesChanged() if necessary (see comments for 492 // OnEncryptedTypesChanged() if necessary (see comments for
491 // OnEncryptedTypesChanged()), and then OnEncryptionComplete(). 493 // OnEncryptedTypesChanged()), and then OnEncryptionComplete().
492 // 494 //
493 // Also updates or adds device information to the nigori node. 495 // Also updates or adds device information to the nigori node.
494 // 496 //
495 // Note: opens a transaction, so must only be called after syncapi 497 // Note: opens a transaction, so must only be called after syncapi
496 // has been initialized. 498 // has been initialized.
497 void RefreshNigori(const std::string& chrome_version, 499 virtual void RefreshNigori(const std::string& chrome_version,
498 const base::Closure& done_callback); 500 const base::Closure& done_callback);
499 501
500 // 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
501 // disabled without clearing the server data. 503 // disabled without clearing the server data.
502 // 504 //
503 // This will trigger OnEncryptedTypesChanged() if necessary (see 505 // This will trigger OnEncryptedTypesChanged() if necessary (see
504 // comments for OnEncryptedTypesChanged()). It then may trigger 506 // comments for OnEncryptedTypesChanged()). It then may trigger
505 // OnPassphraseRequired(), but otherwise it will trigger 507 // OnPassphraseRequired(), but otherwise it will trigger
506 // OnEncryptionComplete(). 508 // OnEncryptionComplete().
507 void EnableEncryptEverything(); 509 void EnableEncryptEverything();
508 510
509 // Returns true if we are currently encrypting all sync data. May 511 // Returns true if we are currently encrypting all sync data. May
510 // be called on any thread. 512 // be called on any thread.
511 bool EncryptEverythingEnabledForTest() const; 513 bool EncryptEverythingEnabledForTest() const;
512 514
513 // Gets the set of encrypted types from the cryptographer 515 // Gets the set of encrypted types from the cryptographer
514 // Note: opens a transaction. May be called from any thread. 516 // Note: opens a transaction. May be called from any thread.
515 syncer::ModelTypeSet GetEncryptedDataTypesForTest() const; 517 syncer::ModelTypeSet GetEncryptedDataTypesForTest() const;
516 518
517 // Reads the nigori node to determine if any experimental features should 519 // Reads the nigori node to determine if any experimental features should
518 // be enabled. 520 // be enabled.
519 // Note: opens a transaction. May be called on any thread. 521 // Note: opens a transaction. May be called on any thread.
520 bool ReceivedExperiment(syncer::Experiments* experiments) const; 522 virtual bool ReceivedExperiment(syncer::Experiments* experiments) const;
521 523
522 // 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
523 // any remaining unsynced items. May be called on any thread. 525 // any remaining unsynced items. May be called on any thread.
524 bool HasUnsyncedItems() const; 526 bool HasUnsyncedItems() const;
525 527
526 // Functions used for testing. 528 // Functions used for testing.
527 529
528 void SimulateEnableNotificationsForTest(); 530 void SimulateEnableNotificationsForTest();
529 531
530 void SimulateDisableNotificationsForTest(int reason); 532 void SimulateDisableNotificationsForTest(int reason);
(...skipping 22 matching lines...) Expand all
553 base::ThreadChecker thread_checker_; 555 base::ThreadChecker thread_checker_;
554 556
555 // An opaque pointer to the nested private class. 557 // An opaque pointer to the nested private class.
556 SyncInternal* data_; 558 SyncInternal* data_;
557 559
558 DISALLOW_COPY_AND_ASSIGN(SyncManager); 560 DISALLOW_COPY_AND_ASSIGN(SyncManager);
559 }; 561 };
560 562
561 bool InitialSyncEndedForTypes(syncer::ModelTypeSet types, UserShare* share); 563 bool InitialSyncEndedForTypes(syncer::ModelTypeSet types, UserShare* share);
562 564
563 syncer::ModelTypeSet GetTypesWithEmptyProgressMarkerToken(
564 syncer::ModelTypeSet types,
565 syncer::UserShare* share);
566
567 const char* ConnectionStatusToString(ConnectionStatus status); 565 const char* ConnectionStatusToString(ConnectionStatus status);
568 566
569 // Returns the string representation of a PassphraseRequiredReason value. 567 // Returns the string representation of a PassphraseRequiredReason value.
570 const char* PassphraseRequiredReasonToString(PassphraseRequiredReason reason); 568 const char* PassphraseRequiredReasonToString(PassphraseRequiredReason reason);
571 569
572 } // namespace syncer 570 } // namespace syncer
573 571
574 #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