remote_change_processor.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
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_CHANGE_PROCESSOR_H_ 6#define CHROME_BROWSER_SYNC_FILE_SYSTEM_REMOTE_CHANGE_PROCESSOR_H_ 7 8#include "base/basictypes.h" 9#include "base/callback_forward.h" 10#include "webkit/fileapi/syncable/sync_callbacks.h" 11#include "webkit/fileapi/syncable/sync_status_code.h" 12 13class FilePath; 14 15namespace fileapi { 16class FileChange; 17class FileChangeList; 18class FileSystemURL; 19class SyncFileMetadata; 20} 21 22namespace sync_file_system { 23 24// Represents an interface to process one remote change and applies 25// it to the local file system. 26// This interface is to be implemented/backed by LocalSyncFileService. 27class RemoteChangeProcessor { 28 public: 29 // Callback type for PrepareForProcessRemoteChange. 30 // |file_type| indicates the current file/directory type of the target 31 // URL in the local filesystem. If the target URL does not exist it is 32 // set to SYNC_FILE_TYPE_UNKNOWN. 33 // |changes| indicates a set of pending changes for the target URL. 34 typedef base::Callback<void( 35 fileapi::SyncStatusCode status, 36 const fileapi::SyncFileMetadata& metadata, 37 const fileapi::FileChangeList& changes)> PrepareChangeCallback; 38 39 RemoteChangeProcessor() {} 40 virtual ~RemoteChangeProcessor() {} 41 42 // This must be called before processing the change for the |url|. 43 // This tries to lock the target |url| and returns the local changes 44 // if any. (The change returned by the callback is to make a decision 45 // on conflict resolution, but NOT for applying local changes to the remote, 46 // which is supposed to be done by LocalChangeProcessor) 47 virtual void PrepareForProcessRemoteChange( 48 const fileapi::FileSystemURL& url, 49 const PrepareChangeCallback& callback) = 0; 50 51 // This is called to apply the remote |change|. If the change type is 52 // ADD_OR_UPDATE for a file, |local_path| needs to point to a 53 // local file path that contains the latest file image (e.g. a path 54 // to a temporary file which has the data downloaded from the server). 55 // This may fail with an error but should NOT result in a conflict 56 // (as we must have checked the change status in PrepareRemoteSync and 57 // have disabled any further writing). 58 virtual void ApplyRemoteChange( 59 const fileapi::FileChange& change, 60 const FilePath& local_path, 61 const fileapi::FileSystemURL& url, 62 const fileapi::SyncStatusCallback& callback) = 0; 63 64 private: 65 DISALLOW_COPY_AND_ASSIGN(RemoteChangeProcessor); 66}; 67 68} // namespace sync_file_system 69 70#endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_REMOTE_CHANGE_PROCESSOR_H_ 71