| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" | 5 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 | 42 |
| 43 #if defined(OS_WIN) || defined(OS_MACOSX) | 43 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 44 #include "chrome/browser/media_galleries/fileapi/itunes_file_util.h" | 44 #include "chrome/browser/media_galleries/fileapi/itunes_file_util.h" |
| 45 #include "chrome/browser/media_galleries/fileapi/picasa_file_util.h" | 45 #include "chrome/browser/media_galleries/fileapi/picasa_file_util.h" |
| 46 #endif // defined(OS_WIN) || defined(OS_MACOSX) | 46 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
| 47 | 47 |
| 48 #if defined(OS_MACOSX) | 48 #if defined(OS_MACOSX) |
| 49 #include "chrome/browser/media_galleries/fileapi/iphoto_file_util.h" | 49 #include "chrome/browser/media_galleries/fileapi/iphoto_file_util.h" |
| 50 #endif // defined(OS_MACOSX) | 50 #endif // defined(OS_MACOSX) |
| 51 | 51 |
| 52 using fileapi::FileSystemContext; | 52 using storage::FileSystemContext; |
| 53 using fileapi::FileSystemURL; | 53 using storage::FileSystemURL; |
| 54 | 54 |
| 55 namespace { | 55 namespace { |
| 56 | 56 |
| 57 const char kMediaGalleryMountPrefix[] = "media_galleries-"; | 57 const char kMediaGalleryMountPrefix[] = "media_galleries-"; |
| 58 | 58 |
| 59 void OnPreferencesInit( | 59 void OnPreferencesInit( |
| 60 const content::RenderViewHost* rvh, | 60 const content::RenderViewHost* rvh, |
| 61 const extensions::Extension* extension, | 61 const extensions::Extension* extension, |
| 62 MediaGalleryPrefId pref_id, | 62 MediaGalleryPrefId pref_id, |
| 63 const base::Callback<void(base::File::Error result)>& callback) { | 63 const base::Callback<void(base::File::Error result)>& callback) { |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 name.append("-"); | 172 name.append("-"); |
| 173 if (pref_id != kInvalidMediaGalleryPrefId) | 173 if (pref_id != kInvalidMediaGalleryPrefId) |
| 174 name.append(base::Uint64ToString(pref_id)); | 174 name.append(base::Uint64ToString(pref_id)); |
| 175 base::ReplaceChars(name, " /", "_", &name); | 175 base::ReplaceChars(name, " /", "_", &name); |
| 176 return name; | 176 return name; |
| 177 } | 177 } |
| 178 | 178 |
| 179 // static | 179 // static |
| 180 bool MediaFileSystemBackend::AttemptAutoMountForURLRequest( | 180 bool MediaFileSystemBackend::AttemptAutoMountForURLRequest( |
| 181 const net::URLRequest* url_request, | 181 const net::URLRequest* url_request, |
| 182 const fileapi::FileSystemURL& filesystem_url, | 182 const storage::FileSystemURL& filesystem_url, |
| 183 const std::string& storage_domain, | 183 const std::string& storage_domain, |
| 184 const base::Callback<void(base::File::Error result)>& callback) { | 184 const base::Callback<void(base::File::Error result)>& callback) { |
| 185 if (storage_domain.empty() || | 185 if (storage_domain.empty() || |
| 186 filesystem_url.type() != fileapi::kFileSystemTypeExternal || | 186 filesystem_url.type() != storage::kFileSystemTypeExternal || |
| 187 storage_domain != filesystem_url.origin().host()) { | 187 storage_domain != filesystem_url.origin().host()) { |
| 188 return false; | 188 return false; |
| 189 } | 189 } |
| 190 | 190 |
| 191 const base::FilePath& virtual_path = filesystem_url.path(); | 191 const base::FilePath& virtual_path = filesystem_url.path(); |
| 192 if (virtual_path.ReferencesParent()) | 192 if (virtual_path.ReferencesParent()) |
| 193 return false; | 193 return false; |
| 194 std::vector<base::FilePath::StringType> components; | 194 std::vector<base::FilePath::StringType> components; |
| 195 virtual_path.GetComponents(&components); | 195 virtual_path.GetComponents(&components); |
| 196 if (components.empty()) | 196 if (components.empty()) |
| 197 return false; | 197 return false; |
| 198 std::string mount_point = base::FilePath(components[0]).AsUTF8Unsafe(); | 198 std::string mount_point = base::FilePath(components[0]).AsUTF8Unsafe(); |
| 199 if (!StartsWithASCII(mount_point, kMediaGalleryMountPrefix, true)) | 199 if (!StartsWithASCII(mount_point, kMediaGalleryMountPrefix, true)) |
| 200 return false; | 200 return false; |
| 201 | 201 |
| 202 const content::ResourceRequestInfo* request_info = | 202 const content::ResourceRequestInfo* request_info = |
| 203 content::ResourceRequestInfo::ForRequest(url_request); | 203 content::ResourceRequestInfo::ForRequest(url_request); |
| 204 if (!request_info) | 204 if (!request_info) |
| 205 return false; | 205 return false; |
| 206 | 206 |
| 207 content::BrowserThread::PostTask( | 207 content::BrowserThread::PostTask( |
| 208 content::BrowserThread::UI, | 208 content::BrowserThread::UI, |
| 209 FROM_HERE, | 209 FROM_HERE, |
| 210 base::Bind(&AttemptAutoMountOnUIThread, request_info->GetChildID(), | 210 base::Bind(&AttemptAutoMountOnUIThread, request_info->GetChildID(), |
| 211 request_info->GetRouteID(), storage_domain, mount_point, | 211 request_info->GetRouteID(), storage_domain, mount_point, |
| 212 callback)); | 212 callback)); |
| 213 return true; | 213 return true; |
| 214 } | 214 } |
| 215 | 215 |
| 216 bool MediaFileSystemBackend::CanHandleType( | 216 bool MediaFileSystemBackend::CanHandleType(storage::FileSystemType type) const { |
| 217 fileapi::FileSystemType type) const { | |
| 218 switch (type) { | 217 switch (type) { |
| 219 case fileapi::kFileSystemTypeNativeMedia: | 218 case storage::kFileSystemTypeNativeMedia: |
| 220 case fileapi::kFileSystemTypeDeviceMedia: | 219 case storage::kFileSystemTypeDeviceMedia: |
| 221 #if defined(OS_WIN) || defined(OS_MACOSX) | 220 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 222 case fileapi::kFileSystemTypePicasa: | 221 case storage::kFileSystemTypePicasa: |
| 223 case fileapi::kFileSystemTypeItunes: | 222 case storage::kFileSystemTypeItunes: |
| 224 #endif // defined(OS_WIN) || defined(OS_MACOSX) | 223 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
| 225 #if defined(OS_MACOSX) | 224 #if defined(OS_MACOSX) |
| 226 case fileapi::kFileSystemTypeIphoto: | 225 case storage::kFileSystemTypeIphoto: |
| 227 #endif // defined(OS_MACOSX) | 226 #endif // defined(OS_MACOSX) |
| 228 return true; | 227 return true; |
| 229 default: | 228 default: |
| 230 return false; | 229 return false; |
| 231 } | 230 } |
| 232 } | 231 } |
| 233 | 232 |
| 234 void MediaFileSystemBackend::Initialize(fileapi::FileSystemContext* context) { | 233 void MediaFileSystemBackend::Initialize(storage::FileSystemContext* context) { |
| 235 } | 234 } |
| 236 | 235 |
| 237 void MediaFileSystemBackend::ResolveURL( | 236 void MediaFileSystemBackend::ResolveURL( |
| 238 const FileSystemURL& url, | 237 const FileSystemURL& url, |
| 239 fileapi::OpenFileSystemMode mode, | 238 storage::OpenFileSystemMode mode, |
| 240 const OpenFileSystemCallback& callback) { | 239 const OpenFileSystemCallback& callback) { |
| 241 // We never allow opening a new FileSystem via usual ResolveURL. | 240 // We never allow opening a new FileSystem via usual ResolveURL. |
| 242 base::MessageLoopProxy::current()->PostTask( | 241 base::MessageLoopProxy::current()->PostTask( |
| 243 FROM_HERE, | 242 FROM_HERE, |
| 244 base::Bind(callback, | 243 base::Bind(callback, |
| 245 GURL(), | 244 GURL(), |
| 246 std::string(), | 245 std::string(), |
| 247 base::File::FILE_ERROR_SECURITY)); | 246 base::File::FILE_ERROR_SECURITY)); |
| 248 } | 247 } |
| 249 | 248 |
| 250 fileapi::AsyncFileUtil* MediaFileSystemBackend::GetAsyncFileUtil( | 249 storage::AsyncFileUtil* MediaFileSystemBackend::GetAsyncFileUtil( |
| 251 fileapi::FileSystemType type) { | 250 storage::FileSystemType type) { |
| 252 switch (type) { | 251 switch (type) { |
| 253 case fileapi::kFileSystemTypeNativeMedia: | 252 case storage::kFileSystemTypeNativeMedia: |
| 254 return native_media_file_util_.get(); | 253 return native_media_file_util_.get(); |
| 255 case fileapi::kFileSystemTypeDeviceMedia: | 254 case storage::kFileSystemTypeDeviceMedia: |
| 256 return device_media_async_file_util_.get(); | 255 return device_media_async_file_util_.get(); |
| 257 #if defined(OS_WIN) || defined(OS_MACOSX) | 256 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 258 case fileapi::kFileSystemTypeItunes: | 257 case storage::kFileSystemTypeItunes: |
| 259 return itunes_file_util_.get(); | 258 return itunes_file_util_.get(); |
| 260 case fileapi::kFileSystemTypePicasa: | 259 case storage::kFileSystemTypePicasa: |
| 261 return picasa_file_util_.get(); | 260 return picasa_file_util_.get(); |
| 262 #endif // defined(OS_WIN) || defined(OS_MACOSX) | 261 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
| 263 #if defined(OS_MACOSX) | 262 #if defined(OS_MACOSX) |
| 264 case fileapi::kFileSystemTypeIphoto: | 263 case storage::kFileSystemTypeIphoto: |
| 265 return iphoto_file_util_.get(); | 264 return iphoto_file_util_.get(); |
| 266 #endif // defined(OS_MACOSX) | 265 #endif // defined(OS_MACOSX) |
| 267 default: | 266 default: |
| 268 NOTREACHED(); | 267 NOTREACHED(); |
| 269 } | 268 } |
| 270 return NULL; | 269 return NULL; |
| 271 } | 270 } |
| 272 | 271 |
| 273 fileapi::CopyOrMoveFileValidatorFactory* | 272 storage::CopyOrMoveFileValidatorFactory* |
| 274 MediaFileSystemBackend::GetCopyOrMoveFileValidatorFactory( | 273 MediaFileSystemBackend::GetCopyOrMoveFileValidatorFactory( |
| 275 fileapi::FileSystemType type, base::File::Error* error_code) { | 274 storage::FileSystemType type, |
| 275 base::File::Error* error_code) { |
| 276 DCHECK(error_code); | 276 DCHECK(error_code); |
| 277 *error_code = base::File::FILE_OK; | 277 *error_code = base::File::FILE_OK; |
| 278 switch (type) { | 278 switch (type) { |
| 279 case fileapi::kFileSystemTypeNativeMedia: | 279 case storage::kFileSystemTypeNativeMedia: |
| 280 case fileapi::kFileSystemTypeDeviceMedia: | 280 case storage::kFileSystemTypeDeviceMedia: |
| 281 case fileapi::kFileSystemTypeIphoto: | 281 case storage::kFileSystemTypeIphoto: |
| 282 case fileapi::kFileSystemTypeItunes: | 282 case storage::kFileSystemTypeItunes: |
| 283 if (!media_copy_or_move_file_validator_factory_) { | 283 if (!media_copy_or_move_file_validator_factory_) { |
| 284 *error_code = base::File::FILE_ERROR_SECURITY; | 284 *error_code = base::File::FILE_ERROR_SECURITY; |
| 285 return NULL; | 285 return NULL; |
| 286 } | 286 } |
| 287 return media_copy_or_move_file_validator_factory_.get(); | 287 return media_copy_or_move_file_validator_factory_.get(); |
| 288 default: | 288 default: |
| 289 NOTREACHED(); | 289 NOTREACHED(); |
| 290 } | 290 } |
| 291 return NULL; | 291 return NULL; |
| 292 } | 292 } |
| 293 | 293 |
| 294 fileapi::FileSystemOperation* | 294 storage::FileSystemOperation* MediaFileSystemBackend::CreateFileSystemOperation( |
| 295 MediaFileSystemBackend::CreateFileSystemOperation( | |
| 296 const FileSystemURL& url, | 295 const FileSystemURL& url, |
| 297 FileSystemContext* context, | 296 FileSystemContext* context, |
| 298 base::File::Error* error_code) const { | 297 base::File::Error* error_code) const { |
| 299 scoped_ptr<fileapi::FileSystemOperationContext> operation_context( | 298 scoped_ptr<storage::FileSystemOperationContext> operation_context( |
| 300 new fileapi::FileSystemOperationContext( | 299 new storage::FileSystemOperationContext(context, |
| 301 context, media_task_runner_.get())); | 300 media_task_runner_.get())); |
| 302 return fileapi::FileSystemOperation::Create( | 301 return storage::FileSystemOperation::Create( |
| 303 url, context, operation_context.Pass()); | 302 url, context, operation_context.Pass()); |
| 304 } | 303 } |
| 305 | 304 |
| 306 bool MediaFileSystemBackend::SupportsStreaming( | 305 bool MediaFileSystemBackend::SupportsStreaming( |
| 307 const fileapi::FileSystemURL& url) const { | 306 const storage::FileSystemURL& url) const { |
| 308 if (url.type() == fileapi::kFileSystemTypeDeviceMedia) { | 307 if (url.type() == storage::kFileSystemTypeDeviceMedia) { |
| 309 DCHECK(device_media_async_file_util_); | 308 DCHECK(device_media_async_file_util_); |
| 310 return device_media_async_file_util_->SupportsStreaming(url); | 309 return device_media_async_file_util_->SupportsStreaming(url); |
| 311 } | 310 } |
| 312 | 311 |
| 313 return false; | 312 return false; |
| 314 } | 313 } |
| 315 | 314 |
| 316 bool MediaFileSystemBackend::HasInplaceCopyImplementation( | 315 bool MediaFileSystemBackend::HasInplaceCopyImplementation( |
| 317 fileapi::FileSystemType type) const { | 316 storage::FileSystemType type) const { |
| 318 DCHECK(type == fileapi::kFileSystemTypeNativeMedia || | 317 DCHECK(type == storage::kFileSystemTypeNativeMedia || |
| 319 type == fileapi::kFileSystemTypeDeviceMedia || | 318 type == storage::kFileSystemTypeDeviceMedia || |
| 320 type == fileapi::kFileSystemTypeItunes || | 319 type == storage::kFileSystemTypeItunes || |
| 321 type == fileapi::kFileSystemTypePicasa || | 320 type == storage::kFileSystemTypePicasa || |
| 322 type == fileapi::kFileSystemTypeIphoto); | 321 type == storage::kFileSystemTypeIphoto); |
| 323 return true; | 322 return true; |
| 324 } | 323 } |
| 325 | 324 |
| 326 scoped_ptr<webkit_blob::FileStreamReader> | 325 scoped_ptr<storage::FileStreamReader> |
| 327 MediaFileSystemBackend::CreateFileStreamReader( | 326 MediaFileSystemBackend::CreateFileStreamReader( |
| 328 const FileSystemURL& url, | 327 const FileSystemURL& url, |
| 329 int64 offset, | 328 int64 offset, |
| 330 const base::Time& expected_modification_time, | 329 const base::Time& expected_modification_time, |
| 331 FileSystemContext* context) const { | 330 FileSystemContext* context) const { |
| 332 if (url.type() == fileapi::kFileSystemTypeDeviceMedia) { | 331 if (url.type() == storage::kFileSystemTypeDeviceMedia) { |
| 333 DCHECK(device_media_async_file_util_); | 332 DCHECK(device_media_async_file_util_); |
| 334 scoped_ptr<webkit_blob::FileStreamReader> reader = | 333 scoped_ptr<storage::FileStreamReader> reader = |
| 335 device_media_async_file_util_->GetFileStreamReader( | 334 device_media_async_file_util_->GetFileStreamReader( |
| 336 url, offset, expected_modification_time, context); | 335 url, offset, expected_modification_time, context); |
| 337 DCHECK(reader); | 336 DCHECK(reader); |
| 338 return reader.Pass(); | 337 return reader.Pass(); |
| 339 } | 338 } |
| 340 | 339 |
| 341 return scoped_ptr<webkit_blob::FileStreamReader>( | 340 return scoped_ptr<storage::FileStreamReader>( |
| 342 webkit_blob::FileStreamReader::CreateForLocalFile( | 341 storage::FileStreamReader::CreateForLocalFile( |
| 343 context->default_file_task_runner(), | 342 context->default_file_task_runner(), |
| 344 url.path(), offset, expected_modification_time)); | 343 url.path(), |
| 344 offset, |
| 345 expected_modification_time)); |
| 345 } | 346 } |
| 346 | 347 |
| 347 scoped_ptr<fileapi::FileStreamWriter> | 348 scoped_ptr<storage::FileStreamWriter> |
| 348 MediaFileSystemBackend::CreateFileStreamWriter( | 349 MediaFileSystemBackend::CreateFileStreamWriter( |
| 349 const FileSystemURL& url, | 350 const FileSystemURL& url, |
| 350 int64 offset, | 351 int64 offset, |
| 351 FileSystemContext* context) const { | 352 FileSystemContext* context) const { |
| 352 return scoped_ptr<fileapi::FileStreamWriter>( | 353 return scoped_ptr<storage::FileStreamWriter>( |
| 353 fileapi::FileStreamWriter::CreateForLocalFile( | 354 storage::FileStreamWriter::CreateForLocalFile( |
| 354 context->default_file_task_runner(), | 355 context->default_file_task_runner(), |
| 355 url.path(), | 356 url.path(), |
| 356 offset, | 357 offset, |
| 357 fileapi::FileStreamWriter::OPEN_EXISTING_FILE)); | 358 storage::FileStreamWriter::OPEN_EXISTING_FILE)); |
| 358 } | 359 } |
| 359 | 360 |
| 360 fileapi::FileSystemQuotaUtil* | 361 storage::FileSystemQuotaUtil* MediaFileSystemBackend::GetQuotaUtil() { |
| 361 MediaFileSystemBackend::GetQuotaUtil() { | |
| 362 // No quota support. | 362 // No quota support. |
| 363 return NULL; | 363 return NULL; |
| 364 } | 364 } |
| OLD | NEW |