Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / media_galleries / fileapi / media_file_system_backend.h
1 // Copyright (c) 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_MEDIA_GALLERIES_FILEAPI_MEDIA_FILE_SYSTEM_BACKEND_H_
6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_MEDIA_FILE_SYSTEM_BACKEND_H_
7
8 #include <string>
9
10 #include "base/callback.h"
11 #include "base/files/file_path.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "chrome/browser/media_galleries/media_galleries_preferences.h"
15 #include "storage/browser/fileapi/file_system_backend.h"
16 #include "storage/browser/fileapi/task_runner_bound_observer_list.h"
17
18 namespace base {
19 class SequencedTaskRunner;
20 }
21
22 namespace storage {
23 class FileSystemURL;
24 }
25
26 namespace net {
27 class URLRequest;
28 }
29
30 class MediaPathFilter;
31 class DeviceMediaAsyncFileUtil;
32
33 class MediaFileSystemBackend : public storage::FileSystemBackend {
34  public:
35   static const char kMediaTaskRunnerName[];
36
37   MediaFileSystemBackend(
38       const base::FilePath& profile_path,
39       base::SequencedTaskRunner* media_task_runner);
40   virtual ~MediaFileSystemBackend();
41
42   static bool CurrentlyOnMediaTaskRunnerThread();
43   static scoped_refptr<base::SequencedTaskRunner> MediaTaskRunner();
44
45   // Construct the mount point for the gallery specified by |pref_id| in
46   // the profile located in |profile_path|.
47   static std::string ConstructMountName(const base::FilePath& profile_path,
48                                         const std::string& extension_id,
49                                         MediaGalleryPrefId pref_id);
50
51   static bool AttemptAutoMountForURLRequest(
52       const net::URLRequest* url_request,
53       const storage::FileSystemURL& filesystem_url,
54       const std::string& storage_domain,
55       const base::Callback<void(base::File::Error result)>& callback);
56
57   // FileSystemBackend implementation.
58   virtual bool CanHandleType(storage::FileSystemType type) const OVERRIDE;
59   virtual void Initialize(storage::FileSystemContext* context) OVERRIDE;
60   virtual void ResolveURL(const storage::FileSystemURL& url,
61                           storage::OpenFileSystemMode mode,
62                           const OpenFileSystemCallback& callback) OVERRIDE;
63   virtual storage::AsyncFileUtil* GetAsyncFileUtil(
64       storage::FileSystemType type) OVERRIDE;
65   virtual storage::WatcherManager* GetWatcherManager(
66       storage::FileSystemType type) OVERRIDE;
67   virtual storage::CopyOrMoveFileValidatorFactory*
68       GetCopyOrMoveFileValidatorFactory(storage::FileSystemType type,
69                                         base::File::Error* error_code) OVERRIDE;
70   virtual storage::FileSystemOperation* CreateFileSystemOperation(
71       const storage::FileSystemURL& url,
72       storage::FileSystemContext* context,
73       base::File::Error* error_code) const OVERRIDE;
74   virtual bool SupportsStreaming(
75       const storage::FileSystemURL& url) const OVERRIDE;
76   virtual bool HasInplaceCopyImplementation(
77       storage::FileSystemType type) const OVERRIDE;
78   virtual scoped_ptr<storage::FileStreamReader> CreateFileStreamReader(
79       const storage::FileSystemURL& url,
80       int64 offset,
81       int64 max_bytes_to_read,
82       const base::Time& expected_modification_time,
83       storage::FileSystemContext* context) const OVERRIDE;
84   virtual scoped_ptr<storage::FileStreamWriter> CreateFileStreamWriter(
85       const storage::FileSystemURL& url,
86       int64 offset,
87       storage::FileSystemContext* context) const OVERRIDE;
88   virtual storage::FileSystemQuotaUtil* GetQuotaUtil() OVERRIDE;
89   virtual const storage::UpdateObserverList* GetUpdateObservers(
90       storage::FileSystemType type) const OVERRIDE;
91   virtual const storage::ChangeObserverList* GetChangeObservers(
92       storage::FileSystemType type) const OVERRIDE;
93   virtual const storage::AccessObserverList* GetAccessObservers(
94       storage::FileSystemType type) const OVERRIDE;
95
96  private:
97   // Store the profile path. We need this to create temporary snapshot files.
98   const base::FilePath profile_path_;
99
100   scoped_refptr<base::SequencedTaskRunner> media_task_runner_;
101
102   scoped_ptr<MediaPathFilter> media_path_filter_;
103   scoped_ptr<storage::CopyOrMoveFileValidatorFactory>
104       media_copy_or_move_file_validator_factory_;
105
106   scoped_ptr<storage::AsyncFileUtil> native_media_file_util_;
107   scoped_ptr<DeviceMediaAsyncFileUtil> device_media_async_file_util_;
108 #if defined(OS_WIN) || defined(OS_MACOSX)
109   scoped_ptr<storage::AsyncFileUtil> picasa_file_util_;
110   scoped_ptr<storage::AsyncFileUtil> itunes_file_util_;
111 #endif  // defined(OS_WIN) || defined(OS_MACOSX)
112 #if defined(OS_MACOSX)
113   scoped_ptr<storage::AsyncFileUtil> iphoto_file_util_;
114 #endif  // defined(OS_MACOSX)
115
116   DISALLOW_COPY_AND_ASSIGN(MediaFileSystemBackend);
117 };
118
119 #endif  // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_MEDIA_FILE_SYSTEM_BACKEND_H_