| OLD | NEW | 
|---|
|  | (Empty) | 
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |  | 
| 2 // Use of this source code is governed by a BSD-style license that can be |  | 
| 3 // found in the LICENSE file. |  | 
| 4 |  | 
| 5 #ifndef CHROME_BROWSER_SYNC_INTERNAL_API_SYNC_MANAGER_H_ |  | 
| 6 #define CHROME_BROWSER_SYNC_INTERNAL_API_SYNC_MANAGER_H_ |  | 
| 7 |  | 
| 8 #include <string> |  | 
| 9 #include <vector> |  | 
| 10 |  | 
| 11 #include "base/basictypes.h" |  | 
| 12 #include "base/callback_forward.h" |  | 
| 13 #include "base/file_path.h" |  | 
| 14 #include "base/memory/ref_counted.h" |  | 
| 15 #include "base/task_runner.h" |  | 
| 16 #include "base/threading/thread_checker.h" |  | 
| 17 #include "base/time.h" |  | 
| 18 #include "chrome/browser/sync/internal_api/change_record.h" |  | 
| 19 #include "chrome/browser/sync/internal_api/configure_reason.h" |  | 
| 20 #include "sync/protocol/sync_protocol_error.h" |  | 
| 21 #include "sync/syncable/model_type.h" |  | 
| 22 #include "sync/util/report_unrecoverable_error_function.h" |  | 
| 23 #include "sync/util/unrecoverable_error_handler.h" |  | 
| 24 #include "sync/util/weak_handle.h" |  | 
| 25 |  | 
| 26 namespace browser_sync { |  | 
| 27 class Encryptor; |  | 
| 28 class ExtensionsActivityMonitor; |  | 
| 29 class JsBackend; |  | 
| 30 class JsEventHandler; |  | 
| 31 class ModelSafeWorkerRegistrar; |  | 
| 32 |  | 
| 33 namespace sessions { |  | 
| 34 struct SyncSessionSnapshot; |  | 
| 35 }  // namespace sessions |  | 
| 36 }  // namespace browser_sync |  | 
| 37 |  | 
| 38 namespace sync_notifier { |  | 
| 39 class SyncNotifier; |  | 
| 40 }  // namespace sync_notifier |  | 
| 41 |  | 
| 42 namespace sync_pb { |  | 
| 43 class EncryptedData; |  | 
| 44 }  // namespace sync_pb |  | 
| 45 |  | 
| 46 namespace sync_api { |  | 
| 47 |  | 
| 48 class BaseTransaction; |  | 
| 49 class HttpPostProviderFactory; |  | 
| 50 struct UserShare; |  | 
| 51 |  | 
| 52 // Used by SyncManager::OnConnectionStatusChange(). |  | 
| 53 enum ConnectionStatus { |  | 
| 54   CONNECTION_OK, |  | 
| 55   CONNECTION_AUTH_ERROR, |  | 
| 56   CONNECTION_SERVER_ERROR |  | 
| 57 }; |  | 
| 58 |  | 
| 59 // Reasons due to which browser_sync::Cryptographer might require a passphrase. |  | 
| 60 enum PassphraseRequiredReason { |  | 
| 61   REASON_PASSPHRASE_NOT_REQUIRED = 0,  // Initial value. |  | 
| 62   REASON_ENCRYPTION = 1,               // The cryptographer requires a |  | 
| 63                                        // passphrase for its first attempt at |  | 
| 64                                        // encryption. Happens only during |  | 
| 65                                        // migration or upgrade. |  | 
| 66   REASON_DECRYPTION = 2,               // The cryptographer requires a |  | 
| 67                                        // passphrase for its first attempt at |  | 
| 68                                        // decryption. |  | 
| 69 }; |  | 
| 70 |  | 
| 71 |  | 
| 72 // Contains everything needed to talk to and identify a user account. |  | 
| 73 struct SyncCredentials { |  | 
| 74   std::string email; |  | 
| 75   std::string sync_token; |  | 
| 76 }; |  | 
| 77 |  | 
| 78 // SyncManager encapsulates syncable::Directory and serves as the parent of all |  | 
| 79 // other objects in the sync API.  If multiple threads interact with the same |  | 
| 80 // local sync repository (i.e. the same sqlite database), they should share a |  | 
| 81 // single SyncManager instance.  The caller should typically create one |  | 
| 82 // SyncManager for the lifetime of a user session. |  | 
| 83 // |  | 
| 84 // Unless stated otherwise, all methods of SyncManager should be called on the |  | 
| 85 // same thread. |  | 
| 86 class SyncManager { |  | 
| 87  public: |  | 
| 88   // SyncInternal contains the implementation of SyncManager, while abstracting |  | 
| 89   // internal types from clients of the interface. |  | 
| 90   class SyncInternal; |  | 
| 91 |  | 
| 92   // Status encapsulates detailed state about the internals of the SyncManager. |  | 
| 93   struct Status { |  | 
| 94     Status(); |  | 
| 95     ~Status(); |  | 
| 96 |  | 
| 97     bool notifications_enabled;  // True only if subscribed for notifications. |  | 
| 98 |  | 
| 99     // Notifications counters updated by the actions in synapi. |  | 
| 100     int notifications_received; |  | 
| 101 |  | 
| 102     browser_sync::SyncProtocolError sync_protocol_error; |  | 
| 103 |  | 
| 104     // Number of unsynced items counted at the start of most recent sync cycle. |  | 
| 105     int unsynced_count; |  | 
| 106 |  | 
| 107     // Number of encryption conflicts counted during most recent sync cycle. |  | 
| 108     int encryption_conflicts; |  | 
| 109 |  | 
| 110     // Number of hierarchy conflicts counted during most recent sync cycle. |  | 
| 111     int hierarchy_conflicts; |  | 
| 112 |  | 
| 113     // Number of simple conflicts counted during most recent sync cycle. |  | 
| 114     int simple_conflicts; |  | 
| 115 |  | 
| 116     // Number of items the server refused to commit due to conflict during most |  | 
| 117     // recent sync cycle. |  | 
| 118     int server_conflicts; |  | 
| 119 |  | 
| 120     // Number of items successfully committed during most recent sync cycle. |  | 
| 121     int committed_count; |  | 
| 122 |  | 
| 123     bool syncing; |  | 
| 124     // True after a client has done a first sync. |  | 
| 125     bool initial_sync_ended; |  | 
| 126 |  | 
| 127     // Total updates available.  If zero, nothing left to download. |  | 
| 128     int64 updates_available; |  | 
| 129     // Total updates received by the syncer since browser start. |  | 
| 130     int updates_received; |  | 
| 131     // Total updates received that are echoes of our own changes. |  | 
| 132     int reflected_updates_received; |  | 
| 133 |  | 
| 134     // Of updates_received, how many were tombstones. |  | 
| 135     int tombstone_updates_received; |  | 
| 136 |  | 
| 137     // Total number of overwrites due to conflict resolver since browser start. |  | 
| 138     int num_local_overwrites_total; |  | 
| 139     int num_server_overwrites_total; |  | 
| 140 |  | 
| 141     // Count of empty and non empty getupdates; |  | 
| 142     int nonempty_get_updates; |  | 
| 143     int empty_get_updates; |  | 
| 144 |  | 
| 145     // Count of sync cycles that successfully committed items; |  | 
| 146     int sync_cycles_with_commits; |  | 
| 147     int sync_cycles_without_commits; |  | 
| 148 |  | 
| 149     // Count of useless and useful syncs we perform. |  | 
| 150     int useless_sync_cycles; |  | 
| 151     int useful_sync_cycles; |  | 
| 152 |  | 
| 153     // Encryption related. |  | 
| 154     syncable::ModelTypeSet encrypted_types; |  | 
| 155     bool cryptographer_ready; |  | 
| 156     bool crypto_has_pending_keys; |  | 
| 157 |  | 
| 158     // The unique identifer for this client. |  | 
| 159     std::string unique_id; |  | 
| 160   }; |  | 
| 161 |  | 
| 162   // An interface the embedding application implements to be notified |  | 
| 163   // on change events.  Note that these methods may be called on *any* |  | 
| 164   // thread. |  | 
| 165   class ChangeDelegate { |  | 
| 166    public: |  | 
| 167     // Notify the delegate that changes have been applied to the sync model. |  | 
| 168     // |  | 
| 169     // This will be invoked on the same thread as on which ApplyChanges was |  | 
| 170     // called. |changes| is an array of size |change_count|, and contains the |  | 
| 171     // ID of each individual item that was changed. |changes| exists only for |  | 
| 172     // the duration of the call. If items of multiple data types change at |  | 
| 173     // the same time, this method is invoked once per data type and |changes| |  | 
| 174     // is restricted to items of the ModelType indicated by |model_type|. |  | 
| 175     // Because the observer is passed a |trans|, the observer can assume a |  | 
| 176     // read lock on the sync model that will be released after the function |  | 
| 177     // returns. |  | 
| 178     // |  | 
| 179     // The SyncManager constructs |changes| in the following guaranteed order: |  | 
| 180     // |  | 
| 181     // 1. Deletions, from leaves up to parents. |  | 
| 182     // 2. Updates to existing items with synced parents & predecessors. |  | 
| 183     // 3. New items with synced parents & predecessors. |  | 
| 184     // 4. Items with parents & predecessors in |changes|. |  | 
| 185     // 5. Repeat #4 until all items are in |changes|. |  | 
| 186     // |  | 
| 187     // Thus, an implementation of OnChangesApplied should be able to |  | 
| 188     // process the change records in the order without having to worry about |  | 
| 189     // forward dependencies.  But since deletions come before reparent |  | 
| 190     // operations, a delete may temporarily orphan a node that is |  | 
| 191     // updated later in the list. |  | 
| 192     virtual void OnChangesApplied( |  | 
| 193         syncable::ModelType model_type, |  | 
| 194         const BaseTransaction* trans, |  | 
| 195         const ImmutableChangeRecordList& changes) = 0; |  | 
| 196 |  | 
| 197     // OnChangesComplete gets called when the TransactionComplete event is |  | 
| 198     // posted (after OnChangesApplied finishes), after the transaction lock |  | 
| 199     // and the change channel mutex are released. |  | 
| 200     // |  | 
| 201     // The purpose of this function is to support processors that require |  | 
| 202     // split-transactions changes. For example, if a model processor wants to |  | 
| 203     // perform blocking I/O due to a change, it should calculate the changes |  | 
| 204     // while holding the transaction lock (from within OnChangesApplied), buffer |  | 
| 205     // those changes, let the transaction fall out of scope, and then commit |  | 
| 206     // those changes from within OnChangesComplete (postponing the blocking |  | 
| 207     // I/O to when it no longer holds any lock). |  | 
| 208     virtual void OnChangesComplete(syncable::ModelType model_type) = 0; |  | 
| 209 |  | 
| 210    protected: |  | 
| 211     virtual ~ChangeDelegate(); |  | 
| 212   }; |  | 
| 213 |  | 
| 214   // Like ChangeDelegate, except called only on the sync thread and |  | 
| 215   // not while a transaction is held.  For objects that want to know |  | 
| 216   // when changes happen, but don't need to process them. |  | 
| 217   class ChangeObserver { |  | 
| 218    public: |  | 
| 219     // Ids referred to in |changes| may or may not be in the write |  | 
| 220     // transaction specified by |write_transaction_id|.  If they're |  | 
| 221     // not, that means that the node didn't actually change, but we |  | 
| 222     // marked them as changed for some other reason (e.g., siblings of |  | 
| 223     // re-ordered nodes). |  | 
| 224     // |  | 
| 225     // TODO(sync, long-term): Ideally, ChangeDelegate/Observer would |  | 
| 226     // be passed a transformed version of EntryKernelMutation instead |  | 
| 227     // of a transaction that would have to be used to look up the |  | 
| 228     // changed nodes.  That is, ChangeDelegate::OnChangesApplied() |  | 
| 229     // would still be called under the transaction, but all the needed |  | 
| 230     // data will be passed down. |  | 
| 231     // |  | 
| 232     // Even more ideally, we would have sync semantics such that we'd |  | 
| 233     // be able to apply changes without being under a transaction. |  | 
| 234     // But that's a ways off... |  | 
| 235     virtual void OnChangesApplied( |  | 
| 236         syncable::ModelType model_type, |  | 
| 237         int64 write_transaction_id, |  | 
| 238         const ImmutableChangeRecordList& changes) = 0; |  | 
| 239 |  | 
| 240     virtual void OnChangesComplete(syncable::ModelType model_type) = 0; |  | 
| 241 |  | 
| 242    protected: |  | 
| 243     virtual ~ChangeObserver(); |  | 
| 244   }; |  | 
| 245 |  | 
| 246   // An interface the embedding application implements to receive |  | 
| 247   // notifications from the SyncManager.  Register an observer via |  | 
| 248   // SyncManager::AddObserver.  All methods are called only on the |  | 
| 249   // sync thread. |  | 
| 250   class Observer { |  | 
| 251    public: |  | 
| 252     // A round-trip sync-cycle took place and the syncer has resolved any |  | 
| 253     // conflicts that may have arisen. |  | 
| 254     virtual void OnSyncCycleCompleted( |  | 
| 255         const browser_sync::sessions::SyncSessionSnapshot* snapshot) = 0; |  | 
| 256 |  | 
| 257     // Called when the status of the connection to the sync server has |  | 
| 258     // changed. |  | 
| 259     virtual void OnConnectionStatusChange(ConnectionStatus status) = 0; |  | 
| 260 |  | 
| 261     // Called when a new auth token is provided by the sync server. |  | 
| 262     virtual void OnUpdatedToken(const std::string& token) = 0; |  | 
| 263 |  | 
| 264     // Called when user interaction is required to obtain a valid passphrase. |  | 
| 265     // - If the passphrase is required for encryption, |reason| will be |  | 
| 266     //   REASON_ENCRYPTION. |  | 
| 267     // - If the passphrase is required for the decryption of data that has |  | 
| 268     //   already been encrypted, |reason| will be REASON_DECRYPTION. |  | 
| 269     // - If the passphrase is required because decryption failed, and a new |  | 
| 270     //   passphrase is required, |reason| will be REASON_SET_PASSPHRASE_FAILED. |  | 
| 271     // |  | 
| 272     // |pending_keys| is a copy of the cryptographer's pending keys, that may be |  | 
| 273     // cached by the frontend for subsequent use by the UI. |  | 
| 274     virtual void OnPassphraseRequired( |  | 
| 275         PassphraseRequiredReason reason, |  | 
| 276         const sync_pb::EncryptedData& pending_keys) = 0; |  | 
| 277 |  | 
| 278     // Called when the passphrase provided by the user has been accepted and is |  | 
| 279     // now used to encrypt sync data. |  | 
| 280     virtual void OnPassphraseAccepted() = 0; |  | 
| 281 |  | 
| 282     // |bootstrap_token| is an opaque base64 encoded representation of the key |  | 
| 283     // generated by the current passphrase, and is provided to the observer for |  | 
| 284     // persistence purposes and use in a future initialization of sync (e.g. |  | 
| 285     // after restart). The boostrap token will always be derived from the most |  | 
| 286     // recent GAIA password (for accounts with implicit passphrases), even if |  | 
| 287     // the data is still encrypted with an older GAIA password. For accounts |  | 
| 288     // with explicit passphrases, it will be the most recently seen custom |  | 
| 289     // passphrase. |  | 
| 290     virtual void OnBootstrapTokenUpdated( |  | 
| 291         const std::string& bootstrap_token) = 0; |  | 
| 292 |  | 
| 293     // Called when initialization is complete to the point that SyncManager can |  | 
| 294     // process changes. This does not necessarily mean authentication succeeded |  | 
| 295     // or that the SyncManager is online. |  | 
| 296     // IMPORTANT: Creating any type of transaction before receiving this |  | 
| 297     // notification is illegal! |  | 
| 298     // WARNING: Calling methods on the SyncManager before receiving this |  | 
| 299     // message, unless otherwise specified, produces undefined behavior. |  | 
| 300     // |  | 
| 301     // |js_backend| is what about:sync interacts with.  It can emit |  | 
| 302     // the following events: |  | 
| 303 |  | 
| 304     /** |  | 
| 305      * @param {{ enabled: boolean }} details A dictionary containing: |  | 
| 306      *     - enabled: whether or not notifications are enabled. |  | 
| 307      */ |  | 
| 308     // function onNotificationStateChange(details); |  | 
| 309 |  | 
| 310     /** |  | 
| 311      * @param {{ changedTypes: Array.<string> }} details A dictionary |  | 
| 312      *     containing: |  | 
| 313      *     - changedTypes: a list of types (as strings) for which there |  | 
| 314              are new updates. |  | 
| 315      */ |  | 
| 316     // function onIncomingNotification(details); |  | 
| 317 |  | 
| 318     // Also, it responds to the following messages (all other messages |  | 
| 319     // are ignored): |  | 
| 320 |  | 
| 321     /** |  | 
| 322      * Gets the current notification state. |  | 
| 323      * |  | 
| 324      * @param {function(boolean)} callback Called with whether or not |  | 
| 325      *     notifications are enabled. |  | 
| 326      */ |  | 
| 327     // function getNotificationState(callback); |  | 
| 328 |  | 
| 329     /** |  | 
| 330      * Gets details about the root node. |  | 
| 331      * |  | 
| 332      * @param {function(!Object)} callback Called with details about the |  | 
| 333      *     root node. |  | 
| 334      */ |  | 
| 335     // TODO(akalin): Change this to getRootNodeId or eliminate it |  | 
| 336     // entirely. |  | 
| 337     // function getRootNodeDetails(callback); |  | 
| 338 |  | 
| 339     /** |  | 
| 340      * Gets summary information for a list of ids. |  | 
| 341      * |  | 
| 342      * @param {Array.<string>} idList List of 64-bit ids in decimal |  | 
| 343      *     string form. |  | 
| 344      * @param {Array.<{id: string, title: string, isFolder: boolean}>} |  | 
| 345      * callback Called with summaries for the nodes in idList that |  | 
| 346      *     exist. |  | 
| 347      */ |  | 
| 348     // function getNodeSummariesById(idList, callback); |  | 
| 349 |  | 
| 350     /** |  | 
| 351      * Gets detailed information for a list of ids. |  | 
| 352      * |  | 
| 353      * @param {Array.<string>} idList List of 64-bit ids in decimal |  | 
| 354      *     string form. |  | 
| 355      * @param {Array.<!Object>} callback Called with detailed |  | 
| 356      *     information for the nodes in idList that exist. |  | 
| 357      */ |  | 
| 358     // function getNodeDetailsById(idList, callback); |  | 
| 359 |  | 
| 360     /** |  | 
| 361      * Gets child ids for a given id. |  | 
| 362      * |  | 
| 363      * @param {string} id 64-bit id in decimal string form of the parent |  | 
| 364      *     node. |  | 
| 365      * @param {Array.<string>} callback Called with the (possibly empty) |  | 
| 366      *     list of child ids. |  | 
| 367      */ |  | 
| 368     // function getChildNodeIds(id); |  | 
| 369 |  | 
| 370     virtual void OnInitializationComplete( |  | 
| 371         const browser_sync::WeakHandle<browser_sync::JsBackend>& |  | 
| 372             js_backend, bool success) = 0; |  | 
| 373 |  | 
| 374     // We are no longer permitted to communicate with the server. Sync should |  | 
| 375     // be disabled and state cleaned up at once.  This can happen for a number |  | 
| 376     // of reasons, e.g. swapping from a test instance to production, or a |  | 
| 377     // global stop syncing operation has wiped the store. |  | 
| 378     virtual void OnStopSyncingPermanently() = 0; |  | 
| 379 |  | 
| 380     // After a request to clear server data, these callbacks are invoked to |  | 
| 381     // indicate success or failure. |  | 
| 382     virtual void OnClearServerDataSucceeded() = 0; |  | 
| 383     virtual void OnClearServerDataFailed() = 0; |  | 
| 384 |  | 
| 385     // Called when the set of encrypted types or the encrypt |  | 
| 386     // everything flag has been changed.  Note that encryption isn't |  | 
| 387     // complete until the OnEncryptionComplete() notification has been |  | 
| 388     // sent (see below). |  | 
| 389     // |  | 
| 390     // |encrypted_types| will always be a superset of |  | 
| 391     // Cryptographer::SensitiveTypes().  If |encrypt_everything| is |  | 
| 392     // true, |encrypted_types| will be the set of all known types. |  | 
| 393     // |  | 
| 394     // Until this function is called, observers can assume that the |  | 
| 395     // set of encrypted types is Cryptographer::SensitiveTypes() and |  | 
| 396     // that the encrypt everything flag is false. |  | 
| 397     // |  | 
| 398     // Called from within a transaction. |  | 
| 399     virtual void OnEncryptedTypesChanged( |  | 
| 400         syncable::ModelTypeSet encrypted_types, |  | 
| 401         bool encrypt_everything) = 0; |  | 
| 402 |  | 
| 403     // Called after we finish encrypting the current set of encrypted |  | 
| 404     // types. |  | 
| 405     // |  | 
| 406     // Called from within a transaction. |  | 
| 407     virtual void OnEncryptionComplete() = 0; |  | 
| 408 |  | 
| 409     virtual void OnActionableError( |  | 
| 410         const browser_sync::SyncProtocolError& sync_protocol_error) = 0; |  | 
| 411 |  | 
| 412    protected: |  | 
| 413     virtual ~Observer(); |  | 
| 414   }; |  | 
| 415 |  | 
| 416   enum TestingMode { |  | 
| 417     NON_TEST, |  | 
| 418     TEST_ON_DISK, |  | 
| 419     TEST_IN_MEMORY, |  | 
| 420   }; |  | 
| 421 |  | 
| 422   // Create an uninitialized SyncManager.  Callers must Init() before using. |  | 
| 423   explicit SyncManager(const std::string& name); |  | 
| 424   virtual ~SyncManager(); |  | 
| 425 |  | 
| 426   // Initialize the sync manager.  |database_location| specifies the path of |  | 
| 427   // the directory in which to locate a sqlite repository storing the syncer |  | 
| 428   // backend state. Initialization will open the database, or create it if it |  | 
| 429   // does not already exist. Returns false on failure. |  | 
| 430   // |event_handler| is the JsEventHandler used to propagate events to |  | 
| 431   // chrome://sync-internals.  |event_handler| may be uninitialized. |  | 
| 432   // |sync_server_and_path| and |sync_server_port| represent the Chrome sync |  | 
| 433   // server to use, and |use_ssl| specifies whether to communicate securely; |  | 
| 434   // the default is false. |  | 
| 435   // |blocking_task_runner| is a TaskRunner to be used for tasks that |  | 
| 436   // may block on disk I/O. |  | 
| 437   // |post_factory| will be owned internally and used to create |  | 
| 438   // instances of an HttpPostProvider. |  | 
| 439   // |model_safe_worker| ownership is given to the SyncManager. |  | 
| 440   // |user_agent| is a 7-bit ASCII string suitable for use as the User-Agent |  | 
| 441   // HTTP header. Used internally when collecting stats to classify clients. |  | 
| 442   // |sync_notifier| is owned and used to listen for notifications. |  | 
| 443   // |report_unrecoverable_error_function| may be NULL. |  | 
| 444   bool Init(const FilePath& database_location, |  | 
| 445             const browser_sync::WeakHandle<browser_sync::JsEventHandler>& |  | 
| 446                 event_handler, |  | 
| 447             const std::string& sync_server_and_path, |  | 
| 448             int sync_server_port, |  | 
| 449             bool use_ssl, |  | 
| 450             const scoped_refptr<base::TaskRunner>& blocking_task_runner, |  | 
| 451             HttpPostProviderFactory* post_factory, |  | 
| 452             browser_sync::ModelSafeWorkerRegistrar* registrar, |  | 
| 453             browser_sync::ExtensionsActivityMonitor* |  | 
| 454                 extensions_activity_monitor, |  | 
| 455             ChangeDelegate* change_delegate, |  | 
| 456             const std::string& user_agent, |  | 
| 457             const SyncCredentials& credentials, |  | 
| 458             bool enable_sync_tabs_for_other_clients, |  | 
| 459             sync_notifier::SyncNotifier* sync_notifier, |  | 
| 460             const std::string& restored_key_for_bootstrapping, |  | 
| 461             TestingMode testing_mode, |  | 
| 462             browser_sync::Encryptor* encryptor, |  | 
| 463             browser_sync::UnrecoverableErrorHandler* |  | 
| 464                 unrecoverable_error_handler, |  | 
| 465             browser_sync::ReportUnrecoverableErrorFunction |  | 
| 466                 report_unrecoverable_error_function); |  | 
| 467 |  | 
| 468   // Throw an unrecoverable error from a transaction (mostly used for |  | 
| 469   // testing). |  | 
| 470   void ThrowUnrecoverableError(); |  | 
| 471 |  | 
| 472   // Check if the database has been populated with a full "initial" download of |  | 
| 473   // sync items for each data type currently present in the routing info. |  | 
| 474   // Prerequisite for calling this is that OnInitializationComplete has been |  | 
| 475   // called.  May be called from any thread. |  | 
| 476   bool InitialSyncEndedForAllEnabledTypes(); |  | 
| 477 |  | 
| 478   // Update tokens that we're using in Sync. Email must stay the same. |  | 
| 479   void UpdateCredentials(const SyncCredentials& credentials); |  | 
| 480 |  | 
| 481   // Called when the user disables or enables a sync type. |  | 
| 482   void UpdateEnabledTypes(); |  | 
| 483 |  | 
| 484   // Conditionally sets the flag in the Nigori node which instructs other |  | 
| 485   // clients to start syncing tabs. |  | 
| 486   void MaybeSetSyncTabsInNigoriNode(syncable::ModelTypeSet enabled_types); |  | 
| 487 |  | 
| 488   // Put the syncer in normal mode ready to perform nudges and polls. |  | 
| 489   void StartSyncingNormally(); |  | 
| 490 |  | 
| 491   // Attempts to re-encrypt encrypted data types using the passphrase provided. |  | 
| 492   // Notifies observers of the result of the operation via OnPassphraseAccepted |  | 
| 493   // or OnPassphraseRequired, updates the nigori node, and does re-encryption as |  | 
| 494   // appropriate. If an explicit password has been set previously, we drop |  | 
| 495   // subsequent requests to set a passphrase. If the cryptographer has pending |  | 
| 496   // keys, and a new implicit passphrase is provided, we try decrypting the |  | 
| 497   // pending keys with it, and if that fails, we cache the passphrase for |  | 
| 498   // re-encryption once the pending keys are decrypted. |  | 
| 499   void SetEncryptionPassphrase(const std::string& passphrase, bool is_explicit); |  | 
| 500 |  | 
| 501   // Provides a passphrase for decrypting the user's existing sync data. |  | 
| 502   // Notifies observers of the result of the operation via OnPassphraseAccepted |  | 
| 503   // or OnPassphraseRequired, updates the nigori node, and does re-encryption as |  | 
| 504   // appropriate if there is a previously cached encryption passphrase. It is an |  | 
| 505   // error to call this when we don't have pending keys. |  | 
| 506   void SetDecryptionPassphrase(const std::string& passphrase); |  | 
| 507 |  | 
| 508   // Puts the SyncScheduler into a mode where no normal nudge or poll traffic |  | 
| 509   // will occur, but calls to RequestConfig will be supported.  If |callback| |  | 
| 510   // is provided, it will be invoked (from the internal SyncScheduler) when |  | 
| 511   // the thread has changed to configuration mode. |  | 
| 512   void StartConfigurationMode(const base::Closure& callback); |  | 
| 513 |  | 
| 514   // Switches the mode of operation to CONFIGURATION_MODE and |  | 
| 515   // schedules a config task to fetch updates for |types|. |  | 
| 516   void RequestConfig(syncable::ModelTypeSet types, |  | 
| 517                      sync_api::ConfigureReason reason); |  | 
| 518 |  | 
| 519   void RequestCleanupDisabledTypes(); |  | 
| 520 |  | 
| 521   // Request a clearing of all data on the server |  | 
| 522   void RequestClearServerData(); |  | 
| 523 |  | 
| 524   // Adds a listener to be notified of sync events. |  | 
| 525   // NOTE: It is OK (in fact, it's probably a good idea) to call this before |  | 
| 526   // having received OnInitializationCompleted. |  | 
| 527   void AddObserver(Observer* observer); |  | 
| 528 |  | 
| 529   // Remove the given observer.  Make sure to call this if the |  | 
| 530   // Observer is being destroyed so the SyncManager doesn't |  | 
| 531   // potentially dereference garbage. |  | 
| 532   void RemoveObserver(Observer* observer); |  | 
| 533 |  | 
| 534   // Status-related getter.  May be called on any thread. |  | 
| 535   Status GetDetailedStatus() const; |  | 
| 536 |  | 
| 537   // Whether or not the Nigori node is encrypted using an explicit passphrase. |  | 
| 538   // May be called on any thread. |  | 
| 539   bool IsUsingExplicitPassphrase(); |  | 
| 540 |  | 
| 541   // Call periodically from a database-safe thread to persist recent changes |  | 
| 542   // to the syncapi model. |  | 
| 543   void SaveChanges(); |  | 
| 544 |  | 
| 545   // Initiates shutdown of various components in the sync engine.  Must be |  | 
| 546   // called from the main thread to allow preempting ongoing tasks on the sync |  | 
| 547   // loop (that may be blocked on I/O).  The semantics of |callback| are the |  | 
| 548   // same as with StartConfigurationMode. If provided and a scheduler / sync |  | 
| 549   // loop exists, it will be invoked from the sync loop by the scheduler to |  | 
| 550   // notify that all work has been flushed + cancelled, and it is idle. |  | 
| 551   // If no scheduler exists, the callback is run immediately (from the loop |  | 
| 552   // this was created on, which is the sync loop), as sync is effectively |  | 
| 553   // stopped. |  | 
| 554   void StopSyncingForShutdown(const base::Closure& callback); |  | 
| 555 |  | 
| 556   // Issue a final SaveChanges, and close sqlite handles. |  | 
| 557   void ShutdownOnSyncThread(); |  | 
| 558 |  | 
| 559   // May be called from any thread. |  | 
| 560   UserShare* GetUserShare() const; |  | 
| 561 |  | 
| 562   // Inform the cryptographer of the most recent passphrase and set of |  | 
| 563   // encrypted types (from nigori node), then ensure all data that |  | 
| 564   // needs encryption is encrypted with the appropriate passphrase. |  | 
| 565   // |  | 
| 566   // May trigger OnPassphraseRequired().  Otherwise, it will trigger |  | 
| 567   // OnEncryptedTypesChanged() if necessary (see comments for |  | 
| 568   // OnEncryptedTypesChanged()), and then OnEncryptionComplete(). |  | 
| 569   // |  | 
| 570   // Also updates or adds device information to the nigori node. |  | 
| 571   // |  | 
| 572   // Note: opens a transaction, so must only be called after syncapi |  | 
| 573   // has been initialized. |  | 
| 574   void RefreshNigori(const std::string& chrome_version, |  | 
| 575                      const base::Closure& done_callback); |  | 
| 576 |  | 
| 577   // Enable encryption of all sync data. Once enabled, it can never be |  | 
| 578   // disabled without clearing the server data. |  | 
| 579   // |  | 
| 580   // This will trigger OnEncryptedTypesChanged() if necessary (see |  | 
| 581   // comments for OnEncryptedTypesChanged()).  It then may trigger |  | 
| 582   // OnPassphraseRequired(), but otherwise it will trigger |  | 
| 583   // OnEncryptionComplete(). |  | 
| 584   void EnableEncryptEverything(); |  | 
| 585 |  | 
| 586   // Returns true if we are currently encrypting all sync data.  May |  | 
| 587   // be called on any thread. |  | 
| 588   bool EncryptEverythingEnabledForTest() const; |  | 
| 589 |  | 
| 590   // Gets the set of encrypted types from the cryptographer |  | 
| 591   // Note: opens a transaction.  May be called from any thread. |  | 
| 592   syncable::ModelTypeSet GetEncryptedDataTypesForTest() const; |  | 
| 593 |  | 
| 594   // Reads the nigori node to determine if any experimental types should be |  | 
| 595   // enabled. |  | 
| 596   // Note: opens a transaction.  May be called on any thread. |  | 
| 597   bool ReceivedExperimentalTypes(syncable::ModelTypeSet* to_add) const; |  | 
| 598 |  | 
| 599   // Uses a read-only transaction to determine if the directory being synced has |  | 
| 600   // any remaining unsynced items.  May be called on any thread. |  | 
| 601   bool HasUnsyncedItems() const; |  | 
| 602 |  | 
| 603   // Functions used for testing. |  | 
| 604 |  | 
| 605   void TriggerOnNotificationStateChangeForTest( |  | 
| 606       bool notifications_enabled); |  | 
| 607 |  | 
| 608   void TriggerOnIncomingNotificationForTest( |  | 
| 609       syncable::ModelTypeSet model_types); |  | 
| 610 |  | 
| 611   static const int kDefaultNudgeDelayMilliseconds; |  | 
| 612   static const int kPreferencesNudgeDelayMilliseconds; |  | 
| 613   static const int kPiggybackNudgeDelay; |  | 
| 614 |  | 
| 615   static const FilePath::CharType kSyncDatabaseFilename[]; |  | 
| 616 |  | 
| 617  private: |  | 
| 618   FRIEND_TEST_ALL_PREFIXES(SyncManagerTest, NudgeDelayTest); |  | 
| 619 |  | 
| 620   // For unit tests. |  | 
| 621   base::TimeDelta GetNudgeDelayTimeDelta(const syncable::ModelType& model_type); |  | 
| 622 |  | 
| 623   base::ThreadChecker thread_checker_; |  | 
| 624 |  | 
| 625   // An opaque pointer to the nested private class. |  | 
| 626   SyncInternal* data_; |  | 
| 627 |  | 
| 628   DISALLOW_COPY_AND_ASSIGN(SyncManager); |  | 
| 629 }; |  | 
| 630 |  | 
| 631 bool InitialSyncEndedForTypes(syncable::ModelTypeSet types, UserShare* share); |  | 
| 632 |  | 
| 633 syncable::ModelTypeSet GetTypesWithEmptyProgressMarkerToken( |  | 
| 634     syncable::ModelTypeSet types, |  | 
| 635     sync_api::UserShare* share); |  | 
| 636 |  | 
| 637 const char* ConnectionStatusToString(ConnectionStatus status); |  | 
| 638 |  | 
| 639 // Returns the string representation of a PassphraseRequiredReason value. |  | 
| 640 const char* PassphraseRequiredReasonToString(PassphraseRequiredReason reason); |  | 
| 641 |  | 
| 642 }  // namespace sync_api |  | 
| 643 |  | 
| 644 #endif  // CHROME_BROWSER_SYNC_INTERNAL_API_SYNC_MANAGER_H_ |  | 
| OLD | NEW | 
|---|