| OLD | NEW | 
|    1 // Copyright 2013 The Chromium Authors. All rights reserved. |    1 // Copyright 2013 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 COMPONENTS_SYNC_DRIVER_GLUE_SYNC_BACKEND_HOST_IMPL_H_ |    5 #ifndef COMPONENTS_SYNC_DRIVER_GLUE_SYNC_BACKEND_HOST_IMPL_H_ | 
|    6 #define COMPONENTS_SYNC_DRIVER_GLUE_SYNC_BACKEND_HOST_IMPL_H_ |    6 #define COMPONENTS_SYNC_DRIVER_GLUE_SYNC_BACKEND_HOST_IMPL_H_ | 
|    7  |    7  | 
|    8 #include <stdint.h> |    8 #include <stdint.h> | 
|    9  |    9  | 
|   10 #include <map> |   10 #include <map> | 
|   11 #include <memory> |   11 #include <memory> | 
|   12 #include <string> |   12 #include <string> | 
|   13 #include <vector> |   13 #include <vector> | 
|   14  |   14  | 
|   15 #include "base/callback.h" |   15 #include "base/callback.h" | 
|   16 #include "base/compiler_specific.h" |   16 #include "base/compiler_specific.h" | 
|   17 #include "base/macros.h" |   17 #include "base/macros.h" | 
|   18 #include "base/memory/ref_counted.h" |   18 #include "base/memory/ref_counted.h" | 
|   19 #include "base/memory/weak_ptr.h" |   19 #include "base/memory/weak_ptr.h" | 
|   20 #include "base/single_thread_task_runner.h" |   20 #include "base/single_thread_task_runner.h" | 
|   21 #include "base/threading/thread.h" |   21 #include "base/threading/thread.h" | 
|   22 #include "components/invalidation/public/invalidation_handler.h" |   22 #include "components/invalidation/public/invalidation_handler.h" | 
|   23 #include "components/sync/base/extensions_activity.h" |   23 #include "components/sync/base/extensions_activity.h" | 
|   24 #include "components/sync/base/model_type.h" |   24 #include "components/sync/base/model_type.h" | 
|   25 #include "components/sync/base/weak_handle.h" |   25 #include "components/sync/base/weak_handle.h" | 
|   26 #include "components/sync/core/configure_reason.h" |   26 #include "components/sync/core/configure_reason.h" | 
|   27 #include "components/sync/core/sync_manager.h" |   27 #include "components/sync/core/sync_manager.h" | 
 |   28 #include "components/sync/driver/backend_data_type_configurer.h" | 
 |   29 #include "components/sync/driver/glue/sync_backend_host.h" | 
