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