OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 #include <vector> | 42 #include <vector> |
43 | 43 |
44 #include "base/basictypes.h" | 44 #include "base/basictypes.h" |
45 #include "base/file_path.h" | 45 #include "base/file_path.h" |
46 #include "base/gtest_prod_util.h" | 46 #include "base/gtest_prod_util.h" |
47 #include "base/scoped_ptr.h" | 47 #include "base/scoped_ptr.h" |
48 #include "build/build_config.h" | 48 #include "build/build_config.h" |
49 #include "chrome/browser/google_service_auth_error.h" | 49 #include "chrome/browser/google_service_auth_error.h" |
50 #include "chrome/browser/sync/notification_method.h" | 50 #include "chrome/browser/sync/notification_method.h" |
51 #include "chrome/browser/sync/syncable/model_type.h" | 51 #include "chrome/browser/sync/syncable/model_type.h" |
| 52 #include "chrome/browser/sync/util/cryptographer.h" |
52 #include "googleurl/src/gurl.h" | 53 #include "googleurl/src/gurl.h" |
53 | 54 |
54 namespace browser_sync { | 55 namespace browser_sync { |
55 class ModelSafeWorkerRegistrar; | 56 class ModelSafeWorkerRegistrar; |
56 | 57 |
57 namespace sessions { | 58 namespace sessions { |
58 struct SyncSessionSnapshot; | 59 struct SyncSessionSnapshot; |
59 } | 60 } |
60 } | 61 } |
61 | 62 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 // Getter specific to the AUTOFILL datatype. Returns protobuf | 181 // Getter specific to the AUTOFILL datatype. Returns protobuf |
181 // data. Can only be called if GetModelType() == AUTOFILL. | 182 // data. Can only be called if GetModelType() == AUTOFILL. |
182 const sync_pb::AutofillSpecifics& GetAutofillSpecifics() const; | 183 const sync_pb::AutofillSpecifics& GetAutofillSpecifics() const; |
183 | 184 |
184 // Getter specific to the NIGORI datatype. Returns protobuf | 185 // Getter specific to the NIGORI datatype. Returns protobuf |
185 // data. Can only be called if GetModelType() == NIGORI. | 186 // data. Can only be called if GetModelType() == NIGORI. |
186 const sync_pb::NigoriSpecifics& GetNigoriSpecifics() const; | 187 const sync_pb::NigoriSpecifics& GetNigoriSpecifics() const; |
187 | 188 |
188 // Getter specific to the PASSWORD datatype. Returns protobuf | 189 // Getter specific to the PASSWORD datatype. Returns protobuf |
189 // data. Can only be called if GetModelType() == PASSWORD. | 190 // data. Can only be called if GetModelType() == PASSWORD. |
190 bool GetPasswordSpecifics(sync_pb::PasswordSpecificsData*) const; | 191 const sync_pb::PasswordSpecificsData& GetPasswordSpecifics() const; |
191 | 192 |
192 // Getter specific to the PREFERENCE datatype. Returns protobuf | 193 // Getter specific to the PREFERENCE datatype. Returns protobuf |
193 // data. Can only be called if GetModelType() == PREFERENCE. | 194 // data. Can only be called if GetModelType() == PREFERENCE. |
194 const sync_pb::PreferenceSpecifics& GetPreferenceSpecifics() const; | 195 const sync_pb::PreferenceSpecifics& GetPreferenceSpecifics() const; |
195 | 196 |
196 // Getter specific to the THEME datatype. Returns protobuf | 197 // Getter specific to the THEME datatype. Returns protobuf |
197 // data. Can only be called if GetModelType() == THEME. | 198 // data. Can only be called if GetModelType() == THEME. |
198 const sync_pb::ThemeSpecifics& GetThemeSpecifics() const; | 199 const sync_pb::ThemeSpecifics& GetThemeSpecifics() const; |
199 | 200 |
200 // Getter specific to the TYPED_URLS datatype. Returns protobuf | 201 // Getter specific to the TYPED_URLS datatype. Returns protobuf |
(...skipping 24 matching lines...) Expand all Loading... |
225 virtual const BaseTransaction* GetTransaction() const = 0; | 226 virtual const BaseTransaction* GetTransaction() const = 0; |
226 | 227 |
227 protected: | 228 protected: |
228 BaseNode(); | 229 BaseNode(); |
229 virtual ~BaseNode(); | 230 virtual ~BaseNode(); |
230 // The server has a size limit on client tags, so we generate a fixed length | 231 // The server has a size limit on client tags, so we generate a fixed length |
231 // hash locally. This also ensures that ModelTypes have unique namespaces. | 232 // hash locally. This also ensures that ModelTypes have unique namespaces. |
232 static std::string GenerateSyncableHash(syncable::ModelType model_type, | 233 static std::string GenerateSyncableHash(syncable::ModelType model_type, |
233 const std::string& client_tag); | 234 const std::string& client_tag); |
234 | 235 |
| 236 // Determines whether part of the entry is encrypted, and if so attempts to |
| 237 // decrypt it. Unless decryption is necessary and fails, this will always |
| 238 // return |true|. |
| 239 bool DecryptIfNecessary(syncable::Entry* entry); |
| 240 |
235 private: | 241 private: |
236 // Node is meant for stack use only. | 242 // Node is meant for stack use only. |
237 void* operator new(size_t size); | 243 void* operator new(size_t size); |
238 | 244 |
| 245 // If this node represents a password, this field will hold the actual |
| 246 // decrypted password data. |
| 247 scoped_ptr<sync_pb::PasswordSpecificsData> password_data_; |
| 248 |
239 friend class SyncApiTest; | 249 friend class SyncApiTest; |
240 FRIEND_TEST_ALL_PREFIXES(SyncApiTest, GenerateSyncableHash); | 250 FRIEND_TEST_ALL_PREFIXES(SyncApiTest, GenerateSyncableHash); |
241 | 251 |
242 DISALLOW_COPY_AND_ASSIGN(BaseNode); | 252 DISALLOW_COPY_AND_ASSIGN(BaseNode); |
243 }; | 253 }; |
244 | 254 |
245 // WriteNode extends BaseNode to add mutation, and wraps | 255 // WriteNode extends BaseNode to add mutation, and wraps |
246 // syncable::MutableEntry. A WriteTransaction is needed to create a WriteNode. | 256 // syncable::MutableEntry. A WriteTransaction is needed to create a WriteNode. |
247 class WriteNode : public BaseNode { | 257 class WriteNode : public BaseNode { |
248 public: | 258 public: |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 // operations are performed by creating ReadNode and WriteNode instances using | 445 // operations are performed by creating ReadNode and WriteNode instances using |
436 // the transaction. These transaction classes wrap identically named classes in | 446 // the transaction. These transaction classes wrap identically named classes in |
437 // syncable, and are used in a similar way. Unlike syncable::BaseTransaction, | 447 // syncable, and are used in a similar way. Unlike syncable::BaseTransaction, |
438 // whose construction requires an explicit syncable::ScopedDirLookup, a sync | 448 // whose construction requires an explicit syncable::ScopedDirLookup, a sync |
439 // API BaseTransaction creates its own ScopedDirLookup implicitly. | 449 // API BaseTransaction creates its own ScopedDirLookup implicitly. |
440 class BaseTransaction { | 450 class BaseTransaction { |
441 public: | 451 public: |
442 // Provide access to the underlying syncable.h objects from BaseNode. | 452 // Provide access to the underlying syncable.h objects from BaseNode. |
443 virtual syncable::BaseTransaction* GetWrappedTrans() const = 0; | 453 virtual syncable::BaseTransaction* GetWrappedTrans() const = 0; |
444 const syncable::ScopedDirLookup& GetLookup() const { return *lookup_; } | 454 const syncable::ScopedDirLookup& GetLookup() const { return *lookup_; } |
| 455 browser_sync::Cryptographer* GetCryptographer() const { |
| 456 return cryptographer_; |
| 457 } |
445 | 458 |
446 protected: | 459 protected: |
447 // The ScopedDirLookup is created in the constructor and destroyed | 460 // The ScopedDirLookup is created in the constructor and destroyed |
448 // in the destructor. Creation of the ScopedDirLookup is not expected | 461 // in the destructor. Creation of the ScopedDirLookup is not expected |
449 // to fail. | 462 // to fail. |
450 explicit BaseTransaction(UserShare* share); | 463 explicit BaseTransaction(UserShare* share); |
451 virtual ~BaseTransaction(); | 464 virtual ~BaseTransaction(); |
452 | 465 |
453 private: | 466 private: |
454 // A syncable ScopedDirLookup, which is the parent of syncable transactions. | 467 // A syncable ScopedDirLookup, which is the parent of syncable transactions. |
455 syncable::ScopedDirLookup* lookup_; | 468 syncable::ScopedDirLookup* lookup_; |
456 | 469 |
| 470 browser_sync::Cryptographer* cryptographer_; |
| 471 |
457 DISALLOW_COPY_AND_ASSIGN(BaseTransaction); | 472 DISALLOW_COPY_AND_ASSIGN(BaseTransaction); |
458 }; | 473 }; |
459 | 474 |
460 // Sync API's ReadTransaction is a read-only BaseTransaction. It wraps | 475 // Sync API's ReadTransaction is a read-only BaseTransaction. It wraps |
461 // a syncable::ReadTransaction. | 476 // a syncable::ReadTransaction. |
462 class ReadTransaction : public BaseTransaction { | 477 class ReadTransaction : public BaseTransaction { |
463 public: | 478 public: |
464 // Start a new read-only transaction on the specified repository. | 479 // Start a new read-only transaction on the specified repository. |
465 explicit ReadTransaction(UserShare* share); | 480 explicit ReadTransaction(UserShare* share); |
466 virtual ~ReadTransaction(); | 481 virtual ~ReadTransaction(); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 int change_count) = 0; | 664 int change_count) = 0; |
650 | 665 |
651 // A round-trip sync-cycle took place and the syncer has resolved any | 666 // A round-trip sync-cycle took place and the syncer has resolved any |
652 // conflicts that may have arisen. | 667 // conflicts that may have arisen. |
653 virtual void OnSyncCycleCompleted( | 668 virtual void OnSyncCycleCompleted( |
654 const browser_sync::sessions::SyncSessionSnapshot* snapshot) = 0; | 669 const browser_sync::sessions::SyncSessionSnapshot* snapshot) = 0; |
655 | 670 |
656 // Called when user interaction may be required due to an auth problem. | 671 // Called when user interaction may be required due to an auth problem. |
657 virtual void OnAuthError(const GoogleServiceAuthError& auth_error) = 0; | 672 virtual void OnAuthError(const GoogleServiceAuthError& auth_error) = 0; |
658 | 673 |
| 674 // Called when user interaction is required to obtain a valid passphrase. |
| 675 virtual void OnPassphraseRequired() = 0; |
| 676 |
| 677 // Called when the passphrase provided by the user has been accepted and is |
| 678 // now used to encrypt sync data. |
| 679 virtual void OnPassphraseAccepted() = 0; |
| 680 |
659 // Called when initialization is complete to the point that SyncManager can | 681 // Called when initialization is complete to the point that SyncManager can |
660 // process changes. This does not necessarily mean authentication succeeded | 682 // process changes. This does not necessarily mean authentication succeeded |
661 // or that the SyncManager is online. | 683 // or that the SyncManager is online. |
662 // IMPORTANT: Creating any type of transaction before receiving this | 684 // IMPORTANT: Creating any type of transaction before receiving this |
663 // notification is illegal! | 685 // notification is illegal! |
664 // WARNING: Calling methods on the SyncManager before receiving this | 686 // WARNING: Calling methods on the SyncManager before receiving this |
665 // message, unless otherwise specified, produces undefined behavior. | 687 // message, unless otherwise specified, produces undefined behavior. |
666 virtual void OnInitializationComplete() = 0; | 688 virtual void OnInitializationComplete() = 0; |
667 | 689 |
668 // The syncer thread has been paused. | 690 // The syncer thread has been paused. |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 // The Observer may, in turn, decide to try again with new | 767 // The Observer may, in turn, decide to try again with new |
746 // credentials. Calling this method again is the appropriate course of action | 768 // credentials. Calling this method again is the appropriate course of action |
747 // to "retry". | 769 // to "retry". |
748 // |username|, |password|, and |captcha| are owned by the caller. | 770 // |username|, |password|, and |captcha| are owned by the caller. |
749 void Authenticate(const char* username, const char* password, | 771 void Authenticate(const char* username, const char* password, |
750 const char* captcha); | 772 const char* captcha); |
751 | 773 |
752 // Start the SyncerThread. | 774 // Start the SyncerThread. |
753 void StartSyncing(); | 775 void StartSyncing(); |
754 | 776 |
| 777 // Attempt to set the passphrase. If the passphrase is valid, |
| 778 // OnPassphraseAccepted will be fired to notify the ProfileSyncService and the |
| 779 // syncer will be nudged so that any update that was waiting for this |
| 780 // passphrase gets applied as soon as possible. |
| 781 // If the passphrase in invalid, OnPassphraseRequired will be fired. |
| 782 // Calling this metdod again is the appropriate course of action to "retry" |
| 783 // with a new passphrase. |
| 784 void SetPassphrase(const std::string& passphrase); |
| 785 |
755 // Requests the syncer thread to pause. The observer's OnPause | 786 // Requests the syncer thread to pause. The observer's OnPause |
756 // method will be called when the syncer thread is paused. Returns | 787 // method will be called when the syncer thread is paused. Returns |
757 // false if the syncer thread can not be paused (e.g. if it is not | 788 // false if the syncer thread can not be paused (e.g. if it is not |
758 // started). | 789 // started). |
759 bool RequestPause(); | 790 bool RequestPause(); |
760 | 791 |
761 // Requests the syncer thread to resume. The observer's OnResume | 792 // Requests the syncer thread to resume. The observer's OnResume |
762 // method will be called when the syncer thread is resumed. Returns | 793 // method will be called when the syncer thread is resumed. Returns |
763 // false if the syncer thread can not be resumed (e.g. if it is not | 794 // false if the syncer thread can not be resumed (e.g. if it is not |
764 // paused). | 795 // paused). |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
879 // This allows actual HttpPostProvider subclass implementations to be | 910 // This allows actual HttpPostProvider subclass implementations to be |
880 // reference counted, which is useful if a particular implementation uses | 911 // reference counted, which is useful if a particular implementation uses |
881 // multiple threads to serve network requests. | 912 // multiple threads to serve network requests. |
882 virtual void Destroy(HttpPostProviderInterface* http) = 0; | 913 virtual void Destroy(HttpPostProviderInterface* http) = 0; |
883 virtual ~HttpPostProviderFactory() { } | 914 virtual ~HttpPostProviderFactory() { } |
884 }; | 915 }; |
885 | 916 |
886 } // namespace sync_api | 917 } // namespace sync_api |
887 | 918 |
888 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNCAPI_H_ | 919 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNCAPI_H_ |
OLD | NEW |