| 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 // This file defines the "sync API", an interface to the syncer | 5 // This file defines the "sync API", an interface to the syncer |
| 6 // backend that exposes (1) the core functionality of maintaining a consistent | 6 // backend that exposes (1) the core functionality of maintaining a consistent |
| 7 // local snapshot of a hierarchical object set; (2) a means to transactionally | 7 // local snapshot of a hierarchical object set; (2) a means to transactionally |
| 8 // access and modify those objects; (3) a means to control client/server | 8 // access and modify those objects; (3) a means to control client/server |
| 9 // synchronization tasks, namely: pushing local object modifications to a | 9 // synchronization tasks, namely: pushing local object modifications to a |
| 10 // server, pulling nonlocal object modifications from a server to this client, | 10 // server, pulling nonlocal object modifications from a server to this client, |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 protected: | 259 protected: |
| 260 BaseNode(); | 260 BaseNode(); |
| 261 virtual ~BaseNode(); | 261 virtual ~BaseNode(); |
| 262 // The server has a size limit on client tags, so we generate a fixed length | 262 // The server has a size limit on client tags, so we generate a fixed length |
| 263 // hash locally. This also ensures that ModelTypes have unique namespaces. | 263 // hash locally. This also ensures that ModelTypes have unique namespaces. |
| 264 static std::string GenerateSyncableHash(syncable::ModelType model_type, | 264 static std::string GenerateSyncableHash(syncable::ModelType model_type, |
| 265 const std::string& client_tag); | 265 const std::string& client_tag); |
| 266 | 266 |
| 267 // Determines whether part of the entry is encrypted, and if so attempts to | 267 // Determines whether part of the entry is encrypted, and if so attempts to |
| 268 // decrypt it. Unless decryption is necessary and fails, this will always | 268 // decrypt it. Unless decryption is necessary and fails, this will always |
| 269 // return |true|. | 269 // return |true|. If the contents are encrypted, the decrypted data will be |
| 270 // stored in |unencrypted_data_|. |
| 271 // This method is invoked once when the BaseNode is initialized. |
| 270 bool DecryptIfNecessary(syncable::Entry* entry); | 272 bool DecryptIfNecessary(syncable::Entry* entry); |
| 271 | 273 |
| 274 // Returns the unencrypted specifics associated with |entry|. If |entry| was |
| 275 // not encrypted, it directly returns |entry|'s EntitySpecifics. Otherwise, |
| 276 // returns |unencrypted_data_|. |
| 277 // This method is invoked by the datatype specific Get<datatype>Specifics |
| 278 // methods. |
| 279 const sync_pb::EntitySpecifics& GetUnencryptedSpecifics( |
| 280 const syncable::Entry* entry) const; |
| 281 |
| 272 private: | 282 private: |
| 273 void* operator new(size_t size); // Node is meant for stack use only. | 283 void* operator new(size_t size); // Node is meant for stack use only. |
| 274 | 284 |
| 275 // If this node represents a password, this field will hold the actual | 285 // A holder for the unencrypted data stored in an encrypted node. |
| 276 // decrypted password data. | 286 sync_pb::EntitySpecifics unencrypted_data_; |
| 287 |
| 288 // Same as |unencrypted_data_|, but for legacy password encryption. |
| 277 scoped_ptr<sync_pb::PasswordSpecificsData> password_data_; | 289 scoped_ptr<sync_pb::PasswordSpecificsData> password_data_; |
| 278 | 290 |
| 279 friend class SyncApiTest; | 291 friend class SyncApiTest; |
| 280 FRIEND_TEST_ALL_PREFIXES(SyncApiTest, GenerateSyncableHash); | 292 FRIEND_TEST_ALL_PREFIXES(SyncApiTest, GenerateSyncableHash); |
| 281 | 293 |
| 282 DISALLOW_COPY_AND_ASSIGN(BaseNode); | 294 DISALLOW_COPY_AND_ASSIGN(BaseNode); |
| 283 }; | 295 }; |
| 284 | 296 |
| 285 // WriteNode extends BaseNode to add mutation, and wraps | 297 // WriteNode extends BaseNode to add mutation, and wraps |
| 286 // syncable::MutableEntry. A WriteTransaction is needed to create a WriteNode. | 298 // syncable::MutableEntry. A WriteTransaction is needed to create a WriteNode. |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 void SetTypedUrlSpecifics(const sync_pb::TypedUrlSpecifics& specifics); | 393 void SetTypedUrlSpecifics(const sync_pb::TypedUrlSpecifics& specifics); |
| 382 | 394 |
| 383 // Set the extension specifics (id, update url, enabled state, etc). | 395 // Set the extension specifics (id, update url, enabled state, etc). |
| 384 // Should only be called if GetModelType() == EXTENSIONS. | 396 // Should only be called if GetModelType() == EXTENSIONS. |
| 385 void SetExtensionSpecifics(const sync_pb::ExtensionSpecifics& specifics); | 397 void SetExtensionSpecifics(const sync_pb::ExtensionSpecifics& specifics); |
| 386 | 398 |
| 387 // Set the session specifics (windows, tabs, navigations etc.). | 399 // Set the session specifics (windows, tabs, navigations etc.). |
| 388 // Should only be called if GetModelType() == SESSIONS. | 400 // Should only be called if GetModelType() == SESSIONS. |
| 389 void SetSessionSpecifics(const sync_pb::SessionSpecifics& specifics); | 401 void SetSessionSpecifics(const sync_pb::SessionSpecifics& specifics); |
| 390 | 402 |
| 403 // Resets the EntitySpecifics for this node based on the unencrypted data. |
| 404 // Will encrypt if necessary. |
| 405 void ResetFromSpecifics(); |
| 406 |
| 391 // Implementation of BaseNode's abstract virtual accessors. | 407 // Implementation of BaseNode's abstract virtual accessors. |
| 392 virtual const syncable::Entry* GetEntry() const; | 408 virtual const syncable::Entry* GetEntry() const; |
| 393 | 409 |
| 394 virtual const BaseTransaction* GetTransaction() const; | 410 virtual const BaseTransaction* GetTransaction() const; |
| 395 | 411 |
| 396 private: | 412 private: |
| 397 void* operator new(size_t size); // Node is meant for stack use only. | 413 void* operator new(size_t size); // Node is meant for stack use only. |
| 398 | 414 |
| 399 // Helper to set model type. This will clear any specifics data. | 415 // Helper to set model type. This will clear any specifics data. |
| 400 void PutModelType(syncable::ModelType model_type); | 416 void PutModelType(syncable::ModelType model_type); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 429 const sync_pb::ExtensionSpecifics& new_value); | 445 const sync_pb::ExtensionSpecifics& new_value); |
| 430 void PutSessionSpecificsAndMarkForSyncing( | 446 void PutSessionSpecificsAndMarkForSyncing( |
| 431 const sync_pb::SessionSpecifics& new_value); | 447 const sync_pb::SessionSpecifics& new_value); |
| 432 void PutSpecificsAndMarkForSyncing( | 448 void PutSpecificsAndMarkForSyncing( |
| 433 const sync_pb::EntitySpecifics& specifics); | 449 const sync_pb::EntitySpecifics& specifics); |
| 434 | 450 |
| 435 // Sets IS_UNSYNCED and SYNCING to ensure this entry is considered in an | 451 // Sets IS_UNSYNCED and SYNCING to ensure this entry is considered in an |
| 436 // upcoming commit pass. | 452 // upcoming commit pass. |
| 437 void MarkForSyncing(); | 453 void MarkForSyncing(); |
| 438 | 454 |
| 455 // Encrypt the specifics if the datatype requries it. |
| 456 void EncryptIfNecessary(sync_pb::EntitySpecifics* new_value); |
| 457 |
| 439 // The underlying syncable object which this class wraps. | 458 // The underlying syncable object which this class wraps. |
| 440 syncable::MutableEntry* entry_; | 459 syncable::MutableEntry* entry_; |
| 441 | 460 |
| 442 // The sync API transaction that is the parent of this node. | 461 // The sync API transaction that is the parent of this node. |
| 443 WriteTransaction* transaction_; | 462 WriteTransaction* transaction_; |
| 444 | 463 |
| 445 DISALLOW_COPY_AND_ASSIGN(WriteNode); | 464 DISALLOW_COPY_AND_ASSIGN(WriteNode); |
| 446 }; | 465 }; |
| 447 | 466 |
| 448 // ReadNode wraps a syncable::Entry to provide the functionality of a | 467 // ReadNode wraps a syncable::Entry to provide the functionality of a |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 // multiple threads interact with the same local sync repository (i.e. the | 599 // multiple threads interact with the same local sync repository (i.e. the |
| 581 // same sqlite database), they should share a single SyncManager instance. The | 600 // same sqlite database), they should share a single SyncManager instance. The |
| 582 // caller should typically create one SyncManager for the lifetime of a user | 601 // caller should typically create one SyncManager for the lifetime of a user |
| 583 // session. | 602 // session. |
| 584 class SyncManager { | 603 class SyncManager { |
| 585 public: | 604 public: |
| 586 // SyncInternal contains the implementation of SyncManager, while abstracting | 605 // SyncInternal contains the implementation of SyncManager, while abstracting |
| 587 // internal types from clients of the interface. | 606 // internal types from clients of the interface. |
| 588 class SyncInternal; | 607 class SyncInternal; |
| 589 | 608 |
| 590 // TODO(tim): Depending on how multi-type encryption pans out, maybe we | 609 // TODO(zea): One day get passwords playing nicely with the rest of encryption |
| 591 // should turn ChangeRecord itself into a class. Or we could template this | 610 // and get rid of this. |
| 592 // wrapper / add a templated method to return unencrypted protobufs. | 611 class ExtraPasswordChangeRecordData { |
| 593 class ExtraChangeRecordData { | |
| 594 public: | 612 public: |
| 595 virtual ~ExtraChangeRecordData(); | 613 ExtraPasswordChangeRecordData(); |
| 614 explicit ExtraPasswordChangeRecordData( |
| 615 const sync_pb::PasswordSpecificsData& data); |
| 616 virtual ~ExtraPasswordChangeRecordData(); |
| 596 | 617 |
| 597 // Transfers ownership of the DictionaryValue to the caller. | 618 // Transfers ownership of the DictionaryValue to the caller. |
| 598 virtual DictionaryValue* ToValue() const = 0; | 619 virtual DictionaryValue* ToValue() const; |
| 620 |
| 621 const sync_pb::PasswordSpecificsData& unencrypted() const; |
| 622 private: |
| 623 sync_pb::PasswordSpecificsData unencrypted_; |
| 599 }; | 624 }; |
| 600 | 625 |
| 601 // ChangeRecord indicates a single item that changed as a result of a sync | 626 // ChangeRecord indicates a single item that changed as a result of a sync |
| 602 // operation. This gives the sync id of the node that changed, and the type | 627 // operation. This gives the sync id of the node that changed, and the type |
| 603 // of change. To get the actual property values after an ADD or UPDATE, the | 628 // of change. To get the actual property values after an ADD or UPDATE, the |
| 604 // client should get the node with InitByIdLookup(), using the provided id. | 629 // client should get the node with InitByIdLookup(), using the provided id. |
| 605 struct ChangeRecord { | 630 struct ChangeRecord { |
| 606 enum Action { | 631 enum Action { |
| 607 ACTION_ADD, | 632 ACTION_ADD, |
| 608 ACTION_DELETE, | 633 ACTION_DELETE, |
| 609 ACTION_UPDATE, | 634 ACTION_UPDATE, |
| 610 }; | 635 }; |
| 611 ChangeRecord(); | 636 ChangeRecord(); |
| 612 ~ChangeRecord(); | 637 ~ChangeRecord(); |
| 613 | 638 |
| 614 // Transfers ownership of the DictionaryValue to the caller. | 639 // Transfers ownership of the DictionaryValue to the caller. |
| 615 DictionaryValue* ToValue(const BaseTransaction* trans) const; | 640 DictionaryValue* ToValue(const BaseTransaction* trans) const; |
| 616 | 641 |
| 617 int64 id; | 642 int64 id; |
| 618 Action action; | 643 Action action; |
| 619 sync_pb::EntitySpecifics specifics; | 644 sync_pb::EntitySpecifics specifics; |
| 620 linked_ptr<ExtraChangeRecordData> extra; | 645 linked_ptr<ExtraPasswordChangeRecordData> extra; |
| 621 }; | |
| 622 | |
| 623 // Since PasswordSpecifics is just an encrypted blob, we extend to provide | |
| 624 // access to unencrypted bits. | |
| 625 class ExtraPasswordChangeRecordData : public ExtraChangeRecordData { | |
| 626 public: | |
| 627 explicit ExtraPasswordChangeRecordData( | |
| 628 const sync_pb::PasswordSpecificsData& data); | |
| 629 virtual ~ExtraPasswordChangeRecordData(); | |
| 630 | |
| 631 // Transfers ownership of the DictionaryValue to the caller. | |
| 632 virtual DictionaryValue* ToValue() const; | |
| 633 | |
| 634 const sync_pb::PasswordSpecificsData& unencrypted() const; | |
| 635 | |
| 636 private: | |
| 637 sync_pb::PasswordSpecificsData unencrypted_; | |
| 638 }; | 646 }; |
| 639 | 647 |
| 640 // Status encapsulates detailed state about the internals of the SyncManager. | 648 // Status encapsulates detailed state about the internals of the SyncManager. |
| 641 struct Status { | 649 struct Status { |
| 642 // Summary is a distilled set of important information that the end-user may | 650 // Summary is a distilled set of important information that the end-user may |
| 643 // wish to be informed about (through UI, for example). Note that if a | 651 // wish to be informed about (through UI, for example). Note that if a |
| 644 // summary state requires user interaction (such as auth failures), more | 652 // summary state requires user interaction (such as auth failures), more |
| 645 // detailed information may be contained in additional status fields. | 653 // detailed information may be contained in additional status fields. |
| 646 enum Summary { | 654 enum Summary { |
| 647 // The internal instance is in an unrecognizable state. This should not | 655 // The internal instance is in an unrecognizable state. This should not |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 // The syncer thread has been resumed. | 802 // The syncer thread has been resumed. |
| 795 virtual void OnResumed() = 0; | 803 virtual void OnResumed() = 0; |
| 796 | 804 |
| 797 // We are no longer permitted to communicate with the server. Sync should | 805 // We are no longer permitted to communicate with the server. Sync should |
| 798 // be disabled and state cleaned up at once. This can happen for a number | 806 // be disabled and state cleaned up at once. This can happen for a number |
| 799 // of reasons, e.g. swapping from a test instance to production, or a | 807 // of reasons, e.g. swapping from a test instance to production, or a |
| 800 // global stop syncing operation has wiped the store. | 808 // global stop syncing operation has wiped the store. |
| 801 virtual void OnStopSyncingPermanently() = 0; | 809 virtual void OnStopSyncingPermanently() = 0; |
| 802 | 810 |
| 803 // After a request to clear server data, these callbacks are invoked to | 811 // After a request to clear server data, these callbacks are invoked to |
| 804 // indicate success or failure | 812 // indicate success or failure. |
| 805 virtual void OnClearServerDataSucceeded() = 0; | 813 virtual void OnClearServerDataSucceeded() = 0; |
| 806 virtual void OnClearServerDataFailed() = 0; | 814 virtual void OnClearServerDataFailed() = 0; |
| 807 | 815 |
| 816 // Called after we finish encrypting all appropriate datatypes. |
| 817 virtual void OnEncryptionComplete( |
| 818 const syncable::ModelTypeSet& encrypted_types) = 0; |
| 819 |
| 808 protected: | 820 protected: |
| 809 virtual ~Observer(); | 821 virtual ~Observer(); |
| 810 }; | 822 }; |
| 811 | 823 |
| 812 // Create an uninitialized SyncManager. Callers must Init() before using. | 824 // Create an uninitialized SyncManager. Callers must Init() before using. |
| 813 SyncManager(); | 825 SyncManager(); |
| 814 virtual ~SyncManager(); | 826 virtual ~SyncManager(); |
| 815 | 827 |
| 816 // Initialize the sync manager. |database_location| specifies the path of | 828 // Initialize the sync manager. |database_location| specifies the path of |
| 817 // the directory in which to locate a sqlite repository storing the syncer | 829 // the directory in which to locate a sqlite repository storing the syncer |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 878 // passphrase gets applied as soon as possible. | 890 // passphrase gets applied as soon as possible. |
| 879 // If the passphrase in invalid, OnPassphraseRequired will be fired. | 891 // If the passphrase in invalid, OnPassphraseRequired will be fired. |
| 880 // Calling this metdod again is the appropriate course of action to "retry" | 892 // Calling this metdod again is the appropriate course of action to "retry" |
| 881 // with a new passphrase. | 893 // with a new passphrase. |
| 882 // |is_explicit| is true if the call is in response to the user explicitly | 894 // |is_explicit| is true if the call is in response to the user explicitly |
| 883 // setting a passphrase as opposed to implicitly (from the users' perspective) | 895 // setting a passphrase as opposed to implicitly (from the users' perspective) |
| 884 // using their Google Account password. An implicit SetPassphrase will *not* | 896 // using their Google Account password. An implicit SetPassphrase will *not* |
| 885 // *not* override an explicit passphrase set previously. | 897 // *not* override an explicit passphrase set previously. |
| 886 void SetPassphrase(const std::string& passphrase, bool is_explicit); | 898 void SetPassphrase(const std::string& passphrase, bool is_explicit); |
| 887 | 899 |
| 900 // Set the datatypes we want to encrypt and encrypt any nodes as necessary. |
| 901 void EncryptDataTypes(const syncable::ModelTypeSet& encrypted_types); |
| 902 |
| 888 // Requests the syncer thread to pause. The observer's OnPause | 903 // Requests the syncer thread to pause. The observer's OnPause |
| 889 // method will be called when the syncer thread is paused. Returns | 904 // method will be called when the syncer thread is paused. Returns |
| 890 // false if the syncer thread can not be paused (e.g. if it is not | 905 // false if the syncer thread can not be paused (e.g. if it is not |
| 891 // started). | 906 // started). |
| 892 bool RequestPause(); | 907 bool RequestPause(); |
| 893 | 908 |
| 894 // Requests the syncer thread to resume. The observer's OnResume | 909 // Requests the syncer thread to resume. The observer's OnResume |
| 895 // method will be called when the syncer thread is resumed. Returns | 910 // method will be called when the syncer thread is resumed. Returns |
| 896 // false if the syncer thread can not be resumed (e.g. if it is not | 911 // false if the syncer thread can not be resumed (e.g. if it is not |
| 897 // paused). | 912 // paused). |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1056 // This allows actual HttpPostProvider subclass implementations to be | 1071 // This allows actual HttpPostProvider subclass implementations to be |
| 1057 // reference counted, which is useful if a particular implementation uses | 1072 // reference counted, which is useful if a particular implementation uses |
| 1058 // multiple threads to serve network requests. | 1073 // multiple threads to serve network requests. |
| 1059 virtual void Destroy(HttpPostProviderInterface* http) = 0; | 1074 virtual void Destroy(HttpPostProviderInterface* http) = 0; |
| 1060 virtual ~HttpPostProviderFactory() { } | 1075 virtual ~HttpPostProviderFactory() { } |
| 1061 }; | 1076 }; |
| 1062 | 1077 |
| 1063 } // namespace sync_api | 1078 } // namespace sync_api |
| 1064 | 1079 |
| 1065 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNCAPI_H_ | 1080 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNCAPI_H_ |
| OLD | NEW |