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