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 | 637 |
613 // Transfers ownership of the DictionaryValue to the caller. | 638 // Transfers ownership of the DictionaryValue to the caller. |
614 DictionaryValue* ToValue(const BaseTransaction* trans) const; | 639 DictionaryValue* ToValue(const BaseTransaction* trans) const; |
615 | 640 |
616 int64 id; | 641 int64 id; |
617 Action action; | 642 Action action; |
618 sync_pb::EntitySpecifics specifics; | 643 sync_pb::EntitySpecifics specifics; |
619 linked_ptr<ExtraChangeRecordData> extra; | 644 linked_ptr<ExtraPasswordChangeRecordData> extra; |
620 }; | |
621 | |
622 // Since PasswordSpecifics is just an encrypted blob, we extend to provide | |
623 // access to unencrypted bits. | |
624 class ExtraPasswordChangeRecordData : public ExtraChangeRecordData { | |
625 public: | |
626 explicit ExtraPasswordChangeRecordData( | |
627 const sync_pb::PasswordSpecificsData& data); | |
628 virtual ~ExtraPasswordChangeRecordData(); | |
629 | |
630 // Transfers ownership of the DictionaryValue to the caller. | |
631 virtual DictionaryValue* ToValue() const; | |
632 | |
633 const sync_pb::PasswordSpecificsData& unencrypted() const; | |
634 | |
635 private: | |
636 sync_pb::PasswordSpecificsData unencrypted_; | |
637 }; | 645 }; |
638 | 646 |
639 // Status encapsulates detailed state about the internals of the SyncManager. | 647 // Status encapsulates detailed state about the internals of the SyncManager. |
640 struct Status { | 648 struct Status { |
641 // Summary is a distilled set of important information that the end-user may | 649 // Summary is a distilled set of important information that the end-user may |
642 // wish to be informed about (through UI, for example). Note that if a | 650 // wish to be informed about (through UI, for example). Note that if a |
643 // summary state requires user interaction (such as auth failures), more | 651 // summary state requires user interaction (such as auth failures), more |
644 // detailed information may be contained in additional status fields. | 652 // detailed information may be contained in additional status fields. |
645 enum Summary { | 653 enum Summary { |
646 // The internal instance is in an unrecognizable state. This should not | 654 // The internal instance is in an unrecognizable state. This should not |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
793 // The syncer thread has been resumed. | 801 // The syncer thread has been resumed. |
794 virtual void OnResumed() = 0; | 802 virtual void OnResumed() = 0; |
795 | 803 |
796 // We are no longer permitted to communicate with the server. Sync should | 804 // We are no longer permitted to communicate with the server. Sync should |
797 // be disabled and state cleaned up at once. This can happen for a number | 805 // be disabled and state cleaned up at once. This can happen for a number |
798 // of reasons, e.g. swapping from a test instance to production, or a | 806 // of reasons, e.g. swapping from a test instance to production, or a |
799 // global stop syncing operation has wiped the store. | 807 // global stop syncing operation has wiped the store. |
800 virtual void OnStopSyncingPermanently() = 0; | 808 virtual void OnStopSyncingPermanently() = 0; |
801 | 809 |
802 // After a request to clear server data, these callbacks are invoked to | 810 // After a request to clear server data, these callbacks are invoked to |
803 // indicate success or failure | 811 // indicate success or failure. |
804 virtual void OnClearServerDataSucceeded() = 0; | 812 virtual void OnClearServerDataSucceeded() = 0; |
805 virtual void OnClearServerDataFailed() = 0; | 813 virtual void OnClearServerDataFailed() = 0; |
806 | 814 |
| 815 // Called after we finish encrypting all appropriate datatypes. |
| 816 virtual void OnEncryptionComplete( |
| 817 const syncable::ModelTypeSet& encrypted_types) = 0; |
| 818 |
807 protected: | 819 protected: |
808 virtual ~Observer(); | 820 virtual ~Observer(); |
809 }; | 821 }; |
810 | 822 |
811 // Create an uninitialized SyncManager. Callers must Init() before using. | 823 // Create an uninitialized SyncManager. Callers must Init() before using. |
812 SyncManager(); | 824 SyncManager(); |
813 virtual ~SyncManager(); | 825 virtual ~SyncManager(); |
814 | 826 |
815 // Initialize the sync manager. |database_location| specifies the path of | 827 // Initialize the sync manager. |database_location| specifies the path of |
816 // the directory in which to locate a sqlite repository storing the syncer | 828 // the directory in which to locate a sqlite repository storing the syncer |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
873 // passphrase gets applied as soon as possible. | 885 // passphrase gets applied as soon as possible. |
874 // If the passphrase in invalid, OnPassphraseRequired will be fired. | 886 // If the passphrase in invalid, OnPassphraseRequired will be fired. |
875 // Calling this metdod again is the appropriate course of action to "retry" | 887 // Calling this metdod again is the appropriate course of action to "retry" |
876 // with a new passphrase. | 888 // with a new passphrase. |
877 // |is_explicit| is true if the call is in response to the user explicitly | 889 // |is_explicit| is true if the call is in response to the user explicitly |
878 // setting a passphrase as opposed to implicitly (from the users' perspective) | 890 // setting a passphrase as opposed to implicitly (from the users' perspective) |
879 // using their Google Account password. An implicit SetPassphrase will *not* | 891 // using their Google Account password. An implicit SetPassphrase will *not* |
880 // *not* override an explicit passphrase set previously. | 892 // *not* override an explicit passphrase set previously. |
881 void SetPassphrase(const std::string& passphrase, bool is_explicit); | 893 void SetPassphrase(const std::string& passphrase, bool is_explicit); |
882 | 894 |
| 895 // Set the datatypes we want to encrypt and encrypt any nodes as necessary. |
| 896 void EncryptDataTypes(const syncable::ModelTypeSet& encrypted_types); |
| 897 |
883 // Requests the syncer thread to pause. The observer's OnPause | 898 // Requests the syncer thread to pause. The observer's OnPause |
884 // method will be called when the syncer thread is paused. Returns | 899 // method will be called when the syncer thread is paused. Returns |
885 // false if the syncer thread can not be paused (e.g. if it is not | 900 // false if the syncer thread can not be paused (e.g. if it is not |
886 // started). | 901 // started). |
887 bool RequestPause(); | 902 bool RequestPause(); |
888 | 903 |
889 // Requests the syncer thread to resume. The observer's OnResume | 904 // Requests the syncer thread to resume. The observer's OnResume |
890 // method will be called when the syncer thread is resumed. Returns | 905 // method will be called when the syncer thread is resumed. Returns |
891 // false if the syncer thread can not be resumed (e.g. if it is not | 906 // false if the syncer thread can not be resumed (e.g. if it is not |
892 // paused). | 907 // paused). |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1051 // This allows actual HttpPostProvider subclass implementations to be | 1066 // This allows actual HttpPostProvider subclass implementations to be |
1052 // reference counted, which is useful if a particular implementation uses | 1067 // reference counted, which is useful if a particular implementation uses |
1053 // multiple threads to serve network requests. | 1068 // multiple threads to serve network requests. |
1054 virtual void Destroy(HttpPostProviderInterface* http) = 0; | 1069 virtual void Destroy(HttpPostProviderInterface* http) = 0; |
1055 virtual ~HttpPostProviderFactory() { } | 1070 virtual ~HttpPostProviderFactory() { } |
1056 }; | 1071 }; |
1057 | 1072 |
1058 } // namespace sync_api | 1073 } // namespace sync_api |
1059 | 1074 |
1060 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNCAPI_H_ | 1075 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNCAPI_H_ |
OLD | NEW |