|   28 #include "components/sync/protocol/encryption.pb.h" |   30 #include "components/sync/protocol/encryption.pb.h" | 
|   29 #include "components/sync/protocol/sync_protocol_error.h" |   31 #include "components/sync/protocol/sync_protocol_error.h" | 
|   30 #include "components/sync/sessions/sync_session_snapshot.h" |   32 #include "components/sync/sessions/sync_session_snapshot.h" | 
|   31 #include "components/sync/sessions/type_debug_info_observer.h" |   33 #include "components/sync/sessions/type_debug_info_observer.h" | 
|   32 #include "components/sync_driver/backend_data_type_configurer.h" |  | 
|   33 #include "components/sync_driver/glue/sync_backend_host.h" |  | 
|   34  |   34  | 
|   35 class GURL; |   35 class GURL; | 
|   36  |   36  | 
|   37 namespace base { |   37 namespace base { | 
|   38 class MessageLoop; |   38 class MessageLoop; | 
|   39 } |   39 } | 
|   40  |   40  | 
|   41 namespace invalidation { |   41 namespace invalidation { | 
|   42 class InvalidationService; |   42 class InvalidationService; | 
|   43 } |   43 } | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
|   54  |   54  | 
|   55 namespace browser_sync { |   55 namespace browser_sync { | 
|   56  |   56  | 
|   57 class ChangeProcessor; |   57 class ChangeProcessor; | 
|   58 class SyncBackendHostCore; |   58 class SyncBackendHostCore; | 
|   59 class SyncBackendRegistrar; |   59 class SyncBackendRegistrar; | 
|   60 struct DoInitializeOptions; |   60 struct DoInitializeOptions; | 
|   61  |   61  | 
|   62 // The only real implementation of the SyncBackendHost.  See that interface's |   62 // The only real implementation of the SyncBackendHost.  See that interface's | 
|   63 // definition for documentation of public methods. |   63 // definition for documentation of public methods. | 
|   64 class SyncBackendHostImpl |   64 class SyncBackendHostImpl : public SyncBackendHost, | 
|   65     : public SyncBackendHost, |   65                             public syncer::InvalidationHandler { | 
|   66       public syncer::InvalidationHandler { |  | 
|   67  public: |   66  public: | 
|   68   typedef syncer::SyncStatus Status; |   67   typedef syncer::SyncStatus Status; | 
|   69  |   68  | 
|   70   // Create a SyncBackendHost with a reference to the |frontend| that |   69   // Create a SyncBackendHost with a reference to the |frontend| that | 
|   71   // it serves and communicates to via the SyncFrontend interface (on |   70   // it serves and communicates to via the SyncFrontend interface (on | 
|   72   // the same thread it used to call the constructor).  Must outlive |   71   // the same thread it used to call the constructor).  Must outlive | 
|   73   // |sync_prefs|. |   72   // |sync_prefs|. | 
|   74   SyncBackendHostImpl( |   73   SyncBackendHostImpl( | 
|   75       const std::string& name, |   74       const std::string& name, | 
|   76       sync_driver::SyncClient* sync_client, |   75       sync_driver::SyncClient* sync_client, | 
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  167   // Request the syncer to reconfigure with the specfied params. |  166   // Request the syncer to reconfigure with the specfied params. | 
|  168   // Virtual for testing. |  167   // Virtual for testing. | 
|  169   virtual void RequestConfigureSyncer( |  168   virtual void RequestConfigureSyncer( | 
|  170       syncer::ConfigureReason reason, |  169       syncer::ConfigureReason reason, | 
|  171       syncer::ModelTypeSet to_download, |  170       syncer::ModelTypeSet to_download, | 
|  172       syncer::ModelTypeSet to_purge, |  171       syncer::ModelTypeSet to_purge, | 
|  173       syncer::ModelTypeSet to_journal, |  172       syncer::ModelTypeSet to_journal, | 
|  174       syncer::ModelTypeSet to_unapply, |  173       syncer::ModelTypeSet to_unapply, | 
|  175       syncer::ModelTypeSet to_ignore, |  174       syncer::ModelTypeSet to_ignore, | 
|  176       const syncer::ModelSafeRoutingInfo& routing_info, |  175       const syncer::ModelSafeRoutingInfo& routing_info, | 
|  177       const base::Callback<void(syncer::ModelTypeSet, |  176       const base::Callback<void(syncer::ModelTypeSet, syncer::ModelTypeSet)>& | 
|  178                                 syncer::ModelTypeSet)>& ready_task, |  177           ready_task, | 
|  179       const base::Closure& retry_callback); |  178       const base::Closure& retry_callback); | 
|  180  |  179  | 
|  181   // Called when the syncer has finished performing a configuration. |  180   // Called when the syncer has finished performing a configuration. | 
|  182   void FinishConfigureDataTypesOnFrontendLoop( |  181   void FinishConfigureDataTypesOnFrontendLoop( | 
|  183       const syncer::ModelTypeSet enabled_types, |  182       const syncer::ModelTypeSet enabled_types, | 
|  184       const syncer::ModelTypeSet succeeded_configuration_types, |  183       const syncer::ModelTypeSet succeeded_configuration_types, | 
|  185       const syncer::ModelTypeSet failed_configuration_types, |  184       const syncer::ModelTypeSet failed_configuration_types, | 
|  186       const base::Callback<void(syncer::ModelTypeSet, |  185       const base::Callback<void(syncer::ModelTypeSet, syncer::ModelTypeSet)>& | 
|  187                                 syncer::ModelTypeSet)>& ready_task); |  186           ready_task); | 
|  188  |  187  | 
|  189   // Reports backend initialization success.  Includes some objects from sync |  188   // Reports backend initialization success.  Includes some objects from sync | 
|  190   // manager initialization to be passed back to the UI thread. |  189   // manager initialization to be passed back to the UI thread. | 
|  191   // |  190   // | 
|  192   // |model_type_connector| is our ModelTypeConnector, which is owned because in |  191   // |model_type_connector| is our ModelTypeConnector, which is owned because in | 
|  193   // production it is a proxy object to the real ModelTypeConnector. |  192   // production it is a proxy object to the real ModelTypeConnector. | 
|  194   virtual void HandleInitializationSuccessOnFrontendLoop( |  193   virtual void HandleInitializationSuccessOnFrontendLoop( | 
|  195       const syncer::WeakHandle<syncer::JsBackend> js_backend, |  194       const syncer::WeakHandle<syncer::JsBackend> js_backend, | 
|  196       const syncer::WeakHandle<syncer::DataTypeDebugInfoListener> |  195       const syncer::WeakHandle<syncer::DataTypeDebugInfoListener> | 
|  197           debug_info_listener, |  196           debug_info_listener, | 
| (...skipping 24 matching lines...) Expand all  Loading... | 
|  222   // explicitly requested that we start forwarding these events. |  221   // explicitly requested that we start forwarding these events. | 
|  223   void HandleDirectoryStatusCountersUpdatedOnFrontendLoop( |  222   void HandleDirectoryStatusCountersUpdatedOnFrontendLoop( | 
|  224       syncer::ModelType type, |  223       syncer::ModelType type, | 
|  225       const syncer::StatusCounters& counters); |  224       const syncer::StatusCounters& counters); | 
|  226  |  225  | 
|  227   // Overwrites the kSyncInvalidationVersions preference with the most recent |  226   // Overwrites the kSyncInvalidationVersions preference with the most recent | 
|  228   // set of invalidation versions for each type. |  227   // set of invalidation versions for each type. | 
|  229   void UpdateInvalidationVersions( |  228   void UpdateInvalidationVersions( | 
|  230       const std::map<syncer::ModelType, int64_t>& invalidation_versions); |  229       const std::map<syncer::ModelType, int64_t>& invalidation_versions); | 
|  231  |  230  | 
|  232   sync_driver::SyncFrontend* frontend() { |  231   sync_driver::SyncFrontend* frontend() { return frontend_; } | 
|  233     return frontend_; |  | 
|  234   } |  | 
|  235  |  232  | 
|  236  private: |  233  private: | 
|  237   friend class SyncBackendHostCore; |  234   friend class SyncBackendHostCore; | 
|  238  |  235  | 
|  239   // Checks if we have received a notice to turn on experimental datatypes |  236   // Checks if we have received a notice to turn on experimental datatypes | 
|  240   // (via the nigori node) and informs the frontend if that is the case. |  237   // (via the nigori node) and informs the frontend if that is the case. | 
|  241   // Note: it is illegal to call this before the backend is initialized. |  238   // Note: it is illegal to call this before the backend is initialized. | 
|  242   void AddExperimentalTypes(); |  239   void AddExperimentalTypes(); | 
|  243  |  240  | 
|  244   // Handles backend initialization failure. |  241   // Handles backend initialization failure. | 
|  245   void HandleInitializationFailureOnFrontendLoop(); |  242   void HandleInitializationFailureOnFrontendLoop(); | 
|  246  |  243  | 
|  247   // Called from Core::OnSyncCycleCompleted to handle updating frontend |  244   // Called from Core::OnSyncCycleCompleted to handle updating frontend | 
|  248   // thread components. |  245   // thread components. | 
|  249   void HandleSyncCycleCompletedOnFrontendLoop( |  246   void HandleSyncCycleCompletedOnFrontendLoop( | 
|  250       const syncer::sessions::SyncSessionSnapshot& snapshot); |  247       const syncer::sessions::SyncSessionSnapshot& snapshot); | 
|  251  |  248  | 
|  252   // Called when the syncer failed to perform a configuration and will |  249   // Called when the syncer failed to perform a configuration and will | 
|  253   // eventually retry. FinishingConfigurationOnFrontendLoop(..) will be called |  250   // eventually retry. FinishingConfigurationOnFrontendLoop(..) will be called | 
|  254   // on successful completion. |  251   // on successful completion. | 
|  255   void RetryConfigurationOnFrontendLoop(const base::Closure& retry_callback); |  252   void RetryConfigurationOnFrontendLoop(const base::Closure& retry_callback); | 
|  256  |  253  | 
|  257   // Helpers to persist a token that can be used to bootstrap sync encryption |  254   // Helpers to persist a token that can be used to bootstrap sync encryption | 
|  258   // across browser restart to avoid requiring the user to re-enter their |  255   // across browser restart to avoid requiring the user to re-enter their | 
|  259   // passphrase.  |token| must be valid UTF-8 as we use the PrefService for |  256   // passphrase.  |token| must be valid UTF-8 as we use the PrefService for | 
|  260   // storage. |  257   // storage. | 
|  261   void PersistEncryptionBootstrapToken( |  258   void PersistEncryptionBootstrapToken(const std::string& token, | 
|  262       const std::string& token, |  259                                        syncer::BootstrapTokenType token_type); | 
|  263       syncer::BootstrapTokenType token_type); |  | 
|  264  |  260  | 
|  265   // For convenience, checks if initialization state is INITIALIZED. |  261   // For convenience, checks if initialization state is INITIALIZED. | 
|  266   bool initialized() const { return initialized_; } |  262   bool initialized() const { return initialized_; } | 
|  267  |  263  | 
|  268   // Let the front end handle the actionable error event. |  264   // Let the front end handle the actionable error event. | 
|  269   void HandleActionableErrorEventOnFrontendLoop( |  265   void HandleActionableErrorEventOnFrontendLoop( | 
|  270       const syncer::SyncProtocolError& sync_error); |  266       const syncer::SyncProtocolError& sync_error); | 
|  271  |  267  | 
|  272   // Handle a migration request. |  268   // Handle a migration request. | 
|  273   void HandleMigrationRequestedOnFrontendLoop(const syncer::ModelTypeSet types); |  269   void HandleMigrationRequestedOnFrontendLoop(const syncer::ModelTypeSet types); | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
|  286   // required reason is REASON_ENCRYPTION, an empty EncryptedData object is |  282   // required reason is REASON_ENCRYPTION, an empty EncryptedData object is | 
|  287   // passed. |  283   // passed. | 
|  288   void NotifyPassphraseRequired(syncer::PassphraseRequiredReason reason, |  284   void NotifyPassphraseRequired(syncer::PassphraseRequiredReason reason, | 
|  289                                 sync_pb::EncryptedData pending_keys); |  285                                 sync_pb::EncryptedData pending_keys); | 
|  290  |  286  | 
|  291   // Invoked when the passphrase provided by the user has been accepted. |  287   // Invoked when the passphrase provided by the user has been accepted. | 
|  292   void NotifyPassphraseAccepted(); |  288   void NotifyPassphraseAccepted(); | 
|  293  |  289  | 
|  294   // Invoked when the set of encrypted types or the encrypt |  290   // Invoked when the set of encrypted types or the encrypt | 
|  295   // everything flag changes. |  291   // everything flag changes. | 
|  296   void NotifyEncryptedTypesChanged( |  292   void NotifyEncryptedTypesChanged(syncer::ModelTypeSet encrypted_types, | 
|  297       syncer::ModelTypeSet encrypted_types, |  293                                    bool encrypt_everything); | 
|  298       bool encrypt_everything); |  | 
|  299  |  294  | 
|  300   // Invoked when sync finishes encrypting new datatypes. |  295   // Invoked when sync finishes encrypting new datatypes. | 
|  301   void NotifyEncryptionComplete(); |  296   void NotifyEncryptionComplete(); | 
|  302  |  297  | 
|  303   // Invoked when the passphrase state has changed. Caches the passphrase state |  298   // Invoked when the passphrase state has changed. Caches the passphrase state | 
|  304   // for later use on the UI thread. |  299   // for later use on the UI thread. | 
|  305   // If |type| is FROZEN_IMPLICIT_PASSPHRASE or CUSTOM_PASSPHRASE, |  300   // If |type| is FROZEN_IMPLICIT_PASSPHRASE or CUSTOM_PASSPHRASE, | 
|  306   // |explicit_passphrase_time| is the time at which that passphrase was set |  301   // |explicit_passphrase_time| is the time at which that passphrase was set | 
|  307   // (if available). |  302   // (if available). | 
|  308   void HandlePassphraseTypeChangedOnFrontendLoop( |  303   void HandlePassphraseTypeChangedOnFrontendLoop( | 
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  377   bool invalidation_handler_registered_; |  372   bool invalidation_handler_registered_; | 
|  378  |  373  | 
|  379   base::WeakPtrFactory<SyncBackendHostImpl> weak_ptr_factory_; |  374   base::WeakPtrFactory<SyncBackendHostImpl> weak_ptr_factory_; | 
|  380  |  375  | 
|  381   DISALLOW_COPY_AND_ASSIGN(SyncBackendHostImpl); |  376   DISALLOW_COPY_AND_ASSIGN(SyncBackendHostImpl); | 
|  382 }; |  377 }; | 
|  383  |  378  | 
|  384 }  // namespace browser_sync |  379 }  // namespace browser_sync | 
|  385  |  380  | 
|  386 #endif  // COMPONENTS_SYNC_DRIVER_GLUE_SYNC_BACKEND_HOST_IMPL_H_ |  381 #endif  // COMPONENTS_SYNC_DRIVER_GLUE_SYNC_BACKEND_HOST_IMPL_H_ | 
| OLD | NEW |