Home | History | Annotate | Download | only in drive_backend
      1 // Copyright 2014 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_FILE_SYSTEM_DRIVE_BACKEND_SYNC_WORKER_INTERFACE_H_
      6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_WORKER_INTERFACE_H_
      7 
      8 #include <string>
      9 
     10 #include "base/memory/scoped_ptr.h"
     11 #include "chrome/browser/sync_file_system/remote_file_sync_service.h"
     12 #include "chrome/browser/sync_file_system/sync_action.h"
     13 #include "chrome/browser/sync_file_system/sync_callbacks.h"
     14 #include "chrome/browser/sync_file_system/sync_direction.h"
     15 #include "net/base/network_change_notifier.h"
     16 
     17 class GURL;
     18 
     19 namespace base {
     20 class FilePath;
     21 class ListValue;
     22 }
     23 
     24 namespace drive {
     25 class DriveServiceInterface;
     26 class DriveUploaderInterface;
     27 }
     28 
     29 namespace fileapi {
     30 class FileSystemURL;
     31 }
     32 
     33 namespace sync_file_system {
     34 
     35 class FileChange;
     36 class SyncFileMetadata;
     37 
     38 namespace drive_backend {
     39 
     40 class MetadataDatabase;
     41 class RemoteChangeProcessorOnWorker;
     42 class SyncEngineContext;
     43 class SyncTaskManager;
     44 
     45 class SyncWorkerInterface {
     46  public:
     47   class Observer {
     48    public:
     49     virtual void OnPendingFileListUpdated(int item_count) = 0;
     50     virtual void OnFileStatusChanged(const fileapi::FileSystemURL& url,
     51                                      SyncFileStatus file_status,
     52                                      SyncAction sync_action,
     53                                      SyncDirection direction) = 0;
     54     virtual void UpdateServiceState(RemoteServiceState state,
     55                                     const std::string& description) = 0;
     56 
     57    protected:
     58     virtual ~Observer() {}
     59   };
     60 
     61   SyncWorkerInterface() {}
     62   virtual ~SyncWorkerInterface() {}
     63 
     64   // Initializes SyncWorkerInterface after constructions of some member classes.
     65   virtual void Initialize(
     66       scoped_ptr<SyncEngineContext> sync_engine_context) = 0;
     67 
     68   // See RemoteFileSyncService for the details.
     69   virtual void RegisterOrigin(const GURL& origin,
     70                               const SyncStatusCallback& callback) = 0;
     71   virtual void EnableOrigin(const GURL& origin,
     72                             const SyncStatusCallback& callback) = 0;
     73   virtual void DisableOrigin(const GURL& origin,
     74                              const SyncStatusCallback& callback) = 0;
     75   virtual void UninstallOrigin(
     76       const GURL& origin,
     77       RemoteFileSyncService::UninstallFlag flag,
     78       const SyncStatusCallback& callback) = 0;
     79   virtual void ProcessRemoteChange(const SyncFileCallback& callback) = 0;
     80   virtual void SetRemoteChangeProcessor(
     81       RemoteChangeProcessorOnWorker* remote_change_processor_on_worker) = 0;
     82   virtual RemoteServiceState GetCurrentState() const = 0;
     83   virtual void GetOriginStatusMap(
     84       const RemoteFileSyncService::StatusMapCallback& callback) = 0;
     85   virtual scoped_ptr<base::ListValue> DumpFiles(const GURL& origin) = 0;
     86   virtual scoped_ptr<base::ListValue> DumpDatabase() = 0;
     87   virtual void SetSyncEnabled(bool enabled) = 0;
     88   virtual void PromoteDemotedChanges() = 0;
     89 
     90   // See LocalChangeProcessor for the details.
     91   virtual void ApplyLocalChange(
     92       const FileChange& local_change,
     93       const base::FilePath& local_path,
     94       const SyncFileMetadata& local_metadata,
     95       const fileapi::FileSystemURL& url,
     96       const SyncStatusCallback& callback) = 0;
     97 
     98   // See drive::DriveNotificationObserver for the details.
     99   virtual void OnNotificationReceived() = 0;
    100 
    101   // See drive::DriveServiceObserver for the details.
    102   virtual void OnReadyToSendRequests() = 0;
    103   virtual void OnRefreshTokenInvalid() = 0;
    104 
    105   // See net::NetworkChangeNotifier::NetworkChangeObserver for the details.
    106   virtual void OnNetworkChanged(
    107       net::NetworkChangeNotifier::ConnectionType type) = 0;
    108 
    109   virtual drive::DriveServiceInterface* GetDriveService() = 0;
    110   virtual drive::DriveUploaderInterface* GetDriveUploader() = 0;
    111   virtual MetadataDatabase* GetMetadataDatabase() = 0;
    112   virtual SyncTaskManager* GetSyncTaskManager() = 0;
    113 
    114   virtual void DetachFromSequence() = 0;
    115 
    116   virtual void AddObserver(Observer* observer) = 0;
    117 
    118  private:
    119   friend class SyncEngineTest;
    120 
    121   // TODO(peria): Remove this interface after making FakeSyncWorker class.
    122   virtual void SetHasRefreshToken(bool has_refresh_token) = 0;
    123 
    124   DISALLOW_COPY_AND_ASSIGN(SyncWorkerInterface);
    125 };
    126 
    127 }  // namespace drive_backend
    128 }  // namespace sync_file_system
    129 
    130 #endif  // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_WORKER_INTERFACE_H_
    131