OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ | 5 #ifndef CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ |
6 #define CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ | 6 #define CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
(...skipping 10 matching lines...) Expand all Loading... |
22 #include "chrome/browser/sync/engine/model_safe_worker.h" | 22 #include "chrome/browser/sync/engine/model_safe_worker.h" |
23 #include "chrome/browser/sync/glue/data_type_controller.h" | 23 #include "chrome/browser/sync/glue/data_type_controller.h" |
24 #include "chrome/browser/sync/glue/ui_model_worker.h" | 24 #include "chrome/browser/sync/glue/ui_model_worker.h" |
25 #include "chrome/browser/sync/syncable/model_type.h" | 25 #include "chrome/browser/sync/syncable/model_type.h" |
26 #include "chrome/common/net/url_request_context_getter.h" | 26 #include "chrome/common/net/url_request_context_getter.h" |
27 #include "googleurl/src/gurl.h" | 27 #include "googleurl/src/gurl.h" |
28 | 28 |
29 class CancelableTask; | 29 class CancelableTask; |
30 class Profile; | 30 class Profile; |
31 | 31 |
32 namespace chrome_common_net { | |
33 class NetworkChangeNotifierThread; | |
34 } | |
35 | |
36 namespace browser_sync { | 32 namespace browser_sync { |
37 | 33 |
38 namespace sessions { | 34 namespace sessions { |
39 struct SyncSessionSnapshot; | 35 struct SyncSessionSnapshot; |
40 } | 36 } |
41 | 37 |
42 class ChangeProcessor; | 38 class ChangeProcessor; |
43 class DataTypeController; | 39 class DataTypeController; |
44 | 40 |
45 // SyncFrontend is the interface used by SyncBackendHost to communicate with | 41 // SyncFrontend is the interface used by SyncBackendHost to communicate with |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 // TODO(skrul): Extract an interface so this is not needed. | 89 // TODO(skrul): Extract an interface so this is not needed. |
94 SyncBackendHost(); | 90 SyncBackendHost(); |
95 ~SyncBackendHost(); | 91 ~SyncBackendHost(); |
96 | 92 |
97 // Called on |frontend_loop_| to kick off asynchronous initialization. | 93 // Called on |frontend_loop_| to kick off asynchronous initialization. |
98 // As a fallback when no cached auth information is available, try to | 94 // As a fallback when no cached auth information is available, try to |
99 // bootstrap authentication using |lsid|, if it isn't empty. | 95 // bootstrap authentication using |lsid|, if it isn't empty. |
100 // Optionally delete the Sync Data folder (if it's corrupt). | 96 // Optionally delete the Sync Data folder (if it's corrupt). |
101 void Initialize(const GURL& service_url, | 97 void Initialize(const GURL& service_url, |
102 const syncable::ModelTypeSet& types, | 98 const syncable::ModelTypeSet& types, |
103 chrome_common_net::NetworkChangeNotifierThread* | |
104 network_change_notifier_thread, | |
105 URLRequestContextGetter* baseline_context_getter, | 99 URLRequestContextGetter* baseline_context_getter, |
106 const std::string& lsid, | 100 const std::string& lsid, |
107 bool delete_sync_data_folder, | 101 bool delete_sync_data_folder, |
108 bool invalidate_sync_login, | 102 bool invalidate_sync_login, |
109 bool invalidate_sync_xmpp_login, | 103 bool invalidate_sync_xmpp_login, |
110 NotificationMethod notification_method); | 104 NotificationMethod notification_method); |
111 | 105 |
112 // Called on |frontend_loop_| to kick off asynchronous authentication. | 106 // Called on |frontend_loop_| to kick off asynchronous authentication. |
113 void Authenticate(const std::string& username, const std::string& password, | 107 void Authenticate(const std::string& username, const std::string& password, |
114 const std::string& captcha); | 108 const std::string& captcha); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 string16 GetAuthenticatedUsername() const; | 167 string16 GetAuthenticatedUsername() const; |
174 | 168 |
175 // ModelSafeWorkerRegistrar implementation. | 169 // ModelSafeWorkerRegistrar implementation. |
176 virtual void GetWorkers(std::vector<browser_sync::ModelSafeWorker*>* out); | 170 virtual void GetWorkers(std::vector<browser_sync::ModelSafeWorker*>* out); |
177 virtual void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out); | 171 virtual void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out); |
178 | 172 |
179 #if defined(UNIT_TEST) | 173 #if defined(UNIT_TEST) |
180 // Called from unit test to bypass authentication and initialize the syncapi | 174 // Called from unit test to bypass authentication and initialize the syncapi |
181 // to a state suitable for testing but not production. | 175 // to a state suitable for testing but not production. |
182 void InitializeForTestMode(const std::wstring& test_user, | 176 void InitializeForTestMode(const std::wstring& test_user, |
183 chrome_common_net::NetworkChangeNotifierThread* | |
184 network_change_notifier_thread, | |
185 sync_api::HttpPostProviderFactory* factory, | 177 sync_api::HttpPostProviderFactory* factory, |
186 sync_api::HttpPostProviderFactory* auth_factory, | 178 sync_api::HttpPostProviderFactory* auth_factory, |
187 bool delete_sync_data_folder, | 179 bool delete_sync_data_folder, |
188 NotificationMethod notification_method) { | 180 NotificationMethod notification_method) { |
189 if (!core_thread_.Start()) | 181 if (!core_thread_.Start()) |
190 return; | 182 return; |
191 registrar_.workers[GROUP_UI] = new UIModelWorker(frontend_loop_); | 183 registrar_.workers[GROUP_UI] = new UIModelWorker(frontend_loop_); |
192 registrar_.routing_info[syncable::BOOKMARKS] = GROUP_PASSIVE; | 184 registrar_.routing_info[syncable::BOOKMARKS] = GROUP_PASSIVE; |
193 registrar_.routing_info[syncable::PREFERENCES] = GROUP_PASSIVE; | 185 registrar_.routing_info[syncable::PREFERENCES] = GROUP_PASSIVE; |
194 registrar_.routing_info[syncable::AUTOFILL] = GROUP_PASSIVE; | 186 registrar_.routing_info[syncable::AUTOFILL] = GROUP_PASSIVE; |
195 registrar_.routing_info[syncable::THEMES] = GROUP_PASSIVE; | 187 registrar_.routing_info[syncable::THEMES] = GROUP_PASSIVE; |
196 registrar_.routing_info[syncable::TYPED_URLS] = GROUP_PASSIVE; | 188 registrar_.routing_info[syncable::TYPED_URLS] = GROUP_PASSIVE; |
197 registrar_.routing_info[syncable::NIGORI] = GROUP_PASSIVE; | 189 registrar_.routing_info[syncable::NIGORI] = GROUP_PASSIVE; |
198 registrar_.routing_info[syncable::PASSWORDS] = GROUP_PASSIVE; | 190 registrar_.routing_info[syncable::PASSWORDS] = GROUP_PASSIVE; |
199 | 191 |
200 core_thread_.message_loop()->PostTask(FROM_HERE, | 192 core_thread_.message_loop()->PostTask(FROM_HERE, |
201 NewRunnableMethod(core_.get(), | 193 NewRunnableMethod(core_.get(), |
202 &SyncBackendHost::Core::DoInitializeForTest, | 194 &SyncBackendHost::Core::DoInitializeForTest, |
203 test_user, | 195 test_user, |
204 network_change_notifier_thread, | |
205 factory, | 196 factory, |
206 auth_factory, | 197 auth_factory, |
207 delete_sync_data_folder, | 198 delete_sync_data_folder, |
208 notification_method)); | 199 notification_method)); |
209 } | 200 } |
210 #endif | 201 #endif |
211 | 202 |
212 private: | 203 private: |
213 // The real guts of SyncBackendHost, to keep the public client API clean. | 204 // The real guts of SyncBackendHost, to keep the public client API clean. |
214 class Core : public base::RefCountedThreadSafe<SyncBackendHost::Core>, | 205 class Core : public base::RefCountedThreadSafe<SyncBackendHost::Core>, |
(...skipping 15 matching lines...) Expand all Loading... |
230 virtual void OnAuthError(const GoogleServiceAuthError& auth_error); | 221 virtual void OnAuthError(const GoogleServiceAuthError& auth_error); |
231 virtual void OnPassphraseRequired(); | 222 virtual void OnPassphraseRequired(); |
232 virtual void OnPassphraseAccepted(); | 223 virtual void OnPassphraseAccepted(); |
233 virtual void OnPaused(); | 224 virtual void OnPaused(); |
234 virtual void OnResumed(); | 225 virtual void OnResumed(); |
235 | 226 |
236 struct DoInitializeOptions { | 227 struct DoInitializeOptions { |
237 DoInitializeOptions( | 228 DoInitializeOptions( |
238 const GURL& service_url, | 229 const GURL& service_url, |
239 bool attempt_last_user_authentication, | 230 bool attempt_last_user_authentication, |
240 chrome_common_net::NetworkChangeNotifierThread* | |
241 network_change_notifier_thread, | |
242 sync_api::HttpPostProviderFactory* http_bridge_factory, | 231 sync_api::HttpPostProviderFactory* http_bridge_factory, |
243 sync_api::HttpPostProviderFactory* auth_http_bridge_factory, | 232 sync_api::HttpPostProviderFactory* auth_http_bridge_factory, |
244 const std::string& lsid, | 233 const std::string& lsid, |
245 bool delete_sync_data_folder, | 234 bool delete_sync_data_folder, |
246 bool invalidate_sync_login, | 235 bool invalidate_sync_login, |
247 bool invalidate_sync_xmpp_login, | 236 bool invalidate_sync_xmpp_login, |
248 NotificationMethod notification_method) | 237 NotificationMethod notification_method) |
249 : service_url(service_url), | 238 : service_url(service_url), |
250 attempt_last_user_authentication(attempt_last_user_authentication), | 239 attempt_last_user_authentication(attempt_last_user_authentication), |
251 network_change_notifier_thread(network_change_notifier_thread), | |
252 http_bridge_factory(http_bridge_factory), | 240 http_bridge_factory(http_bridge_factory), |
253 auth_http_bridge_factory(auth_http_bridge_factory), | 241 auth_http_bridge_factory(auth_http_bridge_factory), |
254 lsid(lsid), | 242 lsid(lsid), |
255 delete_sync_data_folder(delete_sync_data_folder), | 243 delete_sync_data_folder(delete_sync_data_folder), |
256 invalidate_sync_login(invalidate_sync_login), | 244 invalidate_sync_login(invalidate_sync_login), |
257 invalidate_sync_xmpp_login(invalidate_sync_xmpp_login), | 245 invalidate_sync_xmpp_login(invalidate_sync_xmpp_login), |
258 notification_method(notification_method) {} | 246 notification_method(notification_method) {} |
259 | 247 |
260 GURL service_url; | 248 GURL service_url; |
261 bool attempt_last_user_authentication; | 249 bool attempt_last_user_authentication; |
262 chrome_common_net::NetworkChangeNotifierThread* | |
263 network_change_notifier_thread; | |
264 sync_api::HttpPostProviderFactory* http_bridge_factory; | 250 sync_api::HttpPostProviderFactory* http_bridge_factory; |
265 sync_api::HttpPostProviderFactory* auth_http_bridge_factory; | 251 sync_api::HttpPostProviderFactory* auth_http_bridge_factory; |
266 std::string lsid; | 252 std::string lsid; |
267 bool delete_sync_data_folder; | 253 bool delete_sync_data_folder; |
268 bool invalidate_sync_login; | 254 bool invalidate_sync_login; |
269 bool invalidate_sync_xmpp_login; | 255 bool invalidate_sync_xmpp_login; |
270 NotificationMethod notification_method; | 256 NotificationMethod notification_method; |
271 }; | 257 }; |
272 | 258 |
273 // Note: | 259 // Note: |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 // Delete the sync data folder to cleanup backend data. Happens the first | 300 // Delete the sync data folder to cleanup backend data. Happens the first |
315 // time sync is enabled for a user (to prevent accidentally reusing old | 301 // time sync is enabled for a user (to prevent accidentally reusing old |
316 // sync databases), as well as shutdown when you're no longer syncing. | 302 // sync databases), as well as shutdown when you're no longer syncing. |
317 void DeleteSyncDataFolder(); | 303 void DeleteSyncDataFolder(); |
318 | 304 |
319 #if defined(UNIT_TEST) | 305 #if defined(UNIT_TEST) |
320 // Special form of initialization that does not try and authenticate the | 306 // Special form of initialization that does not try and authenticate the |
321 // last known user (since it will fail in test mode) and does some extra | 307 // last known user (since it will fail in test mode) and does some extra |
322 // setup to nudge the syncapi into a useable state. | 308 // setup to nudge the syncapi into a useable state. |
323 void DoInitializeForTest(const std::wstring& test_user, | 309 void DoInitializeForTest(const std::wstring& test_user, |
324 chrome_common_net::NetworkChangeNotifierThread* | |
325 network_change_notifier_thread, | |
326 sync_api::HttpPostProviderFactory* factory, | 310 sync_api::HttpPostProviderFactory* factory, |
327 sync_api::HttpPostProviderFactory* auth_factory, | 311 sync_api::HttpPostProviderFactory* auth_factory, |
328 bool delete_sync_data_folder, | 312 bool delete_sync_data_folder, |
329 NotificationMethod notification_method) { | 313 NotificationMethod notification_method) { |
330 DoInitialize( | 314 DoInitialize(DoInitializeOptions(GURL(), false, factory, auth_factory, |
331 DoInitializeOptions(GURL(), false, | 315 std::string(), delete_sync_data_folder, |
332 network_change_notifier_thread, | 316 false, false, notification_method)); |
333 factory, auth_factory, | |
334 std::string(), delete_sync_data_folder, | |
335 false, false, | |
336 notification_method)); | |
337 syncapi_->SetupForTestMode(test_user); | 317 syncapi_->SetupForTestMode(test_user); |
338 } | 318 } |
339 #endif | 319 #endif |
340 | 320 |
341 private: | 321 private: |
342 friend class base::RefCountedThreadSafe<SyncBackendHost::Core>; | 322 friend class base::RefCountedThreadSafe<SyncBackendHost::Core>; |
343 | 323 |
344 ~Core() {} | 324 ~Core() {} |
345 | 325 |
346 // Sends a SYNC_PAUSED notification to the notification service on | 326 // Sends a SYNC_PAUSED notification to the notification service on |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 | 447 |
468 // UI-thread cache of the last SyncSessionSnapshot received from syncapi. | 448 // UI-thread cache of the last SyncSessionSnapshot received from syncapi. |
469 scoped_ptr<sessions::SyncSessionSnapshot> last_snapshot_; | 449 scoped_ptr<sessions::SyncSessionSnapshot> last_snapshot_; |
470 | 450 |
471 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); | 451 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); |
472 }; | 452 }; |
473 | 453 |
474 } // namespace browser_sync | 454 } // namespace browser_sync |
475 | 455 |
476 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ | 456 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ |
OLD | NEW |