Home | History | Annotate | Download | only in public
      1 // Copyright 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 // InternalComponentsFactory exists so that tests can override creation of
      6 // components used by the SyncManager that are not exposed across the sync
      7 // API boundary.
      8 
      9 #ifndef SYNC_INTERNAL_API_PUBLIC_INTERNAL_COMPONENTS_FACTORY_H_
     10 #define SYNC_INTERNAL_API_PUBLIC_INTERNAL_COMPONENTS_FACTORY_H_
     11 
     12 #include <string>
     13 #include <vector>
     14 
     15 #include "base/files/file_path.h"
     16 #include "sync/base/sync_export.h"
     17 #include "sync/internal_api/public/engine/model_safe_worker.h"
     18 
     19 namespace syncer {
     20 
     21 class CancelationSignal;
     22 class ExtensionsActivity;
     23 class ModelTypeRegistry;
     24 class ServerConnectionManager;
     25 class SyncEngineEventListener;
     26 class SyncScheduler;
     27 
     28 namespace sessions {
     29 class DebugInfoGetter;
     30 class SyncSessionContext;
     31 }
     32 
     33 namespace syncable {
     34 class Directory;
     35 class DirectoryBackingStore;
     36 }
     37 
     38 class SYNC_EXPORT InternalComponentsFactory {
     39  public:
     40   enum EncryptionMethod {
     41     ENCRYPTION_LEGACY,
     42     // Option to enable support for keystore key based encryption.
     43     ENCRYPTION_KEYSTORE
     44   };
     45 
     46   enum BackoffOverride {
     47     BACKOFF_NORMAL,
     48     // Use this value for integration testing to avoid long delays /
     49     // timing out tests. Uses kInitialBackoffShortRetrySeconds (see
     50     // polling_constants.h) for all initial retries.
     51     BACKOFF_SHORT_INITIAL_RETRY_OVERRIDE
     52   };
     53 
     54   enum PreCommitUpdatesPolicy {
     55     // By default, the server will enable or disable this experiment through the
     56     // sync protocol's experiments data type.
     57     SERVER_CONTROLLED_PRE_COMMIT_UPDATE_AVOIANCE,
     58 
     59     // This flag overrides the server's decision and enables the pre-commit
     60     // update avoidance experiment.
     61     FORCE_ENABLE_PRE_COMMIT_UPDATE_AVOIDANCE,
     62   };
     63 
     64   // Configuration options for internal components. This struct is expected
     65   // to grow and shrink over time with transient features / experiments,
     66   // roughly following command line flags in chrome. Implementations of
     67   // InternalComponentsFactory can use this information to build components
     68   // with appropriate bells and whistles.
     69   struct Switches {
     70     EncryptionMethod encryption_method;
     71     BackoffOverride backoff_override;
     72     PreCommitUpdatesPolicy pre_commit_updates_policy;
     73   };
     74 
     75   // For selecting the types of storage to use to persist sync data when
     76   // BuildDirectoryBackingStore() is called.
     77   enum StorageOption {
     78     // BuildDirectoryBackingStore should not use persistent on-disk storage.
     79     STORAGE_IN_MEMORY,
     80     // Use this if you want BuildDirectoryBackingStore to create/use a real
     81     // on disk store.
     82     STORAGE_ON_DISK,
     83     // Use this to defer creating on-disk database until
     84     // DirectoryBackingStore::SaveChanges() is called.
     85     STORAGE_ON_DISK_DEFERRED,
     86     // Use this to test the case where a directory fails to load.
     87     STORAGE_INVALID
     88   };
     89 
     90   virtual ~InternalComponentsFactory() {}
     91 
     92   virtual scoped_ptr<SyncScheduler> BuildScheduler(
     93       const std::string& name,
     94       sessions::SyncSessionContext* context,
     95       CancelationSignal* cancelation_signal) = 0;
     96 
     97   virtual scoped_ptr<sessions::SyncSessionContext> BuildContext(
     98       ServerConnectionManager* connection_manager,
     99       syncable::Directory* directory,
    100       ExtensionsActivity* extensions_activity,
    101       const std::vector<SyncEngineEventListener*>& listeners,
    102       sessions::DebugInfoGetter* debug_info_getter,
    103       ModelTypeRegistry* model_type_registry,
    104       const std::string& invalidator_client_id) = 0;
    105 
    106   virtual scoped_ptr<syncable::DirectoryBackingStore>
    107   BuildDirectoryBackingStore(
    108       StorageOption storage,
    109       const std::string& dir_name,
    110       const base::FilePath& backing_filepath) = 0;
    111 
    112   // Returns the Switches struct that this object is using as configuration, if
    113   // the implementation is making use of one.
    114   virtual Switches GetSwitches() const = 0;
    115 };
    116 
    117 }  // namespace syncer
    118 
    119 #endif  // SYNC_INTERNAL_API_PUBLIC_INTERNAL_COMPONENTS_FACTORY_H_
    120