Home | History | Annotate | Download | only in local
      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 
     17 namespace sync_file_system {
     18 
     19 class LocalFileChangeTracker;
     20 class LocalFileSyncContext;
     21 
     22 class SyncFileSystemBackend
     23     : public fileapi::FileSystemBackend {
     24  public:
     25   explicit SyncFileSystemBackend(Profile* profile);
     26   virtual ~SyncFileSystemBackend();
     27 
     28   static SyncFileSystemBackend* CreateForTesting();
     29 
     30   // FileSystemBackend overrides.
     31   virtual bool CanHandleType(fileapi::FileSystemType type) const OVERRIDE;
     32   virtual void Initialize(fileapi::FileSystemContext* context) OVERRIDE;
     33   virtual void OpenFileSystem(
     34       const GURL& origin_url,
     35       fileapi::FileSystemType type,
     36       fileapi::OpenFileSystemMode mode,
     37       const OpenFileSystemCallback& callback) OVERRIDE;
     38   virtual fileapi::AsyncFileUtil* GetAsyncFileUtil(
     39       fileapi::FileSystemType type) OVERRIDE;
     40   virtual fileapi::CopyOrMoveFileValidatorFactory*
     41       GetCopyOrMoveFileValidatorFactory(
     42           fileapi::FileSystemType type,
     43           base::PlatformFileError* error_code) OVERRIDE;
     44   virtual fileapi::FileSystemOperation* CreateFileSystemOperation(
     45       const fileapi::FileSystemURL& url,
     46       fileapi::FileSystemContext* context,
     47       base::PlatformFileError* error_code) const OVERRIDE;
     48   virtual scoped_ptr<webkit_blob::FileStreamReader> CreateFileStreamReader(
     49       const fileapi::FileSystemURL& url,
     50       int64 offset,
     51       const base::Time& expected_modification_time,
     52       fileapi::FileSystemContext* context) const OVERRIDE;
     53   virtual scoped_ptr<fileapi::FileStreamWriter> CreateFileStreamWriter(
     54       const fileapi::FileSystemURL& url,
     55       int64 offset,
     56       fileapi::FileSystemContext* context) const OVERRIDE;
     57   virtual fileapi::FileSystemQuotaUtil* GetQuotaUtil() OVERRIDE;
     58 
     59   static SyncFileSystemBackend* GetBackend(
     60       const fileapi::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   fileapi::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   fileapi::SandboxFileSystemBackendDelegate* GetDelegate() const;
     99 
    100   void InitializeSyncFileSystemService(
    101       const GURL& origin_url,
    102       const SyncStatusCallback& callback);
    103   void DidInitializeSyncFileSystemService(
    104       fileapi::FileSystemContext* context,
    105       const GURL& origin_url,
    106       fileapi::FileSystemType type,
    107       fileapi::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