| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 // Returns the authenticated username of the sync user, or empty if none | 217 // Returns the authenticated username of the sync user, or empty if none |
| 218 // exists. It will only exist if the authentication service provider (e.g | 218 // exists. It will only exist if the authentication service provider (e.g |
| 219 // GAIA) has confirmed the username is authentic. | 219 // GAIA) has confirmed the username is authentic. |
| 220 string16 GetAuthenticatedUsername() const; | 220 string16 GetAuthenticatedUsername() const; |
| 221 | 221 |
| 222 // Determines if the underlying sync engine has made any local changes to | 222 // Determines if the underlying sync engine has made any local changes to |
| 223 // items that have not yet been synced with the server. | 223 // items that have not yet been synced with the server. |
| 224 // ONLY CALL THIS IF OnInitializationComplete was called! | 224 // ONLY CALL THIS IF OnInitializationComplete was called! |
| 225 bool HasUnsyncedItems() const; | 225 bool HasUnsyncedItems() const; |
| 226 | 226 |
| 227 // Logs the unsynced items. | |
| 228 void LogUnsyncedItems(int level) const; | |
| 229 | |
| 230 // Whether or not we are syncing encryption keys. | 227 // Whether or not we are syncing encryption keys. |
| 231 bool IsNigoriEnabled() const; | 228 bool IsNigoriEnabled() const; |
| 232 | 229 |
| 233 // Whether or not the Nigori node is encrypted using an explicit passphrase. | 230 // Whether or not the Nigori node is encrypted using an explicit passphrase. |
| 234 bool IsUsingExplicitPassphrase(); | 231 bool IsUsingExplicitPassphrase(); |
| 235 | 232 |
| 236 // True if the cryptographer has any keys available to attempt decryption. | 233 // True if the cryptographer has any keys available to attempt decryption. |
| 237 // Could mean we've downloaded and loaded Nigori objects, or we bootstrapped | 234 // Could mean we've downloaded and loaded Nigori objects, or we bootstrapped |
| 238 // using a token previously received. | 235 // using a token previously received. |
| 239 bool IsCryptographerReady(const sync_api::BaseTransaction* trans) const; | 236 bool IsCryptographerReady(const sync_api::BaseTransaction* trans) const; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 252 | 249 |
| 253 // The real guts of SyncBackendHost, to keep the public client API clean. | 250 // The real guts of SyncBackendHost, to keep the public client API clean. |
| 254 class Core : public base::RefCountedThreadSafe<SyncBackendHost::Core>, | 251 class Core : public base::RefCountedThreadSafe<SyncBackendHost::Core>, |
| 255 public sync_api::SyncManager::Observer { | 252 public sync_api::SyncManager::Observer { |
| 256 public: | 253 public: |
| 257 Core(const std::string& name, SyncBackendHost* backend); | 254 Core(const std::string& name, SyncBackendHost* backend); |
| 258 | 255 |
| 259 // SyncManager::Observer implementation. The Core just acts like an air | 256 // SyncManager::Observer implementation. The Core just acts like an air |
| 260 // traffic controller here, forwarding incoming messages to appropriate | 257 // traffic controller here, forwarding incoming messages to appropriate |
| 261 // landing threads. | 258 // landing threads. |
| 262 virtual void OnChangesApplied( | |
| 263 syncable::ModelType model_type, | |
| 264 const sync_api::BaseTransaction* trans, | |
| 265 const sync_api::ImmutableChangeRecordList& changes) OVERRIDE; | |
| 266 virtual void OnChangesComplete( | |
| 267 syncable::ModelType model_type) OVERRIDE; | |
| 268 virtual void OnSyncCycleCompleted( | 259 virtual void OnSyncCycleCompleted( |
| 269 const sessions::SyncSessionSnapshot* snapshot) OVERRIDE; | 260 const sessions::SyncSessionSnapshot* snapshot) OVERRIDE; |
| 270 virtual void OnInitializationComplete( | 261 virtual void OnInitializationComplete( |
| 271 const WeakHandle<JsBackend>& js_backend, | 262 const WeakHandle<JsBackend>& js_backend, |
| 272 bool success) OVERRIDE; | 263 bool success) OVERRIDE; |
| 273 virtual void OnAuthError( | 264 virtual void OnAuthError( |
| 274 const GoogleServiceAuthError& auth_error) OVERRIDE; | 265 const GoogleServiceAuthError& auth_error) OVERRIDE; |
| 275 virtual void OnPassphraseRequired( | 266 virtual void OnPassphraseRequired( |
| 276 sync_api::PassphraseRequiredReason reason) OVERRIDE; | 267 sync_api::PassphraseRequiredReason reason) OVERRIDE; |
| 277 virtual void OnPassphraseAccepted( | 268 virtual void OnPassphraseAccepted( |
| 278 const std::string& bootstrap_token) OVERRIDE; | 269 const std::string& bootstrap_token) OVERRIDE; |
| 279 virtual void OnStopSyncingPermanently() OVERRIDE; | 270 virtual void OnStopSyncingPermanently() OVERRIDE; |
| 280 virtual void OnUpdatedToken(const std::string& token) OVERRIDE; | 271 virtual void OnUpdatedToken(const std::string& token) OVERRIDE; |
| 281 virtual void OnClearServerDataFailed() OVERRIDE; | 272 virtual void OnClearServerDataFailed() OVERRIDE; |
| 282 virtual void OnClearServerDataSucceeded() OVERRIDE; | 273 virtual void OnClearServerDataSucceeded() OVERRIDE; |
| 283 virtual void OnEncryptionComplete( | 274 virtual void OnEncryptionComplete( |
| 284 const syncable::ModelTypeSet& encrypted_types); | 275 const syncable::ModelTypeSet& encrypted_types); |
| 285 virtual void OnActionableError( | 276 virtual void OnActionableError( |
| 286 const browser_sync::SyncProtocolError& sync_error); | 277 const browser_sync::SyncProtocolError& sync_error); |
| 287 | 278 |
| 288 struct DoInitializeOptions { | 279 struct DoInitializeOptions { |
| 289 DoInitializeOptions( | 280 DoInitializeOptions( |
| 281 MessageLoop* sync_loop, |
| 290 SyncBackendRegistrar* registrar, | 282 SyncBackendRegistrar* registrar, |
| 291 const WeakHandle<JsEventHandler>& event_handler, | 283 const WeakHandle<JsEventHandler>& event_handler, |
| 292 const GURL& service_url, | 284 const GURL& service_url, |
| 293 const scoped_refptr<net::URLRequestContextGetter>& | 285 const scoped_refptr<net::URLRequestContextGetter>& |
| 294 request_context_getter, | 286 request_context_getter, |
| 295 const sync_api::SyncCredentials& credentials, | 287 const sync_api::SyncCredentials& credentials, |
| 296 bool delete_sync_data_folder, | 288 bool delete_sync_data_folder, |
| 297 const std::string& restored_key_for_bootstrapping, | 289 const std::string& restored_key_for_bootstrapping, |
| 298 bool setup_for_test_mode); | 290 bool setup_for_test_mode); |
| 299 ~DoInitializeOptions(); | 291 ~DoInitializeOptions(); |
| 300 | 292 |
| 293 MessageLoop* sync_loop; |
| 301 SyncBackendRegistrar* registrar; | 294 SyncBackendRegistrar* registrar; |
| 302 WeakHandle<JsEventHandler> event_handler; | 295 WeakHandle<JsEventHandler> event_handler; |
| 303 GURL service_url; | 296 GURL service_url; |
| 304 scoped_refptr<net::URLRequestContextGetter> request_context_getter; | 297 scoped_refptr<net::URLRequestContextGetter> request_context_getter; |
| 305 sync_api::SyncCredentials credentials; | 298 sync_api::SyncCredentials credentials; |
| 306 std::string lsid; | 299 std::string lsid; |
| 307 bool delete_sync_data_folder; | 300 bool delete_sync_data_folder; |
| 308 std::string restored_key_for_bootstrapping; | 301 std::string restored_key_for_bootstrapping; |
| 309 bool setup_for_test_mode; | 302 bool setup_for_test_mode; |
| 310 }; | 303 }; |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 void HandleClearServerDataFailedOnFrontendLoop(); | 435 void HandleClearServerDataFailedOnFrontendLoop(); |
| 443 | 436 |
| 444 void FinishConfigureDataTypesOnFrontendLoop(); | 437 void FinishConfigureDataTypesOnFrontendLoop(); |
| 445 | 438 |
| 446 // Name used for debugging. | 439 // Name used for debugging. |
| 447 const std::string name_; | 440 const std::string name_; |
| 448 | 441 |
| 449 // Our parent SyncBackendHost | 442 // Our parent SyncBackendHost |
| 450 SyncBackendHost* host_; | 443 SyncBackendHost* host_; |
| 451 | 444 |
| 445 // The loop where all the sync backend operations happen. |
| 446 // Non-NULL only between calls to DoInitialize() and DoShutdown(). |
| 447 MessageLoop* sync_loop_; |
| 448 |
| 452 // Our parent's registrar (not owned). Non-NULL only between | 449 // Our parent's registrar (not owned). Non-NULL only between |
| 453 // calls to DoInitialize() and DoShutdown(). | 450 // calls to DoInitialize() and DoShutdown(). |
| 454 SyncBackendRegistrar* registrar_; | 451 SyncBackendRegistrar* registrar_; |
| 455 | 452 |
| 456 // The timer used to periodically call SaveChanges. | 453 // The timer used to periodically call SaveChanges. |
| 457 base::RepeatingTimer<Core> save_changes_timer_; | 454 base::RepeatingTimer<Core> save_changes_timer_; |
| 458 | 455 |
| 459 // The top-level syncapi entry point. Lives on the sync thread. | 456 // The top-level syncapi entry point. Lives on the sync thread. |
| 460 scoped_ptr<sync_api::SyncManager> sync_manager_; | 457 scoped_ptr<sync_api::SyncManager> sync_manager_; |
| 461 | 458 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 474 void FinishConfigureDataTypesOnFrontendLoop(); | 471 void FinishConfigureDataTypesOnFrontendLoop(); |
| 475 | 472 |
| 476 // Allows tests to perform alternate core initialization work. | 473 // Allows tests to perform alternate core initialization work. |
| 477 virtual void InitCore(const Core::DoInitializeOptions& options); | 474 virtual void InitCore(const Core::DoInitializeOptions& options); |
| 478 | 475 |
| 479 // Factory method for HttpPostProviderFactories. Should be | 476 // Factory method for HttpPostProviderFactories. Should be |
| 480 // thread-safe. | 477 // thread-safe. |
| 481 virtual sync_api::HttpPostProviderFactory* MakeHttpBridgeFactory( | 478 virtual sync_api::HttpPostProviderFactory* MakeHttpBridgeFactory( |
| 482 const scoped_refptr<net::URLRequestContextGetter>& getter); | 479 const scoped_refptr<net::URLRequestContextGetter>& getter); |
| 483 | 480 |
| 484 MessageLoop* sync_loop() { return sync_thread_.message_loop(); } | |
| 485 | |
| 486 // Helpers to persist a token that can be used to bootstrap sync encryption | 481 // Helpers to persist a token that can be used to bootstrap sync encryption |
| 487 // across browser restart to avoid requiring the user to re-enter their | 482 // across browser restart to avoid requiring the user to re-enter their |
| 488 // passphrase. |token| must be valid UTF-8 as we use the PrefService for | 483 // passphrase. |token| must be valid UTF-8 as we use the PrefService for |
| 489 // storage. | 484 // storage. |
| 490 void PersistEncryptionBootstrapToken(const std::string& token); | 485 void PersistEncryptionBootstrapToken(const std::string& token); |
| 491 std::string RestoreEncryptionBootstrapToken(); | 486 std::string RestoreEncryptionBootstrapToken(); |
| 492 | 487 |
| 493 // Our core, which communicates directly to the syncapi. | 488 // Our core, which communicates directly to the syncapi. |
| 494 scoped_refptr<Core> core_; | 489 scoped_refptr<Core> core_; |
| 495 | 490 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 | 541 |
| 547 // UI-thread cache of the last SyncSessionSnapshot received from syncapi. | 542 // UI-thread cache of the last SyncSessionSnapshot received from syncapi. |
| 548 scoped_ptr<sessions::SyncSessionSnapshot> last_snapshot_; | 543 scoped_ptr<sessions::SyncSessionSnapshot> last_snapshot_; |
| 549 | 544 |
| 550 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); | 545 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); |
| 551 }; | 546 }; |
| 552 | 547 |
| 553 } // namespace browser_sync | 548 } // namespace browser_sync |
| 554 | 549 |
| 555 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ | 550 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ |
| OLD | NEW |