1c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved. 2c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// found in the LICENSE file. 4c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 57dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_MEDIA_FILE_SYSTEM_BACKEND_H_ 67dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_MEDIA_FILE_SYSTEM_BACKEND_H_ 7c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 8effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include <string> 9effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 10effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "base/callback.h" 11effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "base/files/file_path.h" 12868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/memory/ref_counted.h" 13c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "base/memory/scoped_ptr.h" 14effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "chrome/browser/media_galleries/media_galleries_preferences.h" 151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "storage/browser/fileapi/file_system_backend.h" 161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "storage/browser/fileapi/task_runner_bound_observer_list.h" 17c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 18868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)namespace base { 19868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class SequencedTaskRunner; 20868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 21868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 2203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)namespace storage { 23effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochclass FileSystemURL; 24effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch} 25effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 2623730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)namespace net { 2723730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)class URLRequest; 2823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)} 2923730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) 30c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class MediaPathFilter; 31c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class DeviceMediaAsyncFileUtil; 32c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 3303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)class MediaFileSystemBackend : public storage::FileSystemBackend { 34c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) public: 35868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) static const char kMediaTaskRunnerName[]; 36c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 377dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch MediaFileSystemBackend( 38868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const base::FilePath& profile_path, 39868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) base::SequencedTaskRunner* media_task_runner); 407dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch virtual ~MediaFileSystemBackend(); 41c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) static bool CurrentlyOnMediaTaskRunnerThread(); 43eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch static scoped_refptr<base::SequencedTaskRunner> MediaTaskRunner(); 447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 45effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // Construct the mount point for the gallery specified by |pref_id| in 46effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // the profile located in |profile_path|. 47effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch static std::string ConstructMountName(const base::FilePath& profile_path, 48effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch const std::string& extension_id, 49effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch MediaGalleryPrefId pref_id); 50effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 5123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) static bool AttemptAutoMountForURLRequest( 5223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) const net::URLRequest* url_request, 5303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) const storage::FileSystemURL& filesystem_url, 5423730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) const std::string& storage_domain, 5523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) const base::Callback<void(base::File::Error result)>& callback); 5623730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) 577dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // FileSystemBackend implementation. 5803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) virtual bool CanHandleType(storage::FileSystemType type) const OVERRIDE; 5903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) virtual void Initialize(storage::FileSystemContext* context) OVERRIDE; 6003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) virtual void ResolveURL(const storage::FileSystemURL& url, 6103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) storage::OpenFileSystemMode mode, 62a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const OpenFileSystemCallback& callback) OVERRIDE; 6303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) virtual storage::AsyncFileUtil* GetAsyncFileUtil( 6403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) storage::FileSystemType type) OVERRIDE; 651320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual storage::WatcherManager* GetWatcherManager( 661320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci storage::FileSystemType type) OVERRIDE; 6703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) virtual storage::CopyOrMoveFileValidatorFactory* 6803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) GetCopyOrMoveFileValidatorFactory(storage::FileSystemType type, 6903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) base::File::Error* error_code) OVERRIDE; 7003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) virtual storage::FileSystemOperation* CreateFileSystemOperation( 7103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) const storage::FileSystemURL& url, 7203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) storage::FileSystemContext* context, 735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::File::Error* error_code) const OVERRIDE; 74a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual bool SupportsStreaming( 7503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) const storage::FileSystemURL& url) const OVERRIDE; 7603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) virtual bool HasInplaceCopyImplementation( 7703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) storage::FileSystemType type) const OVERRIDE; 7803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) virtual scoped_ptr<storage::FileStreamReader> CreateFileStreamReader( 7903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) const storage::FileSystemURL& url, 80c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) int64 offset, 811320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci int64 max_bytes_to_read, 82c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const base::Time& expected_modification_time, 8303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) storage::FileSystemContext* context) const OVERRIDE; 8403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) virtual scoped_ptr<storage::FileStreamWriter> CreateFileStreamWriter( 8503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) const storage::FileSystemURL& url, 86c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) int64 offset, 8703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) storage::FileSystemContext* context) const OVERRIDE; 8803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) virtual storage::FileSystemQuotaUtil* GetQuotaUtil() OVERRIDE; 891320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual const storage::UpdateObserverList* GetUpdateObservers( 901320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci storage::FileSystemType type) const OVERRIDE; 911320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual const storage::ChangeObserverList* GetChangeObservers( 921320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci storage::FileSystemType type) const OVERRIDE; 931320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual const storage::AccessObserverList* GetAccessObservers( 941320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci storage::FileSystemType type) const OVERRIDE; 95c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 96c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) private: 97c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Store the profile path. We need this to create temporary snapshot files. 98c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const base::FilePath profile_path_; 99c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 100868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) scoped_refptr<base::SequencedTaskRunner> media_task_runner_; 101868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 102c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) scoped_ptr<MediaPathFilter> media_path_filter_; 10303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) scoped_ptr<storage::CopyOrMoveFileValidatorFactory> 104c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) media_copy_or_move_file_validator_factory_; 105c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 10603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) scoped_ptr<storage::AsyncFileUtil> native_media_file_util_; 107c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) scoped_ptr<DeviceMediaAsyncFileUtil> device_media_async_file_util_; 108eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#if defined(OS_WIN) || defined(OS_MACOSX) 10903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) scoped_ptr<storage::AsyncFileUtil> picasa_file_util_; 11003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) scoped_ptr<storage::AsyncFileUtil> itunes_file_util_; 111eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#endif // defined(OS_WIN) || defined(OS_MACOSX) 1124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#if defined(OS_MACOSX) 11303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) scoped_ptr<storage::AsyncFileUtil> iphoto_file_util_; 1144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#endif // defined(OS_MACOSX) 115c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1167dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch DISALLOW_COPY_AND_ASSIGN(MediaFileSystemBackend); 117c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}; 118c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1197dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_MEDIA_FILE_SYSTEM_BACKEND_H_ 120