remote_file_sync_service.h revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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_FILE_SYSTEM_REMOTE_FILE_SYNC_SERVICE_H_ 6#define CHROME_BROWSER_SYNC_FILE_SYSTEM_REMOTE_FILE_SYNC_SERVICE_H_ 7 8#include <string> 9 10#include "base/basictypes.h" 11#include "chrome/browser/sync_file_system/conflict_resolution_policy.h" 12#include "webkit/fileapi/file_system_url.h" 13#include "webkit/fileapi/syncable/sync_callbacks.h" 14 15class GURL; 16 17namespace sync_file_system { 18 19class FileStatusObserver; 20class LocalChangeProcessor; 21class RemoteChangeProcessor; 22 23enum RemoteServiceState { 24 // Remote service is up and running, or has not seen any errors yet. 25 // The consumer of this service can make new requests while the 26 // service is in this state. 27 REMOTE_SERVICE_OK, 28 29 // Remote service is temporarily unavailable due to network, 30 // authentication or some other temporary failure. 31 // This state may be automatically resolved when the underlying 32 // network condition or service condition changes. 33 // The consumer of this service can still make new requests but 34 // they may fail (with recoverable error code). 35 REMOTE_SERVICE_TEMPORARY_UNAVAILABLE, 36 37 // Remote service is temporarily unavailable due to authentication failure. 38 // This state may be automatically resolved when the authentication token 39 // has been refreshed internally (e.g. when the user signed in etc). 40 // The consumer of this service can still make new requests but 41 // they may fail (with recoverable error code). 42 REMOTE_SERVICE_AUTHENTICATION_REQUIRED, 43 44 // Remote service is disabled by configuration change or due to some 45 // unrecoverable errors, e.g. local database corruption. 46 // Any new requests will immediately fail when the service is in 47 // this state. 48 REMOTE_SERVICE_DISABLED, 49}; 50 51// This class represents a backing service of the sync filesystem. 52// This also maintains conflict information, i.e. a list of conflicting files 53// (at least in the current design). 54// Owned by SyncFileSystemService. 55class RemoteFileSyncService { 56 public: 57 class Observer { 58 public: 59 Observer() {} 60 virtual ~Observer() {} 61 62 // This is called when RemoteFileSyncService updates its internal queue 63 // of pending remote changes. 64 // |pending_changes_hint| indicates the pending queue length to help sync 65 // scheduling but the value may not be accurately reflect the real-time 66 // value. 67 virtual void OnRemoteChangeQueueUpdated(int64 pending_changes_hint) = 0; 68 69 // This is called when RemoteFileSyncService updates its state. 70 virtual void OnRemoteServiceStateUpdated( 71 RemoteServiceState state, 72 const std::string& description) {} 73 74 private: 75 DISALLOW_COPY_AND_ASSIGN(Observer); 76 }; 77 78 RemoteFileSyncService() {} 79 virtual ~RemoteFileSyncService() {} 80 81 // Adds and removes observers. 82 virtual void AddServiceObserver(Observer* observer) = 0; 83 virtual void AddFileStatusObserver(FileStatusObserver* observer) = 0; 84 85 // Registers |origin| to track remote side changes for the |origin|. 86 // Upon completion, invokes |callback|. 87 // The caller may call this method again when the remote service state 88 // migrates to REMOTE_SERVICE_OK state if the error code returned via 89 // |callback| was retriable ones. 90 virtual void RegisterOriginForTrackingChanges( 91 const GURL& origin, 92 const SyncStatusCallback& callback) = 0; 93 94 // Unregisters |origin| to track remote side changes for the |origin|. 95 // Upon completion, invokes |callback|. 96 // The caller may call this method again when the remote service state 97 // migrates to REMOTE_SERVICE_OK state if the error code returned via 98 // |callback| was retriable ones. 99 virtual void UnregisterOriginForTrackingChanges( 100 const GURL& origin, 101 const SyncStatusCallback& callback) = 0; 102 103 virtual void EnableOriginForTrackingChanges( 104 const GURL& origin, 105 const SyncStatusCallback& callback) = 0; 106 107 virtual void DisableOriginForTrackingChanges( 108 const GURL& origin, 109 const SyncStatusCallback& callback) = 0; 110 111 // Uninstalls the |origin| by deleting its remote data copy and then removing 112 // the origin from the metadata store. 113 virtual void UninstallOrigin( 114 const GURL& origin, 115 const SyncStatusCallback& callback) = 0; 116 117 // Called by the sync engine to process one remote change. 118 // After a change is processed |callback| will be called (to return 119 // the control to the sync engine). 120 // It is invalid to call this before calling SetRemoteChangeProcessor(). 121 virtual void ProcessRemoteChange(const SyncFileCallback& callback) = 0; 122 123 // Sets a remote change processor. This must be called before any 124 // ProcessRemoteChange(). 125 virtual void SetRemoteChangeProcessor( 126 RemoteChangeProcessor* processor) = 0; 127 128 // Returns a LocalChangeProcessor that applies a local change to the remote 129 // storage backed by this service. 130 virtual LocalChangeProcessor* GetLocalChangeProcessor() = 0; 131 132 // Returns true if the file |url| is marked conflicted in the remote service. 133 virtual bool IsConflicting(const fileapi::FileSystemURL& url) = 0; 134 135 // Returns the metadata of a remote file pointed by |url|. 136 virtual void GetRemoteFileMetadata( 137 const fileapi::FileSystemURL& url, 138 const SyncFileMetadataCallback& callback) = 0; 139 140 // Returns the current remote service state (should equal to the value 141 // returned by the last OnRemoteServiceStateUpdated notification. 142 virtual RemoteServiceState GetCurrentState() const = 0; 143 144 // Returns the service name that backs this remote_file_sync_service. 145 virtual const char* GetServiceName() const = 0; 146 147 // Enables or disables the background sync. 148 // Setting this to false should disable the synchronization (and make 149 // the service state to REMOTE_SERVICE_DISABLED), while setting this to 150 // true does not necessarily mean the service is actually turned on 151 // (for example if Chrome is offline the service state will become 152 // REMOTE_SERVICE_TEMPORARY_UNAVAILABLE). 153 virtual void SetSyncEnabled(bool enabled) = 0; 154 155 // Sets the conflict resolution policy. Returns SYNC_STATUS_OK on success, 156 // or returns an error code if the given policy is not supported or had 157 // an error. 158 virtual SyncStatusCode SetConflictResolutionPolicy( 159 ConflictResolutionPolicy policy) = 0; 160 161 // Gets the conflict resolution policy. 162 virtual ConflictResolutionPolicy GetConflictResolutionPolicy() const = 0; 163 164 private: 165 DISALLOW_COPY_AND_ASSIGN(RemoteFileSyncService); 166}; 167 168} // namespace sync_file_system 169 170#endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_REMOTE_FILE_SYNC_SERVICE_H_ 171