| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_LOCAL_LOCAL_FILE_SYNC_CONTEXT_H_ | 5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_LOCAL_FILE_SYNC_CONTEXT_H_ |
| 6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_LOCAL_FILE_SYNC_CONTEXT_H_ | 6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_LOCAL_FILE_SYNC_CONTEXT_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 // This class works as a bridge between LocalFileSyncService (which is a | 44 // This class works as a bridge between LocalFileSyncService (which is a |
| 45 // per-profile object) and FileSystemContext's (which is a per-storage-partition | 45 // per-profile object) and FileSystemContext's (which is a per-storage-partition |
| 46 // object and may exist multiple in a profile). | 46 // object and may exist multiple in a profile). |
| 47 // An instance of this class is shared by FileSystemContexts and outlives | 47 // An instance of this class is shared by FileSystemContexts and outlives |
| 48 // LocalFileSyncService. | 48 // LocalFileSyncService. |
| 49 class LocalFileSyncContext | 49 class LocalFileSyncContext |
| 50 : public base::RefCountedThreadSafe<LocalFileSyncContext>, | 50 : public base::RefCountedThreadSafe<LocalFileSyncContext>, |
| 51 public LocalFileSyncStatus::Observer { | 51 public LocalFileSyncStatus::Observer { |
| 52 public: | 52 public: |
| 53 enum SyncMode { |
| 54 SYNC_EXCLUSIVE, |
| 55 SYNC_SNAPSHOT, |
| 56 }; |
| 57 |
| 53 typedef base::Callback<void( | 58 typedef base::Callback<void( |
| 54 SyncStatusCode status, const LocalFileSyncInfo& sync_file_info)> | 59 SyncStatusCode status, const LocalFileSyncInfo& sync_file_info)> |
| 55 LocalFileSyncInfoCallback; | 60 LocalFileSyncInfoCallback; |
| 56 | 61 |
| 57 typedef base::Callback<void(SyncStatusCode status, | 62 typedef base::Callback<void(SyncStatusCode status, |
| 58 bool has_pending_changes)> | 63 bool has_pending_changes)> |
| 59 HasPendingLocalChangeCallback; | 64 HasPendingLocalChangeCallback; |
| 60 | 65 |
| 61 LocalFileSyncContext(base::SingleThreadTaskRunner* ui_task_runner, | 66 LocalFileSyncContext(base::SingleThreadTaskRunner* ui_task_runner, |
| 62 base::SingleThreadTaskRunner* io_task_runner); | 67 base::SingleThreadTaskRunner* io_task_runner); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 80 void GetFileForLocalSync(fileapi::FileSystemContext* file_system_context, | 85 void GetFileForLocalSync(fileapi::FileSystemContext* file_system_context, |
| 81 const LocalFileSyncInfoCallback& callback); | 86 const LocalFileSyncInfoCallback& callback); |
| 82 | 87 |
| 83 // Clears all pending local changes for |url|. |done_callback| is called | 88 // Clears all pending local changes for |url|. |done_callback| is called |
| 84 // when the changes are cleared. | 89 // when the changes are cleared. |
| 85 // This method must be called on UI thread. | 90 // This method must be called on UI thread. |
| 86 void ClearChangesForURL(fileapi::FileSystemContext* file_system_context, | 91 void ClearChangesForURL(fileapi::FileSystemContext* file_system_context, |
| 87 const fileapi::FileSystemURL& url, | 92 const fileapi::FileSystemURL& url, |
| 88 const base::Closure& done_callback); | 93 const base::Closure& done_callback); |
| 89 | 94 |
| 95 // Updates the on-disk dirty flag for |url| in the tracker DB. |
| 96 // This will clear the dirty flag if |sync_finish_status| is SYNC_STATUS_OK |
| 97 // or SYNC_STATUS_HAS_CONFLICT. |
| 98 // |done_callback| is called when the changes are committed. |
| 99 void CommitChangeStatusForURL( |
| 100 fileapi::FileSystemContext* file_system_context, |
| 101 const fileapi::FileSystemURL& url, |
| 102 SyncStatusCode sync_finish_status, |
| 103 const base::Closure& done_callback); |
| 104 |
| 90 // A local or remote sync has been finished (either successfully or | 105 // A local or remote sync has been finished (either successfully or |
| 91 // with an error). Clears the internal sync flag and enable writing for |url|. | 106 // with an error). Clears the internal sync flag and enable writing for |url|. |
| 92 // This method must be called on UI thread. | 107 // This method must be called on UI thread. |
| 93 void ClearSyncFlagForURL(const fileapi::FileSystemURL& url); | 108 void ClearSyncFlagForURL(const fileapi::FileSystemURL& url); |
| 94 | 109 |
| 95 // Prepares for sync |url| by disabling writes on |url|. | 110 // Prepares for sync |url| by disabling writes on |url|. |
| 96 // If the target |url| is being written and cannot start sync it | 111 // If the target |url| is being written and cannot start sync it |
| 97 // returns SYNC_STATUS_WRITING status code via |callback|. | 112 // returns SYNC_STATUS_WRITING status code via |callback|. |
| 98 // Otherwise it disables writes, marks the |url| syncing and returns | 113 // Otherwise returns the current change sets made on |url|. |
| 99 // the current change set made on |url|. | 114 // |
| 115 // If |sync_mode| is SYNC_EXCLUSIVE this leaves the target file. |
| 116 // If |sync_mode| is SYNC_SNAPSHOT this creates a snapshot (if the |
| 117 // target file is not deleted) and unlocks the file before returning. |
| 118 // |
| 100 // This method must be called on UI thread. | 119 // This method must be called on UI thread. |
| 101 void PrepareForSync(fileapi::FileSystemContext* file_system_context, | 120 void PrepareForSync(fileapi::FileSystemContext* file_system_context, |
| 102 const fileapi::FileSystemURL& url, | 121 const fileapi::FileSystemURL& url, |
| 122 SyncMode sync_mode, |
| 103 const LocalFileSyncInfoCallback& callback); | 123 const LocalFileSyncInfoCallback& callback); |
| 104 | 124 |
| 105 // Registers |url| to wait until sync is enabled for |url|. | 125 // Registers |url| to wait until sync is enabled for |url|. |
| 106 // |on_syncable_callback| is to be called when |url| becomes syncable | 126 // |on_syncable_callback| is to be called when |url| becomes syncable |
| 107 // (i.e. when we have no pending writes and the file is successfully locked | 127 // (i.e. when we have no pending writes and the file is successfully locked |
| 108 // for sync). | 128 // for sync). |
| 109 // | 129 // |
| 110 // Calling this method again while this already has another URL waiting | 130 // Calling this method again while this already has another URL waiting |
| 111 // for sync will overwrite the previously registered URL. | 131 // for sync will overwrite the previously registered URL. |
| 112 // | 132 // |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 std::deque<fileapi::FileSystemURL>* remaining_urls, | 237 std::deque<fileapi::FileSystemURL>* remaining_urls, |
| 218 const LocalFileSyncInfoCallback& callback, | 238 const LocalFileSyncInfoCallback& callback, |
| 219 SyncStatusCode status, | 239 SyncStatusCode status, |
| 220 const LocalFileSyncInfo& sync_file_info); | 240 const LocalFileSyncInfo& sync_file_info); |
| 221 | 241 |
| 222 // Callback routine for PrepareForSync and GetFileForLocalSync. | 242 // Callback routine for PrepareForSync and GetFileForLocalSync. |
| 223 void DidGetWritingStatusForSync( | 243 void DidGetWritingStatusForSync( |
| 224 fileapi::FileSystemContext* file_system_context, | 244 fileapi::FileSystemContext* file_system_context, |
| 225 SyncStatusCode status, | 245 SyncStatusCode status, |
| 226 const fileapi::FileSystemURL& url, | 246 const fileapi::FileSystemURL& url, |
| 247 SyncMode sync_mode, |
| 227 const LocalFileSyncInfoCallback& callback); | 248 const LocalFileSyncInfoCallback& callback); |
| 228 | 249 |
| 229 // Helper routine for ClearSyncFlagForURL. | 250 // Helper routine for ClearSyncFlagForURL. |
| 230 void EnableWritingOnIOThread(const fileapi::FileSystemURL& url); | 251 void EnableWritingOnIOThread(const fileapi::FileSystemURL& url, |
| 252 bool may_have_updates); |
| 231 | 253 |
| 232 void DidRemoveExistingEntryForApplyRemoteChange( | 254 void DidRemoveExistingEntryForApplyRemoteChange( |
| 233 fileapi::FileSystemContext* file_system_context, | 255 fileapi::FileSystemContext* file_system_context, |
| 234 const FileChange& change, | 256 const FileChange& change, |
| 235 const base::FilePath& local_path, | 257 const base::FilePath& local_path, |
| 236 const fileapi::FileSystemURL& url, | 258 const fileapi::FileSystemURL& url, |
| 237 const SyncStatusCallback& callback, | 259 const SyncStatusCallback& callback, |
| 238 base::PlatformFileError error); | 260 base::PlatformFileError error); |
| 239 | 261 |
| 240 // Callback routine for ApplyRemoteChange. | 262 // Callback routine for ApplyRemoteChange. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 ObserverList<LocalOriginChangeObserver> origin_change_observers_; | 314 ObserverList<LocalOriginChangeObserver> origin_change_observers_; |
| 293 | 315 |
| 294 int mock_notify_changes_duration_in_sec_; | 316 int mock_notify_changes_duration_in_sec_; |
| 295 | 317 |
| 296 DISALLOW_COPY_AND_ASSIGN(LocalFileSyncContext); | 318 DISALLOW_COPY_AND_ASSIGN(LocalFileSyncContext); |
| 297 }; | 319 }; |
| 298 | 320 |
| 299 } // namespace sync_file_system | 321 } // namespace sync_file_system |
| 300 | 322 |
| 301 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_LOCAL_FILE_SYNC_CONTEXT_H_ | 323 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_LOCAL_FILE_SYNC_CONTEXT_H_ |
| OLD | NEW |