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