Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(203)

Side by Side Diff: chrome/browser/sync/engine/syncapi.h

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

Powered by Google App Engine
This is Rietveld 408576698