remote_change_processor.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_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
13namespace base {
14class FilePath;
15}
16
17namespace fileapi {
18class FileSystemURL;
19}
20
21namespace sync_file_system {
22
23class FileChange;
24class FileChangeList;
25class SyncFileMetadata;
26
27// Represents an interface to process one remote change and applies
28// it to the local file system.
29// This interface is to be implemented/backed by LocalSyncFileService.
30class RemoteChangeProcessor {
31 public:
32  // Callback type for PrepareForProcessRemoteChange.
33  // |file_type| indicates the current file/directory type of the target
34  // URL in the local filesystem. If the target URL does not exist it is
35  // set to SYNC_FILE_TYPE_UNKNOWN.
36  // |changes| indicates a set of pending changes for the target URL.
37  typedef base::Callback<void(
38      SyncStatusCode status,
39      const SyncFileMetadata& metadata,
40      const FileChangeList& changes)> PrepareChangeCallback;
41
42  RemoteChangeProcessor() {}
43  virtual ~RemoteChangeProcessor() {}
44
45  // This must be called before processing the change for the |url|
46  // for sync service |service_name|.
47  // This tries to lock the target |url| and returns the local changes
48  // if any. (The change returned by the callback is to make a decision
49  // on conflict resolution, but NOT for applying local changes to the remote,
50  // which is supposed to be done by LocalChangeProcessor)
51  virtual void PrepareForProcessRemoteChange(
52      const fileapi::FileSystemURL& url,
53      const std::string& service_name,
54      const PrepareChangeCallback& callback) = 0;
55
56  // This is called to apply the remote |change|. If the change type is
57  // ADD_OR_UPDATE for a file, |local_path| needs to point to a
58  // local file path that contains the latest file image (e.g. a path
59  // to a temporary file which has the data downloaded from the server).
60  // This may fail with an error but should NOT result in a conflict
61  // (as we must have checked the change status in PrepareRemoteSync and
62  // have disabled any further writing).
63  virtual void ApplyRemoteChange(
64      const FileChange& change,
65      const base::FilePath& local_path,
66      const fileapi::FileSystemURL& url,
67      const SyncStatusCallback& callback) = 0;
68
69  // Clears all local changes. This should be called when the remote sync
70  // service reconciled or processed the existing local changes while
71  // processing a remote change.
72  virtual void ClearLocalChanges(
73      const fileapi::FileSystemURL& url,
74      const base::Closure& completion_callback) = 0;
75
76  // Records a fake local change so that the change will be processed in the
77  // next local sync.
78  // This is called when the remote side wants to trigger a local sync
79  // to propagate the local change to the remote change (e.g. to
80  // resolve a conflict by uploading the local file).
81  virtual void RecordFakeLocalChange(
82      const fileapi::FileSystemURL& url,
83      const FileChange& change,
84      const SyncStatusCallback& callback) = 0;
85
86 private:
87  DISALLOW_COPY_AND_ASSIGN(RemoteChangeProcessor);
88};
89
90}  // namespace sync_file_system
91
92#endif  // CHROME_BROWSER_SYNC_FILE_SYSTEM_REMOTE_CHANGE_PROCESSOR_H_
93