OLD | NEW |
| (Empty) |
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 #include "chrome/browser/media_galleries/fileapi/media_file_system_mount_point_p
rovider.h" | |
6 | |
7 #include <string> | |
8 | |
9 #include "base/bind.h" | |
10 #include "base/files/file_path.h" | |
11 #include "base/logging.h" | |
12 #include "base/message_loop/message_loop_proxy.h" | |
13 #include "base/platform_file.h" | |
14 #include "base/sequenced_task_runner.h" | |
15 #include "base/threading/sequenced_worker_pool.h" | |
16 #include "chrome/browser/media_galleries/fileapi/device_media_async_file_util.h" | |
17 #include "chrome/browser/media_galleries/fileapi/media_file_validator_factory.h" | |
18 #include "chrome/browser/media_galleries/fileapi/media_path_filter.h" | |
19 #include "chrome/browser/media_galleries/fileapi/native_media_file_util.h" | |
20 #include "content/public/browser/browser_thread.h" | |
21 #include "webkit/browser/blob/local_file_stream_reader.h" | |
22 #include "webkit/browser/fileapi/async_file_util_adapter.h" | |
23 #include "webkit/browser/fileapi/copy_or_move_file_validator.h" | |
24 #include "webkit/browser/fileapi/file_system_context.h" | |
25 #include "webkit/browser/fileapi/file_system_file_stream_reader.h" | |
26 #include "webkit/browser/fileapi/file_system_operation_context.h" | |
27 #include "webkit/browser/fileapi/file_system_task_runners.h" | |
28 #include "webkit/browser/fileapi/isolated_context.h" | |
29 #include "webkit/browser/fileapi/isolated_file_util.h" | |
30 #include "webkit/browser/fileapi/local_file_stream_writer.h" | |
31 #include "webkit/browser/fileapi/local_file_system_operation.h" | |
32 #include "webkit/browser/fileapi/native_file_util.h" | |
33 #include "webkit/common/fileapi/file_system_types.h" | |
34 #include "webkit/common/fileapi/file_system_util.h" | |
35 | |
36 #if defined(OS_WIN) || defined(OS_MACOSX) | |
37 #include "chrome/browser/media_galleries/fileapi/itunes_file_util.h" | |
38 #include "chrome/browser/media_galleries/fileapi/picasa/picasa_file_util.h" | |
39 #endif // defined(OS_WIN) || defined(OS_MACOSX) | |
40 | |
41 using fileapi::FileSystemContext; | |
42 using fileapi::FileSystemURL; | |
43 | |
44 namespace chrome { | |
45 | |
46 const char MediaFileSystemMountPointProvider::kMediaTaskRunnerName[] = | |
47 "media-task-runner"; | |
48 const char MediaFileSystemMountPointProvider::kMediaPathFilterKey[] = | |
49 "MediaPathFilterKey"; | |
50 const char MediaFileSystemMountPointProvider::kMTPDeviceDelegateURLKey[] = | |
51 "MTPDeviceDelegateKey"; | |
52 | |
53 MediaFileSystemMountPointProvider::MediaFileSystemMountPointProvider( | |
54 const base::FilePath& profile_path, | |
55 base::SequencedTaskRunner* media_task_runner) | |
56 : profile_path_(profile_path), | |
57 media_task_runner_(media_task_runner), | |
58 media_path_filter_(new MediaPathFilter), | |
59 media_copy_or_move_file_validator_factory_(new MediaFileValidatorFactory), | |
60 native_media_file_util_(new NativeMediaFileUtil()), | |
61 device_media_async_file_util_( | |
62 DeviceMediaAsyncFileUtil::Create(profile_path_)) | |
63 #if defined(OS_WIN) || defined(OS_MACOSX) | |
64 , | |
65 picasa_file_util_(new picasa::PicasaFileUtil()), | |
66 itunes_file_util_(new itunes::ItunesFileUtil()) | |
67 #endif // defined(OS_WIN) || defined(OS_MACOSX) | |
68 { | |
69 } | |
70 | |
71 MediaFileSystemMountPointProvider::~MediaFileSystemMountPointProvider() { | |
72 } | |
73 | |
74 // static | |
75 bool MediaFileSystemMountPointProvider::CurrentlyOnMediaTaskRunnerThread() { | |
76 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool(); | |
77 base::SequencedWorkerPool::SequenceToken media_sequence_token = | |
78 pool->GetNamedSequenceToken(kMediaTaskRunnerName); | |
79 return pool->IsRunningSequenceOnCurrentThread(media_sequence_token); | |
80 } | |
81 | |
82 // static | |
83 scoped_refptr<base::SequencedTaskRunner> | |
84 MediaFileSystemMountPointProvider::MediaTaskRunner() { | |
85 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool(); | |
86 base::SequencedWorkerPool::SequenceToken media_sequence_token = | |
87 pool->GetNamedSequenceToken(kMediaTaskRunnerName); | |
88 return pool->GetSequencedTaskRunner(media_sequence_token); | |
89 } | |
90 | |
91 bool MediaFileSystemMountPointProvider::CanHandleType( | |
92 fileapi::FileSystemType type) const { | |
93 switch (type) { | |
94 case fileapi::kFileSystemTypeNativeMedia: | |
95 case fileapi::kFileSystemTypeDeviceMedia: | |
96 #if defined(OS_WIN) || defined(OS_MACOSX) | |
97 case fileapi::kFileSystemTypePicasa: | |
98 case fileapi::kFileSystemTypeItunes: | |
99 #endif // defined(OS_WIN) || defined(OS_MACOSX) | |
100 return true; | |
101 default: | |
102 return false; | |
103 } | |
104 } | |
105 | |
106 void MediaFileSystemMountPointProvider::OpenFileSystem( | |
107 const GURL& origin_url, | |
108 fileapi::FileSystemType type, | |
109 fileapi::OpenFileSystemMode mode, | |
110 const OpenFileSystemCallback& callback) { | |
111 // We never allow opening a new isolated FileSystem via usual OpenFileSystem. | |
112 base::MessageLoopProxy::current()->PostTask( | |
113 FROM_HERE, | |
114 base::Bind(callback, base::PLATFORM_FILE_ERROR_SECURITY)); | |
115 } | |
116 | |
117 fileapi::FileSystemFileUtil* MediaFileSystemMountPointProvider::GetFileUtil( | |
118 fileapi::FileSystemType type) { | |
119 NOTREACHED(); | |
120 return NULL; | |
121 } | |
122 | |
123 fileapi::AsyncFileUtil* MediaFileSystemMountPointProvider::GetAsyncFileUtil( | |
124 fileapi::FileSystemType type) { | |
125 switch (type) { | |
126 case fileapi::kFileSystemTypeNativeMedia: | |
127 return native_media_file_util_.get(); | |
128 case fileapi::kFileSystemTypeDeviceMedia: | |
129 return device_media_async_file_util_.get(); | |
130 #if defined(OS_WIN) || defined(OS_MACOSX) | |
131 case fileapi::kFileSystemTypeItunes: | |
132 return itunes_file_util_.get(); | |
133 case fileapi::kFileSystemTypePicasa: | |
134 return picasa_file_util_.get(); | |
135 #endif // defined(OS_WIN) || defined(OS_MACOSX) | |
136 default: | |
137 NOTREACHED(); | |
138 } | |
139 return NULL; | |
140 } | |
141 | |
142 fileapi::CopyOrMoveFileValidatorFactory* | |
143 MediaFileSystemMountPointProvider::GetCopyOrMoveFileValidatorFactory( | |
144 fileapi::FileSystemType type, base::PlatformFileError* error_code) { | |
145 DCHECK(error_code); | |
146 *error_code = base::PLATFORM_FILE_OK; | |
147 switch (type) { | |
148 case fileapi::kFileSystemTypeNativeMedia: | |
149 case fileapi::kFileSystemTypeDeviceMedia: | |
150 case fileapi::kFileSystemTypeItunes: | |
151 if (!media_copy_or_move_file_validator_factory_) { | |
152 *error_code = base::PLATFORM_FILE_ERROR_SECURITY; | |
153 return NULL; | |
154 } | |
155 return media_copy_or_move_file_validator_factory_.get(); | |
156 default: | |
157 NOTREACHED(); | |
158 } | |
159 return NULL; | |
160 } | |
161 | |
162 fileapi::FileSystemOperation* | |
163 MediaFileSystemMountPointProvider::CreateFileSystemOperation( | |
164 const FileSystemURL& url, | |
165 FileSystemContext* context, | |
166 base::PlatformFileError* error_code) const { | |
167 scoped_ptr<fileapi::FileSystemOperationContext> operation_context( | |
168 new fileapi::FileSystemOperationContext( | |
169 context, media_task_runner_.get())); | |
170 | |
171 operation_context->SetUserValue(kMediaPathFilterKey, | |
172 media_path_filter_.get()); | |
173 if (url.type() == fileapi::kFileSystemTypeDeviceMedia) { | |
174 operation_context->SetUserValue(kMTPDeviceDelegateURLKey, | |
175 url.filesystem_id()); | |
176 } | |
177 | |
178 return new fileapi::LocalFileSystemOperation(url, context, | |
179 operation_context.Pass()); | |
180 } | |
181 | |
182 scoped_ptr<webkit_blob::FileStreamReader> | |
183 MediaFileSystemMountPointProvider::CreateFileStreamReader( | |
184 const FileSystemURL& url, | |
185 int64 offset, | |
186 const base::Time& expected_modification_time, | |
187 FileSystemContext* context) const { | |
188 return scoped_ptr<webkit_blob::FileStreamReader>( | |
189 new webkit_blob::LocalFileStreamReader( | |
190 context->task_runners()->file_task_runner(), | |
191 url.path(), offset, expected_modification_time)); | |
192 } | |
193 | |
194 scoped_ptr<fileapi::FileStreamWriter> | |
195 MediaFileSystemMountPointProvider::CreateFileStreamWriter( | |
196 const FileSystemURL& url, | |
197 int64 offset, | |
198 FileSystemContext* context) const { | |
199 return scoped_ptr<fileapi::FileStreamWriter>( | |
200 new fileapi::LocalFileStreamWriter( | |
201 context->task_runners()->file_task_runner(), | |
202 url.path(), offset)); | |
203 } | |
204 | |
205 fileapi::FileSystemQuotaUtil* | |
206 MediaFileSystemMountPointProvider::GetQuotaUtil() { | |
207 // No quota support. | |
208 return NULL; | |
209 } | |
210 | |
211 } // namespace chrome | |
OLD | NEW |