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