Update To 11.40.268.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   ~MediaFileSystemBackend() override;
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   bool CanHandleType(storage::FileSystemType type) const override;
59   void Initialize(storage::FileSystemContext* context) override;
60   void ResolveURL(const storage::FileSystemURL& url,
61                   storage::OpenFileSystemMode mode,
62                   const OpenFileSystemCallback& callback) override;
63   storage::AsyncFileUtil* GetAsyncFileUtil(
64       storage::FileSystemType type) override;
65   storage::WatcherManager* GetWatcherManager(
66       storage::FileSystemType type) override;
67   storage::CopyOrMoveFileValidatorFactory* GetCopyOrMoveFileValidatorFactory(
68       storage::FileSystemType type,
69       base::File::Error* error_code) override;
70   storage::FileSystemOperation* CreateFileSystemOperation(
71       const storage::FileSystemURL& url,
72       storage::FileSystemContext* context,
73       base::File::Error* error_code) const override;
74   bool SupportsStreaming(const storage::FileSystemURL& url) const override;
75   bool HasInplaceCopyImplementation(
76       storage::FileSystemType type) const override;
77   scoped_ptr<storage::FileStreamReader> CreateFileStreamReader(
78       const storage::FileSystemURL& url,
79       int64 offset,
80       int64 max_bytes_to_read,
81       const base::Time& expected_modification_time,
82       storage::FileSystemContext* context) const override;
83   scoped_ptr<storage::FileStreamWriter> CreateFileStreamWriter(
84       const storage::FileSystemURL& url,
85       int64 offset,
86       storage::FileSystemContext* context) const override;
87   storage::FileSystemQuotaUtil* GetQuotaUtil() override;
88   const storage::UpdateObserverList* GetUpdateObservers(
89       storage::FileSystemType type) const override;
90   const storage::ChangeObserverList* GetChangeObservers(
91       storage::FileSystemType type) const override;
92   const storage::AccessObserverList* GetAccessObservers(
93       storage::FileSystemType type) const override;
94
95  private:
96   // Store the profile path. We need this to create temporary snapshot files.
97   const base::FilePath profile_path_;
98
99   scoped_refptr<base::SequencedTaskRunner> media_task_runner_;
100
101   scoped_ptr<MediaPathFilter> media_path_filter_;
102   scoped_ptr<storage::CopyOrMoveFileValidatorFactory>
103       media_copy_or_move_file_validator_factory_;
104
105   scoped_ptr<storage::AsyncFileUtil> native_media_file_util_;
106   scoped_ptr<DeviceMediaAsyncFileUtil> device_media_async_file_util_;
107 #if defined(OS_WIN) || defined(OS_MACOSX)
108   scoped_ptr<storage::AsyncFileUtil> picasa_file_util_;
109   scoped_ptr<storage::AsyncFileUtil> itunes_file_util_;
110 #endif  // defined(OS_WIN) || defined(OS_MACOSX)
111 #if defined(OS_MACOSX)
112   scoped_ptr<storage::AsyncFileUtil> iphoto_file_util_;
113 #endif  // defined(OS_MACOSX)
114
115   DISALLOW_COPY_AND_ASSIGN(MediaFileSystemBackend);
116 };
117
118 #endif  // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_MEDIA_FILE_SYSTEM_BACKEND_H_