| OLD | NEW |
| 1 // Copyright (c) 2010 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 // changed in another synced client. if | 81 // changed in another synced client. if |
| 82 // |passphrase_required_for_decryption| is false, the passphrase is | 82 // |passphrase_required_for_decryption| is false, the passphrase is |
| 83 // required only for encryption. | 83 // required only for encryption. |
| 84 virtual void OnPassphraseRequired(bool for_decryption) = 0; | 84 virtual void OnPassphraseRequired(bool for_decryption) = 0; |
| 85 | 85 |
| 86 // Called when the passphrase provided by the user is | 86 // Called when the passphrase provided by the user is |
| 87 // accepted. After this is called, updates to sensitive nodes are | 87 // accepted. After this is called, updates to sensitive nodes are |
| 88 // encrypted using the accepted passphrase. | 88 // encrypted using the accepted passphrase. |
| 89 virtual void OnPassphraseAccepted() = 0; | 89 virtual void OnPassphraseAccepted() = 0; |
| 90 | 90 |
| 91 virtual void OnEncryptionComplete( |
| 92 const syncable::ModelTypeSet& encrypted_types) = 0; |
| 93 |
| 91 protected: | 94 protected: |
| 92 // Don't delete through SyncFrontend interface. | 95 // Don't delete through SyncFrontend interface. |
| 93 virtual ~SyncFrontend() { | 96 virtual ~SyncFrontend() { |
| 94 } | 97 } |
| 95 private: | 98 private: |
| 96 DISALLOW_COPY_AND_ASSIGN(SyncFrontend); | 99 DISALLOW_COPY_AND_ASSIGN(SyncFrontend); |
| 97 }; | 100 }; |
| 98 | 101 |
| 99 // A UI-thread safe API into the sync backend that "hosts" the top-level | 102 // A UI-thread safe API into the sync backend that "hosts" the top-level |
| 100 // syncapi element, the SyncManager, on its own thread. This class handles | 103 // syncapi element, the SyncManager, on its own thread. This class handles |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 | 154 |
| 152 // Changes the set of data types that are currently being synced. | 155 // Changes the set of data types that are currently being synced. |
| 153 // The ready_task will be run when all of the requested data types | 156 // The ready_task will be run when all of the requested data types |
| 154 // are up-to-date and ready for activation. The task will cancelled | 157 // are up-to-date and ready for activation. The task will cancelled |
| 155 // upon shutdown. The method takes ownership of the task pointer. | 158 // upon shutdown. The method takes ownership of the task pointer. |
| 156 virtual void ConfigureDataTypes( | 159 virtual void ConfigureDataTypes( |
| 157 const DataTypeController::TypeMap& data_type_controllers, | 160 const DataTypeController::TypeMap& data_type_controllers, |
| 158 const syncable::ModelTypeSet& types, | 161 const syncable::ModelTypeSet& types, |
| 159 CancelableTask* ready_task); | 162 CancelableTask* ready_task); |
| 160 | 163 |
| 164 // Encrypts the specified datatypes and marks them as needing encryption on |
| 165 // other machines. This affects all machines synced to this account and all |
| 166 // data belonging to the specified types. |encrypted_types| must be a subset |
| 167 // of the enabled datatypes. |
| 168 // Note: actual work is done on core_thread_'s message loop. |
| 169 virtual void EncryptDataTypes( |
| 170 const syncable::ModelTypeSet& encrypted_types); |
| 171 |
| 161 syncable::AutofillMigrationState | 172 syncable::AutofillMigrationState |
| 162 GetAutofillMigrationState(); | 173 GetAutofillMigrationState(); |
| 163 | 174 |
| 164 void SetAutofillMigrationState( | 175 void SetAutofillMigrationState( |
| 165 syncable::AutofillMigrationState state); | 176 syncable::AutofillMigrationState state); |
| 166 | 177 |
| 167 syncable::AutofillMigrationDebugInfo | 178 syncable::AutofillMigrationDebugInfo |
| 168 GetAutofillMigrationDebugInfo(); | 179 GetAutofillMigrationDebugInfo(); |
| 169 | 180 |
| 170 void SetAutofillMigrationDebugInfo( | 181 void SetAutofillMigrationDebugInfo( |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 virtual void OnInitializationComplete(); | 278 virtual void OnInitializationComplete(); |
| 268 virtual void OnAuthError(const GoogleServiceAuthError& auth_error); | 279 virtual void OnAuthError(const GoogleServiceAuthError& auth_error); |
| 269 virtual void OnPassphraseRequired(bool for_decryption); | 280 virtual void OnPassphraseRequired(bool for_decryption); |
| 270 virtual void OnPassphraseAccepted(const std::string& bootstrap_token); | 281 virtual void OnPassphraseAccepted(const std::string& bootstrap_token); |
| 271 virtual void OnPaused(); | 282 virtual void OnPaused(); |
| 272 virtual void OnResumed(); | 283 virtual void OnResumed(); |
| 273 virtual void OnStopSyncingPermanently(); | 284 virtual void OnStopSyncingPermanently(); |
| 274 virtual void OnUpdatedToken(const std::string& token); | 285 virtual void OnUpdatedToken(const std::string& token); |
| 275 virtual void OnClearServerDataFailed(); | 286 virtual void OnClearServerDataFailed(); |
| 276 virtual void OnClearServerDataSucceeded(); | 287 virtual void OnClearServerDataSucceeded(); |
| 288 virtual void OnEncryptionComplete( |
| 289 const syncable::ModelTypeSet& encrypted_types); |
| 277 | 290 |
| 278 // JsBackend implementation. | 291 // JsBackend implementation. |
| 279 virtual void SetParentJsEventRouter(JsEventRouter* router); | 292 virtual void SetParentJsEventRouter(JsEventRouter* router); |
| 280 virtual void RemoveParentJsEventRouter(); | 293 virtual void RemoveParentJsEventRouter(); |
| 281 virtual const JsEventRouter* GetParentJsEventRouter() const; | 294 virtual const JsEventRouter* GetParentJsEventRouter() const; |
| 282 virtual void ProcessMessage(const std::string& name, const JsArgList& args, | 295 virtual void ProcessMessage(const std::string& name, const JsArgList& args, |
| 283 const JsEventHandler* sender); | 296 const JsEventHandler* sender); |
| 284 | 297 |
| 285 // JsEventRouter implementation. | 298 // JsEventRouter implementation. |
| 286 virtual void RouteJsEvent(const std::string& event_name, | 299 virtual void RouteJsEvent(const std::string& event_name, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 // syncer. | 343 // syncer. |
| 331 void DoRequestNudge(); | 344 void DoRequestNudge(); |
| 332 void DoRequestPause(); | 345 void DoRequestPause(); |
| 333 void DoRequestResume(); | 346 void DoRequestResume(); |
| 334 void DoRequestClearServerData(); | 347 void DoRequestClearServerData(); |
| 335 | 348 |
| 336 // Called on our SyncBackendHost's |core_thread_| to set the passphrase | 349 // Called on our SyncBackendHost's |core_thread_| to set the passphrase |
| 337 // on behalf of SyncBackendHost::SupplyPassphrase. | 350 // on behalf of SyncBackendHost::SupplyPassphrase. |
| 338 void DoSetPassphrase(const std::string& passphrase, bool is_explicit); | 351 void DoSetPassphrase(const std::string& passphrase, bool is_explicit); |
| 339 | 352 |
| 353 // Called on SyncBackendHost's |core_thread_| to set the datatypes we need |
| 354 // to encrypt as well as encrypt all local data of that type. |
| 355 void DoEncryptDataTypes(const syncable::ModelTypeSet& encrypted_types); |
| 356 |
| 340 // The shutdown order is a bit complicated: | 357 // The shutdown order is a bit complicated: |
| 341 // 1) From |core_thread_|, invoke the syncapi Shutdown call to do a final | 358 // 1) From |core_thread_|, invoke the syncapi Shutdown call to do a final |
| 342 // SaveChanges, close sqlite handles, and halt the syncer thread (which | 359 // SaveChanges, close sqlite handles, and halt the syncer thread (which |
| 343 // could potentially block for 1 minute). | 360 // could potentially block for 1 minute). |
| 344 // 2) Then, from |frontend_loop_|, halt the core_thread_. This causes | 361 // 2) Then, from |frontend_loop_|, halt the core_thread_. This causes |
| 345 // syncapi thread-exit handlers to run and make use of cached pointers to | 362 // syncapi thread-exit handlers to run and make use of cached pointers to |
| 346 // various components owned implicitly by us. | 363 // various components owned implicitly by us. |
| 347 // 3) Destroy this Core. That will delete syncapi components in a safe order | 364 // 3) Destroy this Core. That will delete syncapi components in a safe order |
| 348 // because the thread that was using them has exited (in step 2). | 365 // because the thread that was using them has exited (in step 2). |
| 349 void DoShutdown(bool stopping_sync); | 366 void DoShutdown(bool stopping_sync); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 367 const std::string& name, const JsArgList& args, | 384 const std::string& name, const JsArgList& args, |
| 368 const JsEventHandler* sender); | 385 const JsEventHandler* sender); |
| 369 | 386 |
| 370 #if defined(UNIT_TEST) | 387 #if defined(UNIT_TEST) |
| 371 // Special form of initialization that does not try and authenticate the | 388 // Special form of initialization that does not try and authenticate the |
| 372 // last known user (since it will fail in test mode) and does some extra | 389 // last known user (since it will fail in test mode) and does some extra |
| 373 // setup to nudge the syncapi into a usable state. | 390 // setup to nudge the syncapi into a usable state. |
| 374 void DoInitializeForTest(const std::wstring& test_user, | 391 void DoInitializeForTest(const std::wstring& test_user, |
| 375 sync_api::HttpPostProviderFactory* factory, | 392 sync_api::HttpPostProviderFactory* factory, |
| 376 bool delete_sync_data_folder) { | 393 bool delete_sync_data_folder) { |
| 377 | |
| 378 // Construct dummy credentials for test. | 394 // Construct dummy credentials for test. |
| 379 sync_api::SyncCredentials credentials; | 395 sync_api::SyncCredentials credentials; |
| 380 credentials.email = WideToUTF8(test_user); | 396 credentials.email = WideToUTF8(test_user); |
| 381 credentials.sync_token = "token"; | 397 credentials.sync_token = "token"; |
| 382 DoInitialize(DoInitializeOptions(GURL(), factory, credentials, | 398 DoInitialize(DoInitializeOptions(GURL(), factory, credentials, |
| 383 delete_sync_data_folder, | 399 delete_sync_data_folder, |
| 384 notifier::NotifierOptions(), "", true)); | 400 notifier::NotifierOptions(), "", true)); |
| 385 } | 401 } |
| 386 #endif | 402 #endif |
| 387 | 403 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 // or for encrypting. If the reason is decryption, |for_decryption| will | 442 // or for encrypting. If the reason is decryption, |for_decryption| will |
| 427 // be true. | 443 // be true. |
| 428 void NotifyPassphraseRequired(bool for_decryption); | 444 void NotifyPassphraseRequired(bool for_decryption); |
| 429 | 445 |
| 430 // Invoked when the passphrase provided by the user has been accepted. | 446 // Invoked when the passphrase provided by the user has been accepted. |
| 431 void NotifyPassphraseAccepted(const std::string& bootstrap_token); | 447 void NotifyPassphraseAccepted(const std::string& bootstrap_token); |
| 432 | 448 |
| 433 // Invoked when an updated token is available from the sync server. | 449 // Invoked when an updated token is available from the sync server. |
| 434 void NotifyUpdatedToken(const std::string& token); | 450 void NotifyUpdatedToken(const std::string& token); |
| 435 | 451 |
| 452 // Invoked when sync finishes encrypting new datatypes or has become aware |
| 453 // of new datatypes requiring encryption. |
| 454 void NotifyEncryptionComplete(const syncable::ModelTypeSet& |
| 455 encrypted_types); |
| 456 |
| 436 // Called from Core::OnSyncCycleCompleted to handle updating frontend | 457 // Called from Core::OnSyncCycleCompleted to handle updating frontend |
| 437 // thread components. | 458 // thread components. |
| 438 void HandleSyncCycleCompletedOnFrontendLoop( | 459 void HandleSyncCycleCompletedOnFrontendLoop( |
| 439 sessions::SyncSessionSnapshot* snapshot); | 460 sessions::SyncSessionSnapshot* snapshot); |
| 440 | 461 |
| 441 void HandleStopSyncingPermanentlyOnFrontendLoop(); | 462 void HandleStopSyncingPermanentlyOnFrontendLoop(); |
| 442 | 463 |
| 443 // Called to handle success/failure of clearing server data | 464 // Called to handle success/failure of clearing server data |
| 444 void HandleClearServerDataSucceededOnFrontendLoop(); | 465 void HandleClearServerDataSucceededOnFrontendLoop(); |
| 445 void HandleClearServerDataFailedOnFrontendLoop(); | 466 void HandleClearServerDataFailedOnFrontendLoop(); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 // across browser restart to avoid requiring the user to re-enter their | 515 // across browser restart to avoid requiring the user to re-enter their |
| 495 // passphrase. |token| must be valid UTF-8 as we use the PrefService for | 516 // passphrase. |token| must be valid UTF-8 as we use the PrefService for |
| 496 // storage. | 517 // storage. |
| 497 void PersistEncryptionBootstrapToken(const std::string& token); | 518 void PersistEncryptionBootstrapToken(const std::string& token); |
| 498 std::string RestoreEncryptionBootstrapToken(); | 519 std::string RestoreEncryptionBootstrapToken(); |
| 499 | 520 |
| 500 // Our core, which communicates directly to the syncapi. | 521 // Our core, which communicates directly to the syncapi. |
| 501 scoped_refptr<Core> core_; | 522 scoped_refptr<Core> core_; |
| 502 | 523 |
| 503 private: | 524 private: |
| 504 | |
| 505 UIModelWorker* ui_worker(); | 525 UIModelWorker* ui_worker(); |
| 506 | 526 |
| 507 void ConfigureAutofillMigration(); | 527 void ConfigureAutofillMigration(); |
| 508 | 528 |
| 509 // A thread we dedicate for use by our Core to perform initialization, | 529 // A thread we dedicate for use by our Core to perform initialization, |
| 510 // authentication, handle messages from the syncapi, and periodically tell | 530 // authentication, handle messages from the syncapi, and periodically tell |
| 511 // the syncapi to persist itself. | 531 // the syncapi to persist itself. |
| 512 base::Thread core_thread_; | 532 base::Thread core_thread_; |
| 513 | 533 |
| 514 // A reference to the MessageLoop used to construct |this|, so we know how | 534 // A reference to the MessageLoop used to construct |this|, so we know how |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 | 588 |
| 569 // Whether we've processed the initialization complete callback. | 589 // Whether we've processed the initialization complete callback. |
| 570 bool syncapi_initialized_; | 590 bool syncapi_initialized_; |
| 571 | 591 |
| 572 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); | 592 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); |
| 573 }; | 593 }; |
| 574 | 594 |
| 575 } // namespace browser_sync | 595 } // namespace browser_sync |
| 576 | 596 |
| 577 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ | 597 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ |
| OLD | NEW |