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