sync_file_system_backend.h revision 03b57e008b61dfcb1fbad3aea950ae0e001748b0
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 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_SYNC_FILE_SYSTEM_BACKEND_H_ 6#define CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_SYNC_FILE_SYSTEM_BACKEND_H_ 7 8#include "chrome/browser/profiles/profile.h" 9#include "chrome/browser/sync_file_system/sync_callbacks.h" 10#include "chrome/browser/sync_file_system/sync_status_code.h" 11#include "content/public/browser/notification_observer.h" 12#include "content/public/browser/notification_registrar.h" 13#include "webkit/browser/fileapi/file_system_backend.h" 14#include "webkit/browser/fileapi/file_system_quota_util.h" 15#include "webkit/browser/fileapi/sandbox_file_system_backend_delegate.h" 16 17namespace sync_file_system { 18 19class LocalFileChangeTracker; 20class LocalFileSyncContext; 21 22class SyncFileSystemBackend : public storage::FileSystemBackend { 23 public: 24 explicit SyncFileSystemBackend(Profile* profile); 25 virtual ~SyncFileSystemBackend(); 26 27 static SyncFileSystemBackend* CreateForTesting(); 28 29 // FileSystemBackend overrides. 30 virtual bool CanHandleType(storage::FileSystemType type) const OVERRIDE; 31 virtual void Initialize(storage::FileSystemContext* context) OVERRIDE; 32 virtual void ResolveURL(const storage::FileSystemURL& url, 33 storage::OpenFileSystemMode mode, 34 const OpenFileSystemCallback& callback) OVERRIDE; 35 virtual storage::AsyncFileUtil* GetAsyncFileUtil( 36 storage::FileSystemType type) OVERRIDE; 37 virtual storage::CopyOrMoveFileValidatorFactory* 38 GetCopyOrMoveFileValidatorFactory(storage::FileSystemType type, 39 base::File::Error* error_code) OVERRIDE; 40 virtual storage::FileSystemOperation* CreateFileSystemOperation( 41 const storage::FileSystemURL& url, 42 storage::FileSystemContext* context, 43 base::File::Error* error_code) const OVERRIDE; 44 virtual bool SupportsStreaming( 45 const storage::FileSystemURL& url) const OVERRIDE; 46 virtual bool HasInplaceCopyImplementation( 47 storage::FileSystemType type) const OVERRIDE; 48 virtual scoped_ptr<storage::FileStreamReader> CreateFileStreamReader( 49 const storage::FileSystemURL& url, 50 int64 offset, 51 const base::Time& expected_modification_time, 52 storage::FileSystemContext* context) const OVERRIDE; 53 virtual scoped_ptr<storage::FileStreamWriter> CreateFileStreamWriter( 54 const storage::FileSystemURL& url, 55 int64 offset, 56 storage::FileSystemContext* context) const OVERRIDE; 57 virtual storage::FileSystemQuotaUtil* GetQuotaUtil() OVERRIDE; 58 59 static SyncFileSystemBackend* GetBackend( 60 const storage::FileSystemContext* context); 61 62 LocalFileChangeTracker* change_tracker() { return change_tracker_.get(); } 63 void SetLocalFileChangeTracker(scoped_ptr<LocalFileChangeTracker> tracker); 64 65 LocalFileSyncContext* sync_context() { return sync_context_.get(); } 66 void set_sync_context(LocalFileSyncContext* sync_context); 67 68 private: 69 class ProfileHolder : public content::NotificationObserver { 70 public: 71 explicit ProfileHolder(Profile* profile); 72 73 // NotificationObserver override. 74 virtual void Observe(int type, 75 const content::NotificationSource& source, 76 const content::NotificationDetails& details) OVERRIDE; 77 78 Profile* GetProfile(); 79 80 private: 81 content::NotificationRegistrar registrar_; 82 Profile* profile_; 83 }; 84 85 // Not owned. 86 storage::FileSystemContext* context_; 87 88 scoped_ptr<LocalFileChangeTracker> change_tracker_; 89 scoped_refptr<LocalFileSyncContext> sync_context_; 90 91 // Should be accessed on the UI thread. 92 scoped_ptr<ProfileHolder> profile_holder_; 93 94 // A flag to skip the initialization sequence of SyncFileSystemService for 95 // testing. 96 bool skip_initialize_syncfs_service_for_testing_; 97 98 storage::SandboxFileSystemBackendDelegate* GetDelegate() const; 99 100 void InitializeSyncFileSystemService( 101 const GURL& origin_url, 102 const SyncStatusCallback& callback); 103 void DidInitializeSyncFileSystemService( 104 storage::FileSystemContext* context, 105 const GURL& origin_url, 106 storage::FileSystemType type, 107 storage::OpenFileSystemMode mode, 108 const OpenFileSystemCallback& callback, 109 SyncStatusCode status); 110 111 DISALLOW_COPY_AND_ASSIGN(SyncFileSystemBackend); 112}; 113 114} // namespace sync_file_system 115 116#endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_SYNC_FILE_SYSTEM_BACKEND_H_ 117