17dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// Copyright 2013 The Chromium Authors. All rights reserved.
27dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// Use of this source code is governed by a BSD-style license that can be
37dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// found in the LICENSE file.
47dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
51320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#ifndef STORAGE_BROWSER_FILEAPI_SANDBOX_FILE_SYSTEM_BACKEND_DELEGATE_H_
61320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#define STORAGE_BROWSER_FILEAPI_SANDBOX_FILE_SYSTEM_BACKEND_DELEGATE_H_
77dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
83551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include <map>
9a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include <set>
10a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include <string>
11a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include <utility>
12a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
137dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "base/files/file_path.h"
148bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "base/gtest_prod_util.h"
157dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "base/memory/ref_counted.h"
167dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "base/memory/scoped_ptr.h"
17a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "base/memory/weak_ptr.h"
183551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "base/threading/thread_checker.h"
19a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "base/time/time.h"
201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "storage/browser/fileapi/file_system_backend.h"
211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "storage/browser/fileapi/file_system_options.h"
221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "storage/browser/fileapi/file_system_quota_util.h"
231320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "storage/browser/fileapi/task_runner_bound_observer_list.h"
241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "storage/browser/storage_browser_export.h"
257dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
267dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochnamespace base {
277dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochclass SequencedTaskRunner;
287dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch}
297dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace content {
315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class SandboxFileSystemBackendDelegateTest;
325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class SandboxFileSystemTestHelper;
335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)namespace storage {
367dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochclass QuotaManagerProxy;
377dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochclass SpecialStoragePolicy;
387dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch}
397dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
4003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)namespace storage {
413551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)class FileStreamReader;
423551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)}
433551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
4403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)namespace storage {
457dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
463551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)class AsyncFileUtil;
473551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)class FileStreamWriter;
483551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)class FileSystemFileUtil;
493551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)class FileSystemOperationContext;
50a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)class FileSystemURL;
517dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochclass FileSystemUsageCache;
527dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochclass ObfuscatedFileUtil;
53f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class QuotaReservationManager;
547dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochclass SandboxFileSystemBackend;
557dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochclass SandboxQuotaObserver;
567dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
573551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Delegate implementation of the some methods in Sandbox/SyncFileSystemBackend.
587dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// An instance of this class is created and owned by FileSystemContext.
591320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass STORAGE_EXPORT SandboxFileSystemBackendDelegate
603551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    : public FileSystemQuotaUtil {
617dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch public:
62a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  typedef FileSystemBackend::OpenFileSystemCallback OpenFileSystemCallback;
63a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
647dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // The FileSystem directory name.
657dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  static const base::FilePath::CharType kFileSystemDirectory[];
667dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
67a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // Origin enumerator interface.
68a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // An instance of this interface is assumed to be called on the file thread.
69a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  class OriginEnumerator {
70a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)   public:
71a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    virtual ~OriginEnumerator() {}
72a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
73a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    // Returns the next origin.  Returns empty if there are no more origins.
74a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    virtual GURL Next() = 0;
75a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
76a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    // Returns the current origin's information.
77a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    virtual bool HasFileSystemType(FileSystemType type) const = 0;
78a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  };
79a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
808bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // Returns the type directory name in sandbox directory for given |type|.
818bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  static std::string GetTypeString(FileSystemType type);
828bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
833551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  SandboxFileSystemBackendDelegate(
8403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      storage::QuotaManagerProxy* quota_manager_proxy,
857dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      base::SequencedTaskRunner* file_task_runner,
867dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      const base::FilePath& profile_path,
8703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      storage::SpecialStoragePolicy* special_storage_policy,
88a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      const FileSystemOptions& file_system_options);
897dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
903551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  virtual ~SandboxFileSystemBackendDelegate();
917dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
92a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // Returns an origin enumerator of sandbox filesystem.
93a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // This method can only be called on the file thread.
94a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  OriginEnumerator* CreateOriginEnumerator();
95a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
96a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // Gets a base directory path of the sandboxed filesystem that is
97a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // specified by |origin_url| and |type|.
98a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // (The path is similar to the origin's root path but doesn't contain
99a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // the 'unique' part.)
100a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // Returns an empty path if the given type is invalid.
101a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // This method can only be called on the file thread.
102a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  base::FilePath GetBaseDirectoryForOriginAndType(
103a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      const GURL& origin_url,
104a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      FileSystemType type,
105a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      bool create);
106a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
107a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // FileSystemBackend helpers.
108a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  void OpenFileSystem(
109a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      const GURL& origin_url,
110a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      FileSystemType type,
111a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      OpenFileSystemMode mode,
112a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      const OpenFileSystemCallback& callback,
113a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      const GURL& root_url);
1143551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  scoped_ptr<FileSystemOperationContext> CreateFileSystemOperationContext(
1153551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      const FileSystemURL& url,
1163551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      FileSystemContext* context,
1175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::File::Error* error_code) const;
11803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  scoped_ptr<storage::FileStreamReader> CreateFileStreamReader(
1193551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      const FileSystemURL& url,
1203551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      int64 offset,
1213551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      const base::Time& expected_modification_time,
1223551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      FileSystemContext* context) const;
1233551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  scoped_ptr<FileStreamWriter> CreateFileStreamWriter(
1243551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      const FileSystemURL& url,
1253551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      int64 offset,
1263551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      FileSystemContext* context,
1273551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      FileSystemType type) const;
128a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
1293551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // FileSystemQuotaUtil overrides.
1305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual base::File::Error DeleteOriginDataOnFileTaskRunner(
131a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      FileSystemContext* context,
13203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      storage::QuotaManagerProxy* proxy,
133a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      const GURL& origin_url,
1343551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      FileSystemType type) OVERRIDE;
1355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void GetOriginsForTypeOnFileTaskRunner(
136a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      FileSystemType type,
1373551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      std::set<GURL>* origins) OVERRIDE;
1385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void GetOriginsForHostOnFileTaskRunner(
139a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      FileSystemType type,
140a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      const std::string& host,
1413551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      std::set<GURL>* origins) OVERRIDE;
1425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual int64 GetOriginUsageOnFileTaskRunner(
143a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      FileSystemContext* context,
144a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      const GURL& origin_url,
1453551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      FileSystemType type) OVERRIDE;
146f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual scoped_refptr<QuotaReservation>
147f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      CreateQuotaReservationOnFileTaskRunner(
148f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)          const GURL& origin_url,
149f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)          FileSystemType type) OVERRIDE;
1501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
1511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Adds an observer for the secified |type| of a file system, bound to
1521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // |task_runner|.
1531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void AddFileUpdateObserver(FileSystemType type,
1541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                     FileUpdateObserver* observer,
1551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                     base::SequencedTaskRunner* task_runner);
1561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void AddFileChangeObserver(FileSystemType type,
1571320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                     FileChangeObserver* observer,
1581320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                     base::SequencedTaskRunner* task_runner);
1591320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void AddFileAccessObserver(FileSystemType type,
1601320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                     FileAccessObserver* observer,
1611320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                     base::SequencedTaskRunner* task_runner);
1621320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
1631320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Returns observer lists for the specified |type| of a file system.
1643551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  virtual const UpdateObserverList* GetUpdateObservers(
1651320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      FileSystemType type) const;
1663551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  virtual const ChangeObserverList* GetChangeObservers(
1671320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      FileSystemType type) const;
1683551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  virtual const AccessObserverList* GetAccessObservers(
1691320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      FileSystemType type) const;
1703551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
1718bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // Registers quota observer for file updates on filesystem of |type|.
1728bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  void RegisterQuotaUpdateObserver(FileSystemType type);
1738bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1743551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  void InvalidateUsageCache(const GURL& origin_url,
1753551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)                            FileSystemType type);
1763551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  void StickyInvalidateUsageCache(const GURL& origin_url,
1773551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)                                  FileSystemType type);
178a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
1795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void CollectOpenFileSystemMetrics(base::File::Error error_code);
180a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
1817dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  base::SequencedTaskRunner* file_task_runner() {
1827dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    return file_task_runner_.get();
1837dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  }
1847dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
1853551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  AsyncFileUtil* file_util() { return sandbox_file_util_.get(); }
1867dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  FileSystemUsageCache* usage_cache() { return file_system_usage_cache_.get(); }
1873551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  SandboxQuotaObserver* quota_observer() { return quota_observer_.get(); }
1887dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
18903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  storage::SpecialStoragePolicy* special_storage_policy() {
1907dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    return special_storage_policy_.get();
1917dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  }
1927dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
1933551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  const FileSystemOptions& file_system_options() const {
1943551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    return file_system_options_;
1953551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  }
1967dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
1973551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  FileSystemFileUtil* sync_file_util();
198a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch
1997dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch private:
200f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  friend class QuotaBackendImpl;
2015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  friend class SandboxQuotaObserver;
2025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  friend class content::SandboxFileSystemBackendDelegateTest;
2035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  friend class content::SandboxFileSystemTestHelper;
2048bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
2058bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // Performs API-specific validity checks on the given path |url|.
2068bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // Returns true if access to |url| is valid in this filesystem.
2078bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  bool IsAccessValid(const FileSystemURL& url) const;
2088bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
2098bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // Returns true if the given |url|'s scheme is allowed to access
2108bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // filesystem.
2118bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  bool IsAllowedScheme(const GURL& url) const;
212a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
213a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // Returns a path to the usage cache file.
214a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  base::FilePath GetUsageCachePathForOriginAndType(
215a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      const GURL& origin_url,
216a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      FileSystemType type);
217a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
218a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // Returns a path to the usage cache file (static version).
219a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  static base::FilePath GetUsageCachePathForOriginAndType(
220a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      ObfuscatedFileUtil* sandbox_file_util,
221a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      const GURL& origin_url,
222a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      FileSystemType type,
2235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::File::Error* error_out);
224a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
225a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  int64 RecalculateUsage(FileSystemContext* context,
226a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)                         const GURL& origin,
227a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)                         FileSystemType type);
228a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
2293551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  ObfuscatedFileUtil* obfuscated_file_util();
2303551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
2317dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
2327dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
2333551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  scoped_ptr<AsyncFileUtil> sandbox_file_util_;
2347dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  scoped_ptr<FileSystemUsageCache> file_system_usage_cache_;
2357dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  scoped_ptr<SandboxQuotaObserver> quota_observer_;
236f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  scoped_ptr<QuotaReservationManager> quota_reservation_manager_;
2377dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
23803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy_;
2397dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
240a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  FileSystemOptions file_system_options_;
241a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
2423551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  bool is_filesystem_opened_;
243424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  base::ThreadChecker io_thread_checker_;
2443551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
2453551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // Accessed only on the file thread.
246a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  std::set<GURL> visited_origins_;
247a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
248a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  std::set<std::pair<GURL, FileSystemType> > sticky_dirty_origins_;
249a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
2503551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  std::map<FileSystemType, UpdateObserverList> update_observers_;
2513551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  std::map<FileSystemType, ChangeObserverList> change_observers_;
2523551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  std::map<FileSystemType, AccessObserverList> access_observers_;
2533551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
254a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  base::Time next_release_time_for_open_filesystem_stat_;
255a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
2563551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  base::WeakPtrFactory<SandboxFileSystemBackendDelegate> weak_factory_;
257a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch
2583551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(SandboxFileSystemBackendDelegate);
2597dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch};
2607dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
26103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)}  // namespace storage
2627dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
2631320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#endif  // STORAGE_BROWSER_FILEAPI_SANDBOX_FILE_SYSTEM_BACKEND_DELEGATE_H_
264