| 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 15 matching lines...) Expand all  Loading... | 
| 26 | 26 | 
| 27 namespace base { | 27 namespace base { | 
| 28 class SingleThreadTaskRunner; | 28 class SingleThreadTaskRunner; | 
| 29 } | 29 } | 
| 30 | 30 | 
| 31 namespace fileapi { | 31 namespace fileapi { | 
| 32 class FileSystemContext; | 32 class FileSystemContext; | 
| 33 class FileSystemURL; | 33 class FileSystemURL; | 
| 34 } | 34 } | 
| 35 | 35 | 
|  | 36 namespace webkit_blob { | 
|  | 37 class ScopedFile; | 
|  | 38 } | 
|  | 39 | 
| 36 namespace sync_file_system { | 40 namespace sync_file_system { | 
| 37 | 41 | 
| 38 class FileChange; | 42 class FileChange; | 
| 39 class LocalFileChangeTracker; | 43 class LocalFileChangeTracker; | 
| 40 struct LocalFileSyncInfo; | 44 struct LocalFileSyncInfo; | 
| 41 class LocalOriginChangeObserver; | 45 class LocalOriginChangeObserver; | 
| 42 class SyncableFileOperationRunner; | 46 class SyncableFileOperationRunner; | 
| 43 | 47 | 
| 44 // This class works as a bridge between LocalFileSyncService (which is a | 48 // This class works as a bridge between LocalFileSyncService (which is a | 
| 45 // per-profile object) and FileSystemContext's (which is a per-storage-partition | 49 // per-profile object) and FileSystemContext's (which is a per-storage-partition | 
| 46 // object and may exist multiple in a profile). | 50 // object and may exist multiple in a profile). | 
| 47 // An instance of this class is shared by FileSystemContexts and outlives | 51 // An instance of this class is shared by FileSystemContexts and outlives | 
| 48 // LocalFileSyncService. | 52 // LocalFileSyncService. | 
| 49 class LocalFileSyncContext | 53 class LocalFileSyncContext | 
| 50     : public base::RefCountedThreadSafe<LocalFileSyncContext>, | 54     : public base::RefCountedThreadSafe<LocalFileSyncContext>, | 
| 51       public LocalFileSyncStatus::Observer { | 55       public LocalFileSyncStatus::Observer { | 
| 52  public: | 56  public: | 
| 53   enum SyncMode { | 57   enum SyncMode { | 
| 54     SYNC_EXCLUSIVE, | 58     SYNC_EXCLUSIVE, | 
| 55     SYNC_SNAPSHOT, | 59     SYNC_SNAPSHOT, | 
| 56   }; | 60   }; | 
| 57 | 61 | 
| 58   typedef base::Callback<void( | 62   typedef base::Callback<void( | 
| 59       SyncStatusCode status, const LocalFileSyncInfo& sync_file_info)> | 63       SyncStatusCode status, | 
|  | 64       const LocalFileSyncInfo& sync_file_info, | 
|  | 65       scoped_ptr<webkit_blob::ScopedFile> snapshot)> | 
| 60           LocalFileSyncInfoCallback; | 66           LocalFileSyncInfoCallback; | 
| 61 | 67 | 
| 62   typedef base::Callback<void(SyncStatusCode status, | 68   typedef base::Callback<void(SyncStatusCode status, | 
| 63                               bool has_pending_changes)> | 69                               bool has_pending_changes)> | 
| 64       HasPendingLocalChangeCallback; | 70       HasPendingLocalChangeCallback; | 
| 65 | 71 | 
| 66   LocalFileSyncContext(base::SingleThreadTaskRunner* ui_task_runner, | 72   LocalFileSyncContext(const base::FilePath& base_path, | 
|  | 73                        base::SingleThreadTaskRunner* ui_task_runner, | 
| 67                        base::SingleThreadTaskRunner* io_task_runner); | 74                        base::SingleThreadTaskRunner* io_task_runner); | 
| 68 | 75 | 
| 69   // Initializes |file_system_context| for syncable file operations | 76   // Initializes |file_system_context| for syncable file operations | 
| 70   // and registers the it into the internal map. | 77   // and registers the it into the internal map. | 
| 71   // Calling this multiple times for the same file_system_context is valid. | 78   // Calling this multiple times for the same file_system_context is valid. | 
| 72   // This method must be called on UI thread. | 79   // This method must be called on UI thread. | 
| 73   void MaybeInitializeFileSystemContext( | 80   void MaybeInitializeFileSystemContext( | 
| 74       const GURL& source_url, | 81       const GURL& source_url, | 
| 75       fileapi::FileSystemContext* file_system_context, | 82       fileapi::FileSystemContext* file_system_context, | 
| 76       const SyncStatusCallback& callback); | 83       const SyncStatusCallback& callback); | 
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 230       std::deque<fileapi::FileSystemURL>* urls); | 237       std::deque<fileapi::FileSystemURL>* urls); | 
| 231   void TryPrepareForLocalSync( | 238   void TryPrepareForLocalSync( | 
| 232       fileapi::FileSystemContext* file_system_context, | 239       fileapi::FileSystemContext* file_system_context, | 
| 233       std::deque<fileapi::FileSystemURL>* urls, | 240       std::deque<fileapi::FileSystemURL>* urls, | 
| 234       const LocalFileSyncInfoCallback& callback); | 241       const LocalFileSyncInfoCallback& callback); | 
| 235   void DidTryPrepareForLocalSync( | 242   void DidTryPrepareForLocalSync( | 
| 236       fileapi::FileSystemContext* file_system_context, | 243       fileapi::FileSystemContext* file_system_context, | 
| 237       std::deque<fileapi::FileSystemURL>* remaining_urls, | 244       std::deque<fileapi::FileSystemURL>* remaining_urls, | 
| 238       const LocalFileSyncInfoCallback& callback, | 245       const LocalFileSyncInfoCallback& callback, | 
| 239       SyncStatusCode status, | 246       SyncStatusCode status, | 
| 240       const LocalFileSyncInfo& sync_file_info); | 247       const LocalFileSyncInfo& sync_file_info, | 
|  | 248       scoped_ptr<webkit_blob::ScopedFile> snapshot); | 
| 241 | 249 | 
| 242   // Callback routine for PrepareForSync and GetFileForLocalSync. | 250   // Callback routine for PrepareForSync and GetFileForLocalSync. | 
| 243   void DidGetWritingStatusForSync( | 251   void DidGetWritingStatusForSync( | 
| 244       fileapi::FileSystemContext* file_system_context, | 252       fileapi::FileSystemContext* file_system_context, | 
| 245       SyncStatusCode status, | 253       SyncStatusCode status, | 
| 246       const fileapi::FileSystemURL& url, | 254       const fileapi::FileSystemURL& url, | 
| 247       SyncMode sync_mode, | 255       SyncMode sync_mode, | 
| 248       const LocalFileSyncInfoCallback& callback); | 256       const LocalFileSyncInfoCallback& callback); | 
| 249 | 257 | 
| 250   // Helper routine for ClearSyncFlagForURL. | 258   // Helper routine for sync/writing flag handling, primarily for | 
| 251   void EnableWritingOnIOThread(const fileapi::FileSystemURL& url, | 259   // ClearSyncFlagForURL but is also called by other internal routines. | 
| 252                                bool may_have_updates); | 260   // If |keep_url_in_writing| is true this increments the writing counter | 
|  | 261   // for |url| (after clearing syncing flag), so that the caller can | 
|  | 262   // continue to hold a shared lock on the URL. | 
|  | 263   // (The counter must be manually decremented by EndWritingOnIOThread | 
|  | 264   // if that's the case) | 
|  | 265   void ClearSyncFlagOnIOThread(const fileapi::FileSystemURL& url, | 
|  | 266                                bool keep_url_in_writing); | 
|  | 267   void EndWritingOnIOThread(const fileapi::FileSystemURL& url); | 
| 253 | 268 | 
| 254   void DidRemoveExistingEntryForApplyRemoteChange( | 269   void DidRemoveExistingEntryForApplyRemoteChange( | 
| 255       fileapi::FileSystemContext* file_system_context, | 270       fileapi::FileSystemContext* file_system_context, | 
| 256       const FileChange& change, | 271       const FileChange& change, | 
| 257       const base::FilePath& local_path, | 272       const base::FilePath& local_path, | 
| 258       const fileapi::FileSystemURL& url, | 273       const fileapi::FileSystemURL& url, | 
| 259       const SyncStatusCallback& callback, | 274       const SyncStatusCallback& callback, | 
| 260       base::PlatformFileError error); | 275       base::PlatformFileError error); | 
| 261 | 276 | 
| 262   // Callback routine for ApplyRemoteChange. | 277   // Callback routine for ApplyRemoteChange. | 
| 263   void DidApplyRemoteChange( | 278   void DidApplyRemoteChange( | 
| 264       const fileapi::FileSystemURL& url, | 279       const fileapi::FileSystemURL& url, | 
| 265       const SyncStatusCallback& callback_on_ui, | 280       const SyncStatusCallback& callback_on_ui, | 
| 266       base::PlatformFileError file_error); | 281       base::PlatformFileError file_error); | 
| 267 | 282 | 
| 268   void DidGetFileMetadata( | 283   void DidGetFileMetadata( | 
| 269       const SyncFileMetadataCallback& callback, | 284       const SyncFileMetadataCallback& callback, | 
| 270       base::PlatformFileError file_error, | 285       base::PlatformFileError file_error, | 
| 271       const base::PlatformFileInfo& file_info); | 286       const base::PlatformFileInfo& file_info); | 
| 272 | 287 | 
| 273   base::TimeDelta NotifyChangesDuration(); | 288   base::TimeDelta NotifyChangesDuration(); | 
| 274 | 289 | 
| 275   void DidCreateDirectoryForCopyIn( | 290   void DidCreateDirectoryForCopyIn( | 
| 276       fileapi::FileSystemContext* file_system_context, | 291       fileapi::FileSystemContext* file_system_context, | 
| 277       const base::FilePath& local_file_path, | 292       const base::FilePath& local_file_path, | 
| 278       const fileapi::FileSystemURL& dest_url, | 293       const fileapi::FileSystemURL& dest_url, | 
| 279       const StatusCallback& callback, | 294       const StatusCallback& callback, | 
| 280       base::PlatformFileError error); | 295       base::PlatformFileError error); | 
| 281 | 296 | 
|  | 297   const base::FilePath local_base_path_; | 
|  | 298 | 
| 282   scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | 299   scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | 
| 283   scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 300   scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 
| 284 | 301 | 
| 285   // Indicates if the sync service is shutdown on UI thread. | 302   // Indicates if the sync service is shutdown on UI thread. | 
| 286   bool shutdown_on_ui_; | 303   bool shutdown_on_ui_; | 
| 287 | 304 | 
| 288   // OperationRunner. This must be accessed only on IO thread. | 305   // OperationRunner. This must be accessed only on IO thread. | 
| 289   scoped_ptr<SyncableFileOperationRunner> operation_runner_; | 306   scoped_ptr<SyncableFileOperationRunner> operation_runner_; | 
| 290 | 307 | 
| 291   // Keeps track of writing/syncing status. | 308   // Keeps track of writing/syncing status. | 
| (...skipping 22 matching lines...) Expand all  Loading... | 
| 314   ObserverList<LocalOriginChangeObserver> origin_change_observers_; | 331   ObserverList<LocalOriginChangeObserver> origin_change_observers_; | 
| 315 | 332 | 
| 316   int mock_notify_changes_duration_in_sec_; | 333   int mock_notify_changes_duration_in_sec_; | 
| 317 | 334 | 
| 318   DISALLOW_COPY_AND_ASSIGN(LocalFileSyncContext); | 335   DISALLOW_COPY_AND_ASSIGN(LocalFileSyncContext); | 
| 319 }; | 336 }; | 
| 320 | 337 | 
| 321 }  // namespace sync_file_system | 338 }  // namespace sync_file_system | 
| 322 | 339 | 
| 323 #endif  // CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_LOCAL_FILE_SYNC_CONTEXT_H_ | 340 #endif  // CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_LOCAL_FILE_SYNC_CONTEXT_H_ | 
| OLD | NEW | 
|---|