18bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
28bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
38bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// found in the LICENSE file.
48bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
51320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "storage/browser/fileapi/plugin_private_file_system_backend.h"
68bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
78bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include <map>
88bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
98bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "base/stl_util.h"
108bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "base/synchronization/lock.h"
118bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "base/task_runner_util.h"
128bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "net/base/net_util.h"
131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "storage/browser/blob/file_stream_reader.h"
141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "storage/browser/fileapi/async_file_util_adapter.h"
151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "storage/browser/fileapi/file_stream_writer.h"
161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "storage/browser/fileapi/file_system_context.h"
171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "storage/browser/fileapi/file_system_operation.h"
181320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "storage/browser/fileapi/file_system_operation_context.h"
191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "storage/browser/fileapi/file_system_options.h"
201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "storage/browser/fileapi/isolated_context.h"
211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "storage/browser/fileapi/obfuscated_file_util.h"
221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "storage/browser/fileapi/quota/quota_reservation.h"
231320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "storage/common/fileapi/file_system_util.h"
248bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
2503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)namespace storage {
268bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
278bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)class PluginPrivateFileSystemBackend::FileSystemIDToPluginMap {
288bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) public:
29f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  explicit FileSystemIDToPluginMap(base::SequencedTaskRunner* task_runner)
308bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      : task_runner_(task_runner) {}
318bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  ~FileSystemIDToPluginMap() {}
328bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
338bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  std::string GetPluginIDForURL(const FileSystemURL& url) {
348bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    DCHECK(task_runner_->RunsTasksOnCurrentThread());
358bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    Map::iterator found = map_.find(url.filesystem_id());
368bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    if (url.type() != kFileSystemTypePluginPrivate || found == map_.end()) {
378bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      NOTREACHED() << "Unsupported url is given: " << url.DebugString();
388bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      return std::string();
398bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    }
408bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    return found->second;
418bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  }
428bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
438bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  void RegisterFileSystem(const std::string& filesystem_id,
448bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                          const std::string& plugin_id) {
458bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    DCHECK(task_runner_->RunsTasksOnCurrentThread());
46f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    DCHECK(!filesystem_id.empty());
47f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    DCHECK(!ContainsKey(map_, filesystem_id)) << filesystem_id;
488bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    map_[filesystem_id] = plugin_id;
498bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  }
508bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
518bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  void RemoveFileSystem(const std::string& filesystem_id) {
528bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    DCHECK(task_runner_->RunsTasksOnCurrentThread());
538bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    map_.erase(filesystem_id);
548bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  }
558bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
568bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) private:
578bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  typedef std::map<std::string, std::string> Map;
588bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  scoped_refptr<base::SequencedTaskRunner> task_runner_;
598bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  Map map_;
608bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)};
618bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
628bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)namespace {
638bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
648bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)const base::FilePath::CharType* kFileSystemDirectory =
658bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    SandboxFileSystemBackendDelegate::kFileSystemDirectory;
668bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)const base::FilePath::CharType* kPluginPrivateDirectory =
678bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    FILE_PATH_LITERAL("Plugins");
688bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)base::File::Error OpenFileSystemOnFileTaskRunner(
708bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    ObfuscatedFileUtil* file_util,
718bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    PluginPrivateFileSystemBackend::FileSystemIDToPluginMap* plugin_map,
728bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    const GURL& origin_url,
738bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    const std::string& filesystem_id,
748bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    const std::string& plugin_id,
758bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    OpenFileSystemMode mode) {
765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::File::Error error = base::File::FILE_ERROR_FAILED;
778bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  const bool create = (mode == OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT);
788bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  file_util->GetDirectoryForOriginAndType(
798bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      origin_url, plugin_id, create, &error);
805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (error == base::File::FILE_OK)
818bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    plugin_map->RegisterFileSystem(filesystem_id, plugin_id);
828bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  return error;
838bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)}
848bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
858bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)}  // namespace
868bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
878bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)PluginPrivateFileSystemBackend::PluginPrivateFileSystemBackend(
888bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    base::SequencedTaskRunner* file_task_runner,
898bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    const base::FilePath& profile_path,
9003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    storage::SpecialStoragePolicy* special_storage_policy,
918bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    const FileSystemOptions& file_system_options)
928bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    : file_task_runner_(file_task_runner),
938bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      file_system_options_(file_system_options),
9403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      base_path_(profile_path.Append(kFileSystemDirectory)
9503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)                     .Append(kPluginPrivateDirectory)),
968bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      plugin_map_(new FileSystemIDToPluginMap(file_task_runner)),
978bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      weak_factory_(this) {
988bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  file_util_.reset(
998bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      new AsyncFileUtilAdapter(new ObfuscatedFileUtil(
1008bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)          special_storage_policy,
1015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          base_path_, file_system_options.env_override(),
1028bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)          file_task_runner,
1038bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)          base::Bind(&FileSystemIDToPluginMap::GetPluginIDForURL,
1048bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                     base::Owned(plugin_map_)),
1051e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)          std::set<std::string>(),
1061e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)          NULL)));
1078bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)}
1088bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1098bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)PluginPrivateFileSystemBackend::~PluginPrivateFileSystemBackend() {
1108bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  if (!file_task_runner_->RunsTasksOnCurrentThread()) {
1118bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    AsyncFileUtil* file_util = file_util_.release();
1128bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    if (!file_task_runner_->DeleteSoon(FROM_HERE, file_util))
1138bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      delete file_util;
1148bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  }
1158bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)}
1168bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1178bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)void PluginPrivateFileSystemBackend::OpenPrivateFileSystem(
1188bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    const GURL& origin_url,
1198bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    FileSystemType type,
120f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    const std::string& filesystem_id,
1218bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    const std::string& plugin_id,
1228bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    OpenFileSystemMode mode,
123f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    const StatusCallback& callback) {
1248bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  if (!CanHandleType(type) || file_system_options_.is_incognito()) {
1258bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    base::MessageLoopProxy::current()->PostTask(
1265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        FROM_HERE, base::Bind(callback, base::File::FILE_ERROR_SECURITY));
1278bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    return;
1288bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  }
1298bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1308bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  PostTaskAndReplyWithResult(
1318bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      file_task_runner_.get(),
1328bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      FROM_HERE,
1335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&OpenFileSystemOnFileTaskRunner,
1348bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                 obfuscated_file_util(), plugin_map_,
1358bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                 origin_url, filesystem_id, plugin_id, mode),
136f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      callback);
1378bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)}
1388bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1398bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)bool PluginPrivateFileSystemBackend::CanHandleType(FileSystemType type) const {
1408bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  return type == kFileSystemTypePluginPrivate;
1418bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)}
1428bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1438bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)void PluginPrivateFileSystemBackend::Initialize(FileSystemContext* context) {
1448bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)}
1458bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
146a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void PluginPrivateFileSystemBackend::ResolveURL(
147a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    const FileSystemURL& url,
1488bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    OpenFileSystemMode mode,
1498bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    const OpenFileSystemCallback& callback) {
1508bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // We never allow opening a new plugin-private filesystem via usual
151a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // ResolveURL.
1528bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  base::MessageLoopProxy::current()->PostTask(
1538bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      FROM_HERE,
1548bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      base::Bind(callback, GURL(), std::string(),
1555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 base::File::FILE_ERROR_SECURITY));
1568bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)}
1578bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1588bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)AsyncFileUtil*
1598bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)PluginPrivateFileSystemBackend::GetAsyncFileUtil(FileSystemType type) {
1608bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  return file_util_.get();
1618bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)}
1628bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1631320f92c476a1ad9d19dba2a48c72b75566198e9Primiano TucciWatcherManager* PluginPrivateFileSystemBackend::GetWatcherManager(
1641320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    FileSystemType type) {
1651320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  return NULL;
1661320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}
1671320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
1688bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)CopyOrMoveFileValidatorFactory*
1698bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)PluginPrivateFileSystemBackend::GetCopyOrMoveFileValidatorFactory(
1708bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    FileSystemType type,
1715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    base::File::Error* error_code) {
1728bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  DCHECK(error_code);
1735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  *error_code = base::File::FILE_OK;
1748bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  return NULL;
1758bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)}
1768bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1778bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)FileSystemOperation* PluginPrivateFileSystemBackend::CreateFileSystemOperation(
1788bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    const FileSystemURL& url,
1798bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    FileSystemContext* context,
1805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    base::File::Error* error_code) const {
1818bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  scoped_ptr<FileSystemOperationContext> operation_context(
1828bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      new FileSystemOperationContext(context));
1838bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  return FileSystemOperation::Create(url, context, operation_context.Pass());
1848bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)}
1858bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
186a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)bool PluginPrivateFileSystemBackend::SupportsStreaming(
18703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    const storage::FileSystemURL& url) const {
188a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  return false;
189a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
190a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
19103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)bool PluginPrivateFileSystemBackend::HasInplaceCopyImplementation(
19203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    storage::FileSystemType type) const {
19303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  return false;
19403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)}
19503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
19603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)scoped_ptr<storage::FileStreamReader>
1978bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)PluginPrivateFileSystemBackend::CreateFileStreamReader(
1988bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    const FileSystemURL& url,
1998bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    int64 offset,
2001320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    int64 max_bytes_to_read,
2018bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    const base::Time& expected_modification_time,
2028bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    FileSystemContext* context) const {
20303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  return scoped_ptr<storage::FileStreamReader>();
2048bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)}
2058bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
2068bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)scoped_ptr<FileStreamWriter>
2078bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)PluginPrivateFileSystemBackend::CreateFileStreamWriter(
2088bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    const FileSystemURL& url,
2098bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    int64 offset,
2108bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    FileSystemContext* context) const {
2118bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  return scoped_ptr<FileStreamWriter>();
2128bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)}
2138bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
2148bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)FileSystemQuotaUtil* PluginPrivateFileSystemBackend::GetQuotaUtil() {
2158bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  return this;
2168bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)}
2178bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
2185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)base::File::Error
2195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)PluginPrivateFileSystemBackend::DeleteOriginDataOnFileTaskRunner(
2208bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    FileSystemContext* context,
22103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    storage::QuotaManagerProxy* proxy,
2228bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    const GURL& origin_url,
2238bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    FileSystemType type) {
2248bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  if (!CanHandleType(type))
2255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return base::File::FILE_ERROR_SECURITY;
2268bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  bool result = obfuscated_file_util()->DeleteDirectoryForOriginAndType(
2278bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      origin_url, std::string());
2288bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  if (result)
2295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return base::File::FILE_OK;
2305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return base::File::FILE_ERROR_FAILED;
2318bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)}
2328bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
2335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void PluginPrivateFileSystemBackend::GetOriginsForTypeOnFileTaskRunner(
2348bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    FileSystemType type,
2358bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    std::set<GURL>* origins) {
2368bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  if (!CanHandleType(type))
2378bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    return;
2388bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  scoped_ptr<ObfuscatedFileUtil::AbstractOriginEnumerator> enumerator(
2398bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      obfuscated_file_util()->CreateOriginEnumerator());
2408bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  GURL origin;
2418bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  while (!(origin = enumerator->Next()).is_empty())
2428bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    origins->insert(origin);
2438bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)}
2448bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
2455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void PluginPrivateFileSystemBackend::GetOriginsForHostOnFileTaskRunner(
2468bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    FileSystemType type,
2478bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    const std::string& host,
2488bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    std::set<GURL>* origins) {
2498bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  if (!CanHandleType(type))
2508bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    return;
2518bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  scoped_ptr<ObfuscatedFileUtil::AbstractOriginEnumerator> enumerator(
2528bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      obfuscated_file_util()->CreateOriginEnumerator());
2538bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  GURL origin;
2548bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  while (!(origin = enumerator->Next()).is_empty()) {
2558bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    if (host == net::GetHostOrSpecFromURL(origin))
2568bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      origins->insert(origin);
2578bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  }
2588bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)}
2598bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
2605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)int64 PluginPrivateFileSystemBackend::GetOriginUsageOnFileTaskRunner(
2618bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    FileSystemContext* context,
2628bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    const GURL& origin_url,
2638bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    FileSystemType type) {
2648bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // We don't track usage on this filesystem.
2658bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  return 0;
2668bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)}
2678bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
268f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)scoped_refptr<QuotaReservation>
269f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)PluginPrivateFileSystemBackend::CreateQuotaReservationOnFileTaskRunner(
270f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    const GURL& origin_url,
271f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    FileSystemType type) {
272f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // We don't track usage on this filesystem.
273f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  NOTREACHED();
274f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  return scoped_refptr<QuotaReservation>();
275f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
276f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
2778bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)const UpdateObserverList* PluginPrivateFileSystemBackend::GetUpdateObservers(
2788bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    FileSystemType type) const {
2798bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  return NULL;
2808bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)}
2818bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
2828bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)const ChangeObserverList* PluginPrivateFileSystemBackend::GetChangeObservers(
2838bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    FileSystemType type) const {
2848bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  return NULL;
2858bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)}
2868bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
2878bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)const AccessObserverList* PluginPrivateFileSystemBackend::GetAccessObservers(
2888bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    FileSystemType type) const {
2898bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  return NULL;
2908bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)}
2918bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
2928bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)ObfuscatedFileUtil* PluginPrivateFileSystemBackend::obfuscated_file_util() {
2938bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  return static_cast<ObfuscatedFileUtil*>(
2948bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      static_cast<AsyncFileUtilAdapter*>(file_util_.get())->sync_file_util());
2958bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)}
2968bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
29703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)}  // namespace storage
298