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 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 protected: | 253 protected: |
254 BaseNode(); | 254 BaseNode(); |
255 virtual ~BaseNode(); | 255 virtual ~BaseNode(); |
256 // The server has a size limit on client tags, so we generate a fixed length | 256 // The server has a size limit on client tags, so we generate a fixed length |
257 // hash locally. This also ensures that ModelTypes have unique namespaces. | 257 // hash locally. This also ensures that ModelTypes have unique namespaces. |
258 static std::string GenerateSyncableHash(syncable::ModelType model_type, | 258 static std::string GenerateSyncableHash(syncable::ModelType model_type, |
259 const std::string& client_tag); | 259 const std::string& client_tag); |
260 | 260 |
261 // Determines whether part of the entry is encrypted, and if so attempts to | 261 // Determines whether part of the entry is encrypted, and if so attempts to |
262 // decrypt it. Unless decryption is necessary and fails, this will always | 262 // decrypt it. Unless decryption is necessary and fails, this will always |
263 // return |true|. | 263 // return |true|. If the contents are encrypted, the decrypted data will be |
| 264 // stored in |unencrypted_data_|. |
| 265 // This method is invoked once when the BaseNode is initialized. |
264 bool DecryptIfNecessary(syncable::Entry* entry); | 266 bool DecryptIfNecessary(syncable::Entry* entry); |
265 | 267 |
| 268 // Returns the unencrypted specifics associated with |entry|. If |entry| was |
| 269 // not encrypted, it directly returns |entry|'s EntitySpecifics. Otherwise, |
| 270 // returns |unencrypted_data_|. |
| 271 // This method is invoked by the datatype specific Get<datatype>Specifics |
| 272 // methods. |
| 273 const sync_pb::EntitySpecifics& GetUnencryptedSpecifics( |
| 274 const syncable::Entry* entry) const; |
| 275 |
266 private: | 276 private: |
267 void* operator new(size_t size); // Node is meant for stack use only. | 277 void* operator new(size_t size); // Node is meant for stack use only. |
268 | 278 |
269 // If this node represents a password, this field will hold the actual | 279 // A holder for the unencrypted data stored in an encrypted node. |
270 // decrypted password data. | 280 sync_pb::EntitySpecifics unencrypted_data_; |
| 281 |
| 282 // Same as |unencrypted_data_|, but for legacy password encryption. |
271 scoped_ptr<sync_pb::PasswordSpecificsData> password_data_; | 283 scoped_ptr<sync_pb::PasswordSpecificsData> password_data_; |
272 | 284 |
273 friend class SyncApiTest; | 285 friend class SyncApiTest; |
274 FRIEND_TEST_ALL_PREFIXES(SyncApiTest, GenerateSyncableHash); | 286 FRIEND_TEST_ALL_PREFIXES(SyncApiTest, GenerateSyncableHash); |
275 | 287 |
276 DISALLOW_COPY_AND_ASSIGN(BaseNode); | 288 DISALLOW_COPY_AND_ASSIGN(BaseNode); |
277 }; | 289 }; |
278 | 290 |
279 // WriteNode extends BaseNode to add mutation, and wraps | 291 // WriteNode extends BaseNode to add mutation, and wraps |
280 // syncable::MutableEntry. A WriteTransaction is needed to create a WriteNode. | 292 // syncable::MutableEntry. A WriteTransaction is needed to create a WriteNode. |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 void SetTypedUrlSpecifics(const sync_pb::TypedUrlSpecifics& specifics); | 387 void SetTypedUrlSpecifics(const sync_pb::TypedUrlSpecifics& specifics); |
376 | 388 |
377 // Set the extension specifics (id, update url, enabled state, etc). | 389 // Set the extension specifics (id, update url, enabled state, etc). |
378 // Should only be called if GetModelType() == EXTENSIONS. | 390 // Should only be called if GetModelType() == EXTENSIONS. |
379 void SetExtensionSpecifics(const sync_pb::ExtensionSpecifics& specifics); | 391 void SetExtensionSpecifics(const sync_pb::ExtensionSpecifics& specifics); |
380 | 392 |
381 // Set the session specifics (windows, tabs, navigations etc.). | 393 // Set the session specifics (windows, tabs, navigations etc.). |
382 // Should only be called if GetModelType() == SESSIONS. | 394 // Should only be called if GetModelType() == SESSIONS. |
383 void SetSessionSpecifics(const sync_pb::SessionSpecifics& specifics); | 395 void SetSessionSpecifics(const sync_pb::SessionSpecifics& specifics); |
384 | 396 |
| 397 // Resets the EntitySpecifics for this node based on the unencrypted data. |
| 398 // Will encrypt if necessary. |
| 399 void ResetFromSpecifics(); |
| 400 |
385 // Implementation of BaseNode's abstract virtual accessors. | 401 // Implementation of BaseNode's abstract virtual accessors. |
386 virtual const syncable::Entry* GetEntry() const; | 402 virtual const syncable::Entry* GetEntry() const; |
387 | 403 |
388 virtual const BaseTransaction* GetTransaction() const; | 404 virtual const BaseTransaction* GetTransaction() const; |
389 | 405 |
390 private: | 406 private: |
391 void* operator new(size_t size); // Node is meant for stack use only. | 407 void* operator new(size_t size); // Node is meant for stack use only. |
392 | 408 |
393 // Helper to set model type. This will clear any specifics data. | 409 // Helper to set model type. This will clear any specifics data. |
394 void PutModelType(syncable::ModelType model_type); | 410 void PutModelType(syncable::ModelType model_type); |
(...skipping 28 matching lines...) Expand all Loading... |
423 const sync_pb::ExtensionSpecifics& new_value); | 439 const sync_pb::ExtensionSpecifics& new_value); |
424 void PutSessionSpecificsAndMarkForSyncing( | 440 void PutSessionSpecificsAndMarkForSyncing( |
425 const sync_pb::SessionSpecifics& new_value); | 441 const sync_pb::SessionSpecifics& new_value); |
426 void PutSpecificsAndMarkForSyncing( | 442 void PutSpecificsAndMarkForSyncing( |
427 const sync_pb::EntitySpecifics& specifics); | 443 const sync_pb::EntitySpecifics& specifics); |
428 | 444 |
429 // Sets IS_UNSYNCED and SYNCING to ensure this entry is considered in an | 445 // Sets IS_UNSYNCED and SYNCING to ensure this entry is considered in an |
430 // upcoming commit pass. | 446 // upcoming commit pass. |
431 void MarkForSyncing(); | 447 void MarkForSyncing(); |
432 | 448 |
| 449 // Encrypt the specifics if the datatype requries it. |
| 450 void EncryptIfNecessary(sync_pb::EntitySpecifics* new_value); |
| 451 |
433 // The underlying syncable object which this class wraps. | 452 // The underlying syncable object which this class wraps. |
434 syncable::MutableEntry* entry_; | 453 syncable::MutableEntry* entry_; |
435 | 454 |
436 // The sync API transaction that is the parent of this node. | 455 // The sync API transaction that is the parent of this node. |
437 WriteTransaction* transaction_; | 456 WriteTransaction* transaction_; |
438 | 457 |
439 DISALLOW_COPY_AND_ASSIGN(WriteNode); | 458 DISALLOW_COPY_AND_ASSIGN(WriteNode); |
440 }; | 459 }; |
441 | 460 |
442 // ReadNode wraps a syncable::Entry to provide the functionality of a | 461 // ReadNode wraps a syncable::Entry to provide the functionality of a |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 // multiple threads interact with the same local sync repository (i.e. the | 593 // multiple threads interact with the same local sync repository (i.e. the |
575 // same sqlite database), they should share a single SyncManager instance. The | 594 // same sqlite database), they should share a single SyncManager instance. The |
576 // caller should typically create one SyncManager for the lifetime of a user | 595 // caller should typically create one SyncManager for the lifetime of a user |
577 // session. | 596 // session. |
578 class SyncManager { | 597 class SyncManager { |
579 public: | 598 public: |
580 // SyncInternal contains the implementation of SyncManager, while abstracting | 599 // SyncInternal contains the implementation of SyncManager, while abstracting |
581 // internal types from clients of the interface. | 600 // internal types from clients of the interface. |
582 class SyncInternal; | 601 class SyncInternal; |
583 | 602 |
584 // TODO(tim): Depending on how multi-type encryption pans out, maybe we | 603 // TODO(zea): One day get passwords playing nicely with the rest of encryption |
585 // should turn ChangeRecord itself into a class. Or we could template this | 604 // and get rid of this. |
586 // wrapper / add a templated method to return unencrypted protobufs. | 605 class ExtraPasswordChangeRecordData { |
587 class ExtraChangeRecordData { | |
588 public: | 606 public: |
589 ExtraChangeRecordData() {} | 607 explicit ExtraPasswordChangeRecordData( |
590 virtual ~ExtraChangeRecordData() {} | 608 const sync_pb::PasswordSpecificsData& data); |
| 609 virtual ~ExtraPasswordChangeRecordData(); |
| 610 const sync_pb::PasswordSpecificsData& unencrypted() { |
| 611 return unencrypted_; |
| 612 } |
| 613 private: |
| 614 sync_pb::PasswordSpecificsData unencrypted_; |
591 }; | 615 }; |
592 | 616 |
593 // ChangeRecord indicates a single item that changed as a result of a sync | 617 // ChangeRecord indicates a single item that changed as a result of a sync |
594 // operation. This gives the sync id of the node that changed, and the type | 618 // operation. This gives the sync id of the node that changed, and the type |
595 // of change. To get the actual property values after an ADD or UPDATE, the | 619 // of change. To get the actual property values after an ADD or UPDATE, the |
596 // client should get the node with InitByIdLookup(), using the provided id. | 620 // client should get the node with InitByIdLookup(), using the provided id. |
597 struct ChangeRecord { | 621 struct ChangeRecord { |
598 enum Action { | 622 enum Action { |
599 ACTION_ADD, | 623 ACTION_ADD, |
600 ACTION_DELETE, | 624 ACTION_DELETE, |
601 ACTION_UPDATE, | 625 ACTION_UPDATE, |
602 }; | 626 }; |
603 ChangeRecord(); | 627 ChangeRecord(); |
604 ~ChangeRecord(); | 628 ~ChangeRecord(); |
605 | 629 |
606 int64 id; | 630 int64 id; |
607 Action action; | 631 Action action; |
608 sync_pb::EntitySpecifics specifics; | 632 sync_pb::EntitySpecifics specifics; |
609 linked_ptr<ExtraChangeRecordData> extra; | 633 linked_ptr<ExtraPasswordChangeRecordData> extra; |
610 }; | |
611 | |
612 // Since PasswordSpecifics is just an encrypted blob, we extend to provide | |
613 // access to unencrypted bits. | |
614 class ExtraPasswordChangeRecordData : public ExtraChangeRecordData { | |
615 public: | |
616 explicit ExtraPasswordChangeRecordData( | |
617 const sync_pb::PasswordSpecificsData& data); | |
618 virtual ~ExtraPasswordChangeRecordData(); | |
619 const sync_pb::PasswordSpecificsData& unencrypted() { | |
620 return unencrypted_; | |
621 } | |
622 private: | |
623 sync_pb::PasswordSpecificsData unencrypted_; | |
624 }; | 634 }; |
625 | 635 |
626 // Status encapsulates detailed state about the internals of the SyncManager. | 636 // Status encapsulates detailed state about the internals of the SyncManager. |
627 struct Status { | 637 struct Status { |
628 // Summary is a distilled set of important information that the end-user may | 638 // Summary is a distilled set of important information that the end-user may |
629 // wish to be informed about (through UI, for example). Note that if a | 639 // wish to be informed about (through UI, for example). Note that if a |
630 // summary state requires user interaction (such as auth failures), more | 640 // summary state requires user interaction (such as auth failures), more |
631 // detailed information may be contained in additional status fields. | 641 // detailed information may be contained in additional status fields. |
632 enum Summary { | 642 enum Summary { |
633 // The internal instance is in an unrecognizable state. This should not | 643 // The internal instance is in an unrecognizable state. This should not |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
783 // The syncer thread has been resumed. | 793 // The syncer thread has been resumed. |
784 virtual void OnResumed() = 0; | 794 virtual void OnResumed() = 0; |
785 | 795 |
786 // We are no longer permitted to communicate with the server. Sync should | 796 // We are no longer permitted to communicate with the server. Sync should |
787 // be disabled and state cleaned up at once. This can happen for a number | 797 // be disabled and state cleaned up at once. This can happen for a number |
788 // of reasons, e.g. swapping from a test instance to production, or a | 798 // of reasons, e.g. swapping from a test instance to production, or a |
789 // global stop syncing operation has wiped the store. | 799 // global stop syncing operation has wiped the store. |
790 virtual void OnStopSyncingPermanently() = 0; | 800 virtual void OnStopSyncingPermanently() = 0; |
791 | 801 |
792 // After a request to clear server data, these callbacks are invoked to | 802 // After a request to clear server data, these callbacks are invoked to |
793 // indicate success or failure | 803 // indicate success or failure. |
794 virtual void OnClearServerDataSucceeded() = 0; | 804 virtual void OnClearServerDataSucceeded() = 0; |
795 virtual void OnClearServerDataFailed() = 0; | 805 virtual void OnClearServerDataFailed() = 0; |
796 | 806 |
| 807 // Called after we finish encrypting all appropriate datatypes. |
| 808 virtual void OnEncryptionComplete( |
| 809 const syncable::ModelTypeSet& encrypted_types) = 0; |
| 810 |
797 private: | 811 private: |
798 DISALLOW_COPY_AND_ASSIGN(Observer); | 812 DISALLOW_COPY_AND_ASSIGN(Observer); |
799 }; | 813 }; |
800 | 814 |
801 // Create an uninitialized SyncManager. Callers must Init() before using. | 815 // Create an uninitialized SyncManager. Callers must Init() before using. |
802 SyncManager(); | 816 SyncManager(); |
803 virtual ~SyncManager(); | 817 virtual ~SyncManager(); |
804 | 818 |
805 // Initialize the sync manager. |database_location| specifies the path of | 819 // Initialize the sync manager. |database_location| specifies the path of |
806 // the directory in which to locate a sqlite repository storing the syncer | 820 // 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... |
863 // passphrase gets applied as soon as possible. | 877 // passphrase gets applied as soon as possible. |
864 // If the passphrase in invalid, OnPassphraseRequired will be fired. | 878 // If the passphrase in invalid, OnPassphraseRequired will be fired. |
865 // Calling this metdod again is the appropriate course of action to "retry" | 879 // Calling this metdod again is the appropriate course of action to "retry" |
866 // with a new passphrase. | 880 // with a new passphrase. |
867 // |is_explicit| is true if the call is in response to the user explicitly | 881 // |is_explicit| is true if the call is in response to the user explicitly |
868 // setting a passphrase as opposed to implicitly (from the users' perspective) | 882 // setting a passphrase as opposed to implicitly (from the users' perspective) |
869 // using their Google Account password. An implicit SetPassphrase will *not* | 883 // using their Google Account password. An implicit SetPassphrase will *not* |
870 // *not* override an explicit passphrase set previously. | 884 // *not* override an explicit passphrase set previously. |
871 void SetPassphrase(const std::string& passphrase, bool is_explicit); | 885 void SetPassphrase(const std::string& passphrase, bool is_explicit); |
872 | 886 |
| 887 // Set the datatypes we want to encrypt and encrypt any nodes as necessary. |
| 888 void EncryptDataTypes(const syncable::ModelTypeSet& encrypted_types); |
| 889 |
873 // Requests the syncer thread to pause. The observer's OnPause | 890 // Requests the syncer thread to pause. The observer's OnPause |
874 // method will be called when the syncer thread is paused. Returns | 891 // method will be called when the syncer thread is paused. Returns |
875 // false if the syncer thread can not be paused (e.g. if it is not | 892 // false if the syncer thread can not be paused (e.g. if it is not |
876 // started). | 893 // started). |
877 bool RequestPause(); | 894 bool RequestPause(); |
878 | 895 |
879 // Requests the syncer thread to resume. The observer's OnResume | 896 // Requests the syncer thread to resume. The observer's OnResume |
880 // method will be called when the syncer thread is resumed. Returns | 897 // method will be called when the syncer thread is resumed. Returns |
881 // false if the syncer thread can not be resumed (e.g. if it is not | 898 // false if the syncer thread can not be resumed (e.g. if it is not |
882 // paused). | 899 // paused). |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
999 // This allows actual HttpPostProvider subclass implementations to be | 1016 // This allows actual HttpPostProvider subclass implementations to be |
1000 // reference counted, which is useful if a particular implementation uses | 1017 // reference counted, which is useful if a particular implementation uses |
1001 // multiple threads to serve network requests. | 1018 // multiple threads to serve network requests. |
1002 virtual void Destroy(HttpPostProviderInterface* http) = 0; | 1019 virtual void Destroy(HttpPostProviderInterface* http) = 0; |
1003 virtual ~HttpPostProviderFactory() { } | 1020 virtual ~HttpPostProviderFactory() { } |
1004 }; | 1021 }; |
1005 | 1022 |
1006 } // namespace sync_api | 1023 } // namespace sync_api |
1007 | 1024 |
1008 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNCAPI_H_ | 1025 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNCAPI_H_ |
OLD | NEW |