Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / components / sync_driver / sync_frontend.h
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
15 namespace syncer {
16 class DataTypeDebugInfoListener;
17 class JsBackend;
18 class ProtocolEvent;
19 struct CommitCounters;
20 struct StatusCounters;
21 struct UpdateCounters;
22 }  // namespace syncer
23
24 namespace sync_pb {
25 class EncryptedData;
26 }  // namespace sync_pb
27
28 namespace 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.
35 class 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   // Informs the frontned of some network event.  These notifications are
58   // disabled by default and must be enabled through an explicit request to the
59   // SyncBackendHost.
60   //
61   // It's disabld by default to avoid copying data across threads when no one
62   // is listening for it.
63   virtual void OnProtocolEvent(const syncer::ProtocolEvent& event) = 0;
64
65   // Called when we receive an updated commit counter for a directory type.
66   //
67   // Disabled by default.  Enable by calling
68   // EnableDirectoryTypeDebugInfoForwarding() on the backend.
69   virtual void OnDirectoryTypeCommitCounterUpdated(
70       syncer::ModelType type,
71       const syncer::CommitCounters& counters) = 0;
72
73   // Called when we receive an updated update counter for a directory type.
74   //
75   // Disabled by default.  Enable by calling
76   // EnableDirectoryTypeDebugInfoForwarding() on the backend.
77   virtual void OnDirectoryTypeUpdateCounterUpdated(
78       syncer::ModelType type,
79       const syncer::UpdateCounters& counters) = 0;
80
81   // Called when we receive an updated status counter for a directory type.
82   //
83   // Disabled by default.  Enable by calling
84   // EnableDirectoryTypeDebugInfoForwarding() on the backend.
85   virtual void OnDirectoryTypeStatusCounterUpdated(
86       syncer::ModelType type,
87       const syncer::StatusCounters& counters) = 0;
88
89   // The status of the connection to the sync server has changed.
90   virtual void OnConnectionStatusChange(
91       syncer::ConnectionStatus status) = 0;
92
93   // The syncer requires a passphrase to decrypt sensitive updates. This is
94   // called when the first sensitive data type is setup by the user and anytime
95   // the passphrase is changed by another synced client. |reason| denotes why
96   // the passphrase was required. |pending_keys| is a copy of the
97   // cryptographer's pending keys to be passed on to the frontend in order to
98   // be cached.
99   virtual void OnPassphraseRequired(
100       syncer::PassphraseRequiredReason reason,
101       const sync_pb::EncryptedData& pending_keys) = 0;
102
103   // Called when the passphrase provided by the user is
104   // accepted. After this is called, updates to sensitive nodes are
105   // encrypted using the accepted passphrase.
106   virtual void OnPassphraseAccepted() = 0;
107
108   // Called when the set of encrypted types or the encrypt everything
109   // flag has been changed.  Note that encryption isn't complete until
110   // the OnEncryptionComplete() notification has been sent (see
111   // below).
112   //
113   // |encrypted_types| will always be a superset of
114   // syncer::Cryptographer::SensitiveTypes().  If |encrypt_everything| is
115   // true, |encrypted_types| will be the set of all known types.
116   //
117   // Until this function is called, observers can assume that the set
118   // of encrypted types is syncer::Cryptographer::SensitiveTypes() and that
119   // the encrypt everything flag is false.
120   virtual void OnEncryptedTypesChanged(
121       syncer::ModelTypeSet encrypted_types,
122       bool encrypt_everything) = 0;
123
124   // Called after we finish encrypting the current set of encrypted
125   // types.
126   virtual void OnEncryptionComplete() = 0;
127
128   // Called to perform migration of |types|.
129   virtual void OnMigrationNeededForTypes(syncer::ModelTypeSet types) = 0;
130
131   // Inform the Frontend that new datatypes are available for registration.
132   virtual void OnExperimentsChanged(
133       const syncer::Experiments& experiments) = 0;
134
135   // Called when the sync cycle returns there is an user actionable error.
136   virtual void OnActionableError(const syncer::SyncProtocolError& error) = 0;
137 };
138
139 }  // namespace sync_driver
140
141 #endif  // COMPONENTS_SYNC_DRIVER_SYNC_FRONTEND_H_