| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_SYNC_FRONTEND_H_ | 5 #ifndef COMPONENTS_SYNC_DRIVER_SYNC_FRONTEND_H_ |
| 6 #define COMPONENTS_SYNC_DRIVER_SYNC_FRONTEND_H_ | 6 #define COMPONENTS_SYNC_DRIVER_SYNC_FRONTEND_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "components/sync/base/model_type.h" | 10 #include "components/sync/base/model_type.h" |
| 11 #include "components/sync/base/weak_handle.h" | 11 #include "components/sync/base/weak_handle.h" |
| 12 #include "components/sync/core/sync_encryption_handler.h" | 12 #include "components/sync/core/sync_encryption_handler.h" |
| 13 #include "components/sync/core/sync_manager.h" | 13 #include "components/sync/core/sync_manager.h" |
| 14 #include "components/sync/protocol/sync_protocol_error.h" | 14 #include "components/sync/protocol/sync_protocol_error.h" |
| 15 | 15 |
| 16 namespace sync_pb { | |
| 17 class EncryptedData; | |
| 18 } // namespace sync_pb | |
| 19 | |
| 20 namespace syncer { | 16 namespace syncer { |
| 21 | |
| 22 class DataTypeDebugInfoListener; | 17 class DataTypeDebugInfoListener; |
| 23 class JsBackend; | 18 class JsBackend; |
| 24 class ProtocolEvent; | 19 class ProtocolEvent; |
| 25 struct CommitCounters; | 20 struct CommitCounters; |
| 26 struct StatusCounters; | 21 struct StatusCounters; |
| 27 struct UpdateCounters; | 22 struct UpdateCounters; |
| 23 } // namespace syncer |
| 24 |
| 25 namespace sync_pb { |
| 26 class EncryptedData; |
| 27 } // namespace sync_pb |
| 28 |
| 29 namespace sync_driver { |
| 28 | 30 |
| 29 // SyncFrontend is the interface used by SyncBackendHost to communicate with | 31 // SyncFrontend is the interface used by SyncBackendHost to communicate with |
| 30 // the entity that created it and, presumably, is interested in sync-related | 32 // the entity that created it and, presumably, is interested in sync-related |
| 31 // activity. | 33 // activity. |
| 32 // NOTE: All methods will be invoked by a SyncBackendHost on the same thread | 34 // NOTE: All methods will be invoked by a SyncBackendHost on the same thread |
| 33 // used to create that SyncBackendHost. | 35 // used to create that SyncBackendHost. |
| 34 class SyncFrontend { | 36 class SyncFrontend { |
| 35 public: | 37 public: |
| 36 SyncFrontend(); | 38 SyncFrontend(); |
| 37 virtual ~SyncFrontend(); | 39 virtual ~SyncFrontend(); |
| 38 | 40 |
| 39 // The backend has completed initialization and it is now ready to | 41 // The backend has completed initialization and it is now ready to |
| 40 // accept and process changes. If success is false, initialization | 42 // accept and process changes. If success is false, initialization |
| 41 // wasn't able to be completed and should be retried. | 43 // wasn't able to be completed and should be retried. |
| 42 // | 44 // |
| 43 // |js_backend| is what about:sync interacts with; it's different | 45 // |js_backend| is what about:sync interacts with; it's different |
| 44 // from the 'Backend' in 'OnBackendInitialized' (unfortunately). It | 46 // from the 'Backend' in 'OnBackendInitialized' (unfortunately). It |
| 45 // is initialized only if |success| is true. | 47 // is initialized only if |success| is true. |
| 46 virtual void OnBackendInitialized( | 48 virtual void OnBackendInitialized( |
| 47 const WeakHandle<JsBackend>& js_backend, | 49 const syncer::WeakHandle<syncer::JsBackend>& js_backend, |
| 48 const WeakHandle<DataTypeDebugInfoListener>& debug_info_listener, | 50 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& |
| 51 debug_info_listener, |
| 49 const std::string& cache_guid, | 52 const std::string& cache_guid, |
| 50 bool success) = 0; | 53 bool success) = 0; |
| 51 | 54 |
| 52 // The backend queried the server recently and received some updates. | 55 // The backend queried the server recently and received some updates. |
| 53 virtual void OnSyncCycleCompleted() = 0; | 56 virtual void OnSyncCycleCompleted() = 0; |
| 54 | 57 |
| 55 // Informs the frontned of some network event. These notifications are | 58 // Informs the frontned of some network event. These notifications are |
| 56 // disabled by default and must be enabled through an explicit request to the | 59 // disabled by default and must be enabled through an explicit request to the |
| 57 // SyncBackendHost. | 60 // SyncBackendHost. |
| 58 // | 61 // |
| 59 // It's disabld by default to avoid copying data across threads when no one | 62 // It's disabld by default to avoid copying data across threads when no one |
| 60 // is listening for it. | 63 // is listening for it. |
| 61 virtual void OnProtocolEvent(const ProtocolEvent& event) = 0; | 64 virtual void OnProtocolEvent(const syncer::ProtocolEvent& event) = 0; |
| 62 | 65 |
| 63 // Called when we receive an updated commit counter for a directory type. | 66 // Called when we receive an updated commit counter for a directory type. |
| 64 // | 67 // |
| 65 // Disabled by default. Enable by calling | 68 // Disabled by default. Enable by calling |
| 66 // EnableDirectoryTypeDebugInfoForwarding() on the backend. | 69 // EnableDirectoryTypeDebugInfoForwarding() on the backend. |
| 67 virtual void OnDirectoryTypeCommitCounterUpdated( | 70 virtual void OnDirectoryTypeCommitCounterUpdated( |
| 68 ModelType type, | 71 syncer::ModelType type, |
| 69 const CommitCounters& counters) = 0; | 72 const syncer::CommitCounters& counters) = 0; |
| 70 | 73 |
| 71 // Called when we receive an updated update counter for a directory type. | 74 // Called when we receive an updated update counter for a directory type. |
| 72 // | 75 // |
| 73 // Disabled by default. Enable by calling | 76 // Disabled by default. Enable by calling |
| 74 // EnableDirectoryTypeDebugInfoForwarding() on the backend. | 77 // EnableDirectoryTypeDebugInfoForwarding() on the backend. |
| 75 virtual void OnDirectoryTypeUpdateCounterUpdated( | 78 virtual void OnDirectoryTypeUpdateCounterUpdated( |
| 76 ModelType type, | 79 syncer::ModelType type, |
| 77 const UpdateCounters& counters) = 0; | 80 const syncer::UpdateCounters& counters) = 0; |
| 78 | 81 |
| 79 // Called when we receive an updated status counter for a directory type. | 82 // Called when we receive an updated status counter for a directory type. |
| 80 // | 83 // |
| 81 // Disabled by default. Enable by calling | 84 // Disabled by default. Enable by calling |
| 82 // EnableDirectoryTypeDebugInfoForwarding() on the backend. | 85 // EnableDirectoryTypeDebugInfoForwarding() on the backend. |
| 83 virtual void OnDirectoryTypeStatusCounterUpdated( | 86 virtual void OnDirectoryTypeStatusCounterUpdated( |
| 84 ModelType type, | 87 syncer::ModelType type, |
| 85 const StatusCounters& counters) = 0; | 88 const syncer::StatusCounters& counters) = 0; |
| 86 | 89 |
| 87 // The status of the connection to the sync server has changed. | 90 // The status of the connection to the sync server has changed. |
| 88 virtual void OnConnectionStatusChange(ConnectionStatus status) = 0; | 91 virtual void OnConnectionStatusChange(syncer::ConnectionStatus status) = 0; |
| 89 | 92 |
| 90 // The syncer requires a passphrase to decrypt sensitive updates. This is | 93 // The syncer requires a passphrase to decrypt sensitive updates. This is |
| 91 // called when the first sensitive data type is setup by the user and anytime | 94 // called when the first sensitive data type is setup by the user and anytime |
| 92 // the passphrase is changed by another synced client. |reason| denotes why | 95 // the passphrase is changed by another synced client. |reason| denotes why |
| 93 // the passphrase was required. |pending_keys| is a copy of the | 96 // the passphrase was required. |pending_keys| is a copy of the |
| 94 // cryptographer's pending keys to be passed on to the frontend in order to | 97 // cryptographer's pending keys to be passed on to the frontend in order to |
| 95 // be cached. | 98 // be cached. |
| 96 virtual void OnPassphraseRequired( | 99 virtual void OnPassphraseRequired( |
| 97 PassphraseRequiredReason reason, | 100 syncer::PassphraseRequiredReason reason, |
| 98 const sync_pb::EncryptedData& pending_keys) = 0; | 101 const sync_pb::EncryptedData& pending_keys) = 0; |
| 99 | 102 |
| 100 // Called when the passphrase provided by the user is | 103 // Called when the passphrase provided by the user is |
| 101 // accepted. After this is called, updates to sensitive nodes are | 104 // accepted. After this is called, updates to sensitive nodes are |
| 102 // encrypted using the accepted passphrase. | 105 // encrypted using the accepted passphrase. |
| 103 virtual void OnPassphraseAccepted() = 0; | 106 virtual void OnPassphraseAccepted() = 0; |
| 104 | 107 |
| 105 // Called when the set of encrypted types or the encrypt everything | 108 // Called when the set of encrypted types or the encrypt everything |
| 106 // flag has been changed. Note that encryption isn't complete until | 109 // flag has been changed. Note that encryption isn't complete until |
| 107 // the OnEncryptionComplete() notification has been sent (see | 110 // the OnEncryptionComplete() notification has been sent (see |
| 108 // below). | 111 // below). |
| 109 // | 112 // |
| 110 // |encrypted_types| will always be a superset of | 113 // |encrypted_types| will always be a superset of |
| 111 // Cryptographer::SensitiveTypes(). If |encrypt_everything| is | 114 // syncer::Cryptographer::SensitiveTypes(). If |encrypt_everything| is |
| 112 // true, |encrypted_types| will be the set of all known types. | 115 // true, |encrypted_types| will be the set of all known types. |
| 113 // | 116 // |
| 114 // Until this function is called, observers can assume that the set | 117 // Until this function is called, observers can assume that the set |
| 115 // of encrypted types is Cryptographer::SensitiveTypes() and that | 118 // of encrypted types is syncer::Cryptographer::SensitiveTypes() and that |
| 116 // the encrypt everything flag is false. | 119 // the encrypt everything flag is false. |
| 117 virtual void OnEncryptedTypesChanged(ModelTypeSet encrypted_types, | 120 virtual void OnEncryptedTypesChanged(syncer::ModelTypeSet encrypted_types, |
| 118 bool encrypt_everything) = 0; | 121 bool encrypt_everything) = 0; |
| 119 | 122 |
| 120 // Called after we finish encrypting the current set of encrypted | 123 // Called after we finish encrypting the current set of encrypted |
| 121 // types. | 124 // types. |
| 122 virtual void OnEncryptionComplete() = 0; | 125 virtual void OnEncryptionComplete() = 0; |
| 123 | 126 |
| 124 // Called to perform migration of |types|. | 127 // Called to perform migration of |types|. |
| 125 virtual void OnMigrationNeededForTypes(ModelTypeSet types) = 0; | 128 virtual void OnMigrationNeededForTypes(syncer::ModelTypeSet types) = 0; |
| 126 | 129 |
| 127 // Inform the Frontend that new datatypes are available for registration. | 130 // Inform the Frontend that new datatypes are available for registration. |
| 128 virtual void OnExperimentsChanged(const Experiments& experiments) = 0; | 131 virtual void OnExperimentsChanged(const syncer::Experiments& experiments) = 0; |
| 129 | 132 |
| 130 // Called when the sync cycle returns there is an user actionable error. | 133 // Called when the sync cycle returns there is an user actionable error. |
| 131 virtual void OnActionableError(const SyncProtocolError& error) = 0; | 134 virtual void OnActionableError(const syncer::SyncProtocolError& error) = 0; |
| 132 | 135 |
| 133 // Called when the user of this device enables passphrase encryption. | 136 // Called when the user of this device enables passphrase encryption. |
| 134 // | 137 // |
| 135 // |nigori_state| contains the new (post custom passphrase) encryption keys | 138 // |nigori_state| contains the new (post custom passphrase) encryption keys |
| 136 // and can be used to restore SyncEncryptionHandler's state across sync | 139 // and can be used to restore SyncEncryptionHandler's state across sync |
| 137 // backend instances. See also SyncEncryptionHandlerImpl::RestoreNigori. | 140 // backend instances. See also SyncEncryptionHandlerImpl::RestoreNigori. |
| 138 virtual void OnLocalSetPassphraseEncryption( | 141 virtual void OnLocalSetPassphraseEncryption( |
| 139 const SyncEncryptionHandler::NigoriState& nigori_state) = 0; | 142 const syncer::SyncEncryptionHandler::NigoriState& nigori_state) = 0; |
| 140 }; | 143 }; |
| 141 | 144 |
| 142 } // namespace syncer | 145 } // namespace sync_driver |
| 143 | 146 |
| 144 #endif // COMPONENTS_SYNC_DRIVER_SYNC_FRONTEND_H_ | 147 #endif // COMPONENTS_SYNC_DRIVER_SYNC_FRONTEND_H_ |
| OLD | NEW |