| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_SYNC_INTERNAL_API_SYNC_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_SYNC_INTERNAL_API_SYNC_MANAGER_H_ |
| 6 #define CHROME_BROWSER_SYNC_INTERNAL_API_SYNC_MANAGER_H_ | 6 #define CHROME_BROWSER_SYNC_INTERNAL_API_SYNC_MANAGER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> |
| 9 | 10 |
| 10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 11 #include "base/callback_old.h" | 12 #include "base/callback_old.h" |
| 12 #include "base/memory/linked_ptr.h" | 13 #include "chrome/browser/sync/internal_api/change_record.h" |
| 13 #include "chrome/browser/sync/internal_api/configure_reason.h" | 14 #include "chrome/browser/sync/internal_api/configure_reason.h" |
| 14 #include "chrome/browser/sync/protocol/password_specifics.pb.h" | |
| 15 #include "chrome/browser/sync/protocol/sync_protocol_error.h" | 15 #include "chrome/browser/sync/protocol/sync_protocol_error.h" |
| 16 #include "chrome/browser/sync/syncable/model_type.h" | 16 #include "chrome/browser/sync/syncable/model_type.h" |
| 17 #include "chrome/browser/sync/util/weak_handle.h" | 17 #include "chrome/browser/sync/util/weak_handle.h" |
| 18 #include "chrome/common/net/gaia/google_service_auth_error.h" | 18 #include "chrome/common/net/gaia/google_service_auth_error.h" |
| 19 | 19 |
| 20 class FilePath; | 20 class FilePath; |
| 21 | 21 |
| 22 namespace base { | 22 namespace base { |
| 23 class DictionaryValue; | 23 class DictionaryValue; |
| 24 } // namespace base | 24 } // namespace base |
| 25 | 25 |
| 26 namespace browser_sync { | 26 namespace browser_sync { |
| 27 class JsBackend; | 27 class JsBackend; |
| 28 class JsEventHandler; | 28 class JsEventHandler; |
| 29 class ModelSafeWorkerRegistrar; | 29 class ModelSafeWorkerRegistrar; |
| 30 | 30 |
| 31 namespace sessions { | 31 namespace sessions { |
| 32 struct SyncSessionSnapshot; | 32 struct SyncSessionSnapshot; |
| 33 } // namespace sessions | 33 } // namespace sessions |
| 34 } // namespace browser_sync | 34 } // namespace browser_sync |
| 35 | 35 |
| 36 namespace sync_notifier { | 36 namespace sync_notifier { |
| 37 class SyncNotifier; | 37 class SyncNotifier; |
| 38 } // namespace sync_notifier | 38 } // namespace sync_notifier |
| 39 | 39 |
| 40 namespace sync_pb { | |
| 41 class PasswordSpecificsData; | |
| 42 } // namespace sync_pb | |
| 43 | |
| 44 namespace sync_api { | 40 namespace sync_api { |
| 45 | 41 |
| 46 class BaseTransaction; | 42 class BaseTransaction; |
| 47 class HttpPostProviderFactory; | 43 class HttpPostProviderFactory; |
| 48 struct UserShare; | 44 struct UserShare; |
| 49 | 45 |
| 50 // Reasons due to which browser_sync::Cryptographer might require a passphrase. | 46 // Reasons due to which browser_sync::Cryptographer might require a passphrase. |
| 51 enum PassphraseRequiredReason { | 47 enum PassphraseRequiredReason { |
| 52 REASON_PASSPHRASE_NOT_REQUIRED = 0, // Initial value. | 48 REASON_PASSPHRASE_NOT_REQUIRED = 0, // Initial value. |
| 53 REASON_ENCRYPTION = 1, // The cryptographer requires a | 49 REASON_ENCRYPTION = 1, // The cryptographer requires a |
| (...skipping 20 matching lines...) Expand all Loading... |
| 74 // multiple threads interact with the same local sync repository (i.e. the | 70 // multiple threads interact with the same local sync repository (i.e. the |
| 75 // same sqlite database), they should share a single SyncManager instance. The | 71 // same sqlite database), they should share a single SyncManager instance. The |
| 76 // caller should typically create one SyncManager for the lifetime of a user | 72 // caller should typically create one SyncManager for the lifetime of a user |
| 77 // session. | 73 // session. |
| 78 class SyncManager { | 74 class SyncManager { |
| 79 public: | 75 public: |
| 80 // SyncInternal contains the implementation of SyncManager, while abstracting | 76 // SyncInternal contains the implementation of SyncManager, while abstracting |
| 81 // internal types from clients of the interface. | 77 // internal types from clients of the interface. |
| 82 class SyncInternal; | 78 class SyncInternal; |
| 83 | 79 |
| 84 // TODO(zea): One day get passwords playing nicely with the rest of encryption | |
| 85 // and get rid of this. | |
| 86 class ExtraPasswordChangeRecordData { | |
| 87 public: | |
| 88 ExtraPasswordChangeRecordData(); | |
| 89 explicit ExtraPasswordChangeRecordData( | |
| 90 const sync_pb::PasswordSpecificsData& data); | |
| 91 virtual ~ExtraPasswordChangeRecordData(); | |
| 92 | |
| 93 // Transfers ownership of the DictionaryValue to the caller. | |
| 94 virtual base::DictionaryValue* ToValue() const; | |
| 95 | |
| 96 const sync_pb::PasswordSpecificsData& unencrypted() const; | |
| 97 private: | |
| 98 sync_pb::PasswordSpecificsData unencrypted_; | |
| 99 }; | |
| 100 | |
| 101 // ChangeRecord indicates a single item that changed as a result of a sync | |
| 102 // operation. This gives the sync id of the node that changed, and the type | |
| 103 // of change. To get the actual property values after an ADD or UPDATE, the | |
| 104 // client should get the node with InitByIdLookup(), using the provided id. | |
| 105 struct ChangeRecord { | |
| 106 enum Action { | |
| 107 ACTION_ADD, | |
| 108 ACTION_DELETE, | |
| 109 ACTION_UPDATE, | |
| 110 }; | |
| 111 ChangeRecord(); | |
| 112 ~ChangeRecord(); | |
| 113 | |
| 114 // Transfers ownership of the DictionaryValue to the caller. | |
| 115 base::DictionaryValue* ToValue(const BaseTransaction* trans) const; | |
| 116 | |
| 117 int64 id; | |
| 118 Action action; | |
| 119 sync_pb::EntitySpecifics specifics; | |
| 120 linked_ptr<ExtraPasswordChangeRecordData> extra; | |
| 121 }; | |
| 122 | |
| 123 // Status encapsulates detailed state about the internals of the SyncManager. | 80 // Status encapsulates detailed state about the internals of the SyncManager. |
| 124 struct Status { | 81 struct Status { |
| 125 // Summary is a distilled set of important information that the end-user may | 82 // Summary is a distilled set of important information that the end-user may |
| 126 // wish to be informed about (through UI, for example). Note that if a | 83 // wish to be informed about (through UI, for example). Note that if a |
| 127 // summary state requires user interaction (such as auth failures), more | 84 // summary state requires user interaction (such as auth failures), more |
| 128 // detailed information may be contained in additional status fields. | 85 // detailed information may be contained in additional status fields. |
| 129 enum Summary { | 86 enum Summary { |
| 130 // The internal instance is in an unrecognizable state. This should not | 87 // The internal instance is in an unrecognizable state. This should not |
| 131 // happen. | 88 // happen. |
| 132 INVALID = 0, | 89 INVALID = 0, |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 // 2. Updates to existing items with synced parents & predecessors. | 191 // 2. Updates to existing items with synced parents & predecessors. |
| 235 // 3. New items with synced parents & predecessors. | 192 // 3. New items with synced parents & predecessors. |
| 236 // 4. Items with parents & predecessors in |changes|. | 193 // 4. Items with parents & predecessors in |changes|. |
| 237 // 5. Repeat #4 until all items are in |changes|. | 194 // 5. Repeat #4 until all items are in |changes|. |
| 238 // | 195 // |
| 239 // Thus, an implementation of OnChangesApplied should be able to | 196 // Thus, an implementation of OnChangesApplied should be able to |
| 240 // process the change records in the order without having to worry about | 197 // process the change records in the order without having to worry about |
| 241 // forward dependencies. But since deletions come before reparent | 198 // forward dependencies. But since deletions come before reparent |
| 242 // operations, a delete may temporarily orphan a node that is | 199 // operations, a delete may temporarily orphan a node that is |
| 243 // updated later in the list. | 200 // updated later in the list. |
| 244 virtual void OnChangesApplied(syncable::ModelType model_type, | 201 virtual void OnChangesApplied( |
| 245 const BaseTransaction* trans, | 202 syncable::ModelType model_type, |
| 246 const ChangeRecord* changes, | 203 const BaseTransaction* trans, |
| 247 int change_count) = 0; | 204 const ImmutableChangeRecordList& changes) = 0; |
| 248 | 205 |
| 249 // OnChangesComplete gets called when the TransactionComplete event is | 206 // OnChangesComplete gets called when the TransactionComplete event is |
| 250 // posted (after OnChangesApplied finishes), after the transaction lock | 207 // posted (after OnChangesApplied finishes), after the transaction lock |
| 251 // and the change channel mutex are released. | 208 // and the change channel mutex are released. |
| 252 // | 209 // |
| 253 // The purpose of this function is to support processors that require | 210 // The purpose of this function is to support processors that require |
| 254 // split-transactions changes. For example, if a model processor wants to | 211 // split-transactions changes. For example, if a model processor wants to |
| 255 // perform blocking I/O due to a change, it should calculate the changes | 212 // perform blocking I/O due to a change, it should calculate the changes |
| 256 // while holding the transaction lock (from within OnChangesApplied), buffer | 213 // while holding the transaction lock (from within OnChangesApplied), buffer |
| 257 // those changes, let the transaction fall out of scope, and then commit | 214 // those changes, let the transaction fall out of scope, and then commit |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 }; | 514 }; |
| 558 | 515 |
| 559 bool InitialSyncEndedForTypes(syncable::ModelTypeSet types, UserShare* share); | 516 bool InitialSyncEndedForTypes(syncable::ModelTypeSet types, UserShare* share); |
| 560 | 517 |
| 561 // Returns the string representation of a PassphraseRequiredReason value. | 518 // Returns the string representation of a PassphraseRequiredReason value. |
| 562 std::string PassphraseRequiredReasonToString(PassphraseRequiredReason reason); | 519 std::string PassphraseRequiredReasonToString(PassphraseRequiredReason reason); |
| 563 | 520 |
| 564 } // namespace sync_api | 521 } // namespace sync_api |
| 565 | 522 |
| 566 #endif // CHROME_BROWSER_SYNC_INTERNAL_API_SYNC_MANAGER_H_ | 523 #endif // CHROME_BROWSER_SYNC_INTERNAL_API_SYNC_MANAGER_H_ |
| OLD | NEW |