OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 COMPONENTS_SYNC_CORE_SYNC_MANAGER_H_ | 5 #ifndef COMPONENTS_SYNC_CORE_SYNC_MANAGER_H_ |
6 #define COMPONENTS_SYNC_CORE_SYNC_MANAGER_H_ | 6 #define COMPONENTS_SYNC_CORE_SYNC_MANAGER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/callback.h" | 14 #include "base/callback.h" |
15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/memory/scoped_vector.h" | 17 #include "base/memory/scoped_vector.h" |
18 #include "base/task_runner.h" | 18 #include "base/task_runner.h" |
19 #include "base/threading/thread_checker.h" | 19 #include "base/threading/thread_checker.h" |
20 #include "components/sync/base/invalidation_interface.h" | 20 #include "components/sync/base/invalidation_interface.h" |
21 #include "components/sync/base/model_type.h" | 21 #include "components/sync/base/model_type.h" |
22 #include "components/sync/base/sync_export.h" | |
23 #include "components/sync/base/weak_handle.h" | 22 #include "components/sync/base/weak_handle.h" |
24 #include "components/sync/core/change_record.h" | 23 #include "components/sync/core/change_record.h" |
25 #include "components/sync/core/configure_reason.h" | 24 #include "components/sync/core/configure_reason.h" |
26 #include "components/sync/core/connection_status.h" | 25 #include "components/sync/core/connection_status.h" |
27 #include "components/sync/core/http_post_provider_factory.h" | 26 #include "components/sync/core/http_post_provider_factory.h" |
28 #include "components/sync/core/internal_components_factory.h" | 27 #include "components/sync/core/internal_components_factory.h" |
29 #include "components/sync/core/model_type_connector.h" | 28 #include "components/sync/core/model_type_connector.h" |
30 #include "components/sync/core/shutdown_reason.h" | 29 #include "components/sync/core/shutdown_reason.h" |
31 #include "components/sync/core/sync_encryption_handler.h" | 30 #include "components/sync/core/sync_encryption_handler.h" |
32 #include "components/sync/engine/events/protocol_event.h" | 31 #include "components/sync/engine/events/protocol_event.h" |
(...skipping 24 matching lines...) Expand all Loading... |
57 class TypeDebugInfoObserver; | 56 class TypeDebugInfoObserver; |
58 class UnrecoverableErrorHandler; | 57 class UnrecoverableErrorHandler; |
59 struct Experiments; | 58 struct Experiments; |
60 struct UserShare; | 59 struct UserShare; |
61 | 60 |
62 namespace sessions { | 61 namespace sessions { |
63 class SyncSessionSnapshot; | 62 class SyncSessionSnapshot; |
64 } // namespace sessions | 63 } // namespace sessions |
65 | 64 |
66 // Contains everything needed to talk to and identify a user account. | 65 // Contains everything needed to talk to and identify a user account. |
67 struct SYNC_EXPORT SyncCredentials { | 66 struct SyncCredentials { |
68 SyncCredentials(); | 67 SyncCredentials(); |
69 SyncCredentials(const SyncCredentials& other); | 68 SyncCredentials(const SyncCredentials& other); |
70 ~SyncCredentials(); | 69 ~SyncCredentials(); |
71 | 70 |
72 // Account_id of signed in account. | 71 // Account_id of signed in account. |
73 std::string account_id; | 72 std::string account_id; |
74 | 73 |
75 // The email associated with this account. | 74 // The email associated with this account. |
76 std::string email; | 75 std::string email; |
77 | 76 |
78 // The raw authentication token's bytes. | 77 // The raw authentication token's bytes. |
79 std::string sync_token; | 78 std::string sync_token; |
80 | 79 |
81 // The set of scopes to use when talking to sync server. | 80 // The set of scopes to use when talking to sync server. |
82 OAuth2TokenService::ScopeSet scope_set; | 81 OAuth2TokenService::ScopeSet scope_set; |
83 }; | 82 }; |
84 | 83 |
85 // SyncManager encapsulates syncable::Directory and serves as the parent of all | 84 // SyncManager encapsulates syncable::Directory and serves as the parent of all |
86 // other objects in the sync API. If multiple threads interact with the same | 85 // other objects in the sync API. If multiple threads interact with the same |
87 // local sync repository (i.e. the same sqlite database), they should share a | 86 // local sync repository (i.e. the same sqlite database), they should share a |
88 // single SyncManager instance. The caller should typically create one | 87 // single SyncManager instance. The caller should typically create one |
89 // SyncManager for the lifetime of a user session. | 88 // SyncManager for the lifetime of a user session. |
90 // | 89 // |
91 // Unless stated otherwise, all methods of SyncManager should be called on the | 90 // Unless stated otherwise, all methods of SyncManager should be called on the |
92 // same thread. | 91 // same thread. |
93 class SYNC_EXPORT SyncManager { | 92 class SyncManager { |
94 public: | 93 public: |
95 // An interface the embedding application implements to be notified | 94 // An interface the embedding application implements to be notified |
96 // on change events. Note that these methods may be called on *any* | 95 // on change events. Note that these methods may be called on *any* |
97 // thread. | 96 // thread. |
98 class SYNC_EXPORT ChangeDelegate { | 97 class ChangeDelegate { |
99 public: | 98 public: |
100 // Notify the delegate that changes have been applied to the sync model. | 99 // Notify the delegate that changes have been applied to the sync model. |
101 // | 100 // |
102 // This will be invoked on the same thread as on which ApplyChanges was | 101 // This will be invoked on the same thread as on which ApplyChanges was |
103 // called. |changes| is an array of size |change_count|, and contains the | 102 // called. |changes| is an array of size |change_count|, and contains the |
104 // ID of each individual item that was changed. |changes| exists only for | 103 // ID of each individual item that was changed. |changes| exists only for |
105 // the duration of the call. If items of multiple data types change at | 104 // the duration of the call. If items of multiple data types change at |
106 // the same time, this method is invoked once per data type and |changes| | 105 // the same time, this method is invoked once per data type and |changes| |
107 // is restricted to items of the ModelType indicated by |model_type|. | 106 // is restricted to items of the ModelType indicated by |model_type|. |
108 // Because the observer is passed a |trans|, the observer can assume a | 107 // Because the observer is passed a |trans|, the observer can assume a |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 // I/O to when it no longer holds any lock). | 139 // I/O to when it no longer holds any lock). |
141 virtual void OnChangesComplete(ModelType model_type) = 0; | 140 virtual void OnChangesComplete(ModelType model_type) = 0; |
142 | 141 |
143 protected: | 142 protected: |
144 virtual ~ChangeDelegate(); | 143 virtual ~ChangeDelegate(); |
145 }; | 144 }; |
146 | 145 |
147 // Like ChangeDelegate, except called only on the sync thread and | 146 // Like ChangeDelegate, except called only on the sync thread and |
148 // not while a transaction is held. For objects that want to know | 147 // not while a transaction is held. For objects that want to know |
149 // when changes happen, but don't need to process them. | 148 // when changes happen, but don't need to process them. |
150 class SYNC_EXPORT ChangeObserver { | 149 class ChangeObserver { |
151 public: | 150 public: |
152 // Ids referred to in |changes| may or may not be in the write | 151 // Ids referred to in |changes| may or may not be in the write |
153 // transaction specified by |write_transaction_id|. If they're | 152 // transaction specified by |write_transaction_id|. If they're |
154 // not, that means that the node didn't actually change, but we | 153 // not, that means that the node didn't actually change, but we |
155 // marked them as changed for some other reason (e.g., siblings of | 154 // marked them as changed for some other reason (e.g., siblings of |
156 // re-ordered nodes). | 155 // re-ordered nodes). |
157 // | 156 // |
158 // TODO(sync, long-term): Ideally, ChangeDelegate/Observer would | 157 // TODO(sync, long-term): Ideally, ChangeDelegate/Observer would |
159 // be passed a transformed version of EntryKernelMutation instead | 158 // be passed a transformed version of EntryKernelMutation instead |
160 // of a transaction that would have to be used to look up the | 159 // of a transaction that would have to be used to look up the |
(...skipping 11 matching lines...) Expand all Loading... |
172 virtual void OnChangesComplete(ModelType model_type) = 0; | 171 virtual void OnChangesComplete(ModelType model_type) = 0; |
173 | 172 |
174 protected: | 173 protected: |
175 virtual ~ChangeObserver(); | 174 virtual ~ChangeObserver(); |
176 }; | 175 }; |
177 | 176 |
178 // An interface the embedding application implements to receive | 177 // An interface the embedding application implements to receive |
179 // notifications from the SyncManager. Register an observer via | 178 // notifications from the SyncManager. Register an observer via |
180 // SyncManager::AddObserver. All methods are called only on the | 179 // SyncManager::AddObserver. All methods are called only on the |
181 // sync thread. | 180 // sync thread. |
182 class SYNC_EXPORT Observer { | 181 class Observer { |
183 public: | 182 public: |
184 // A round-trip sync-cycle took place and the syncer has resolved any | 183 // A round-trip sync-cycle took place and the syncer has resolved any |
185 // conflicts that may have arisen. | 184 // conflicts that may have arisen. |
186 virtual void OnSyncCycleCompleted( | 185 virtual void OnSyncCycleCompleted( |
187 const sessions::SyncSessionSnapshot& snapshot) = 0; | 186 const sessions::SyncSessionSnapshot& snapshot) = 0; |
188 | 187 |
189 // Called when the status of the connection to the sync server has | 188 // Called when the status of the connection to the sync server has |
190 // changed. | 189 // changed. |
191 virtual void OnConnectionStatusChange(ConnectionStatus status) = 0; | 190 virtual void OnConnectionStatusChange(ConnectionStatus status) = 0; |
192 | 191 |
(...skipping 16 matching lines...) Expand all Loading... |
209 | 208 |
210 virtual void OnMigrationRequested(ModelTypeSet types) = 0; | 209 virtual void OnMigrationRequested(ModelTypeSet types) = 0; |
211 | 210 |
212 virtual void OnProtocolEvent(const ProtocolEvent& event) = 0; | 211 virtual void OnProtocolEvent(const ProtocolEvent& event) = 0; |
213 | 212 |
214 protected: | 213 protected: |
215 virtual ~Observer(); | 214 virtual ~Observer(); |
216 }; | 215 }; |
217 | 216 |
218 // Arguments for initializing SyncManager. | 217 // Arguments for initializing SyncManager. |
219 struct SYNC_EXPORT InitArgs { | 218 struct InitArgs { |
220 InitArgs(); | 219 InitArgs(); |
221 ~InitArgs(); | 220 ~InitArgs(); |
222 | 221 |
223 // Path in which to create or open sync's sqlite database (aka the | 222 // Path in which to create or open sync's sqlite database (aka the |
224 // directory). | 223 // directory). |
225 base::FilePath database_location; | 224 base::FilePath database_location; |
226 | 225 |
227 // Used to propagate events to chrome://sync-internals. Optional. | 226 // Used to propagate events to chrome://sync-internals. Optional. |
228 WeakHandle<JsEventHandler> event_handler; | 227 WeakHandle<JsEventHandler> event_handler; |
229 | 228 |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 | 401 |
403 // Updates Sync's tracking of whether the cookie jar has a mismatch with the | 402 // Updates Sync's tracking of whether the cookie jar has a mismatch with the |
404 // chrome account. See ClientConfigParams proto message for more info. | 403 // chrome account. See ClientConfigParams proto message for more info. |
405 // Note: this does not trigger a sync cycle. It just updates the sync context. | 404 // Note: this does not trigger a sync cycle. It just updates the sync context. |
406 virtual void OnCookieJarChanged(bool account_mismatch, bool empty_jar) = 0; | 405 virtual void OnCookieJarChanged(bool account_mismatch, bool empty_jar) = 0; |
407 }; | 406 }; |
408 | 407 |
409 } // namespace syncer | 408 } // namespace syncer |
410 | 409 |
411 #endif // COMPONENTS_SYNC_CORE_SYNC_MANAGER_H_ | 410 #endif // COMPONENTS_SYNC_CORE_SYNC_MANAGER_H_ |
OLD | NEW |