Fix Win8 metro startup crash from window switcher button
[chromium-blink-merge.git] / webkit / fileapi / sandbox_file_system_test_helper.h
blob15f9281cd5340f2b9caf0f6a03a56aa034ebe5c8
1 // Copyright (c) 2012 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.
5 #ifndef WEBKIT_FILEAPI_SANDBOX_FILE_SYSTEM_TEST_HELPER_H_
6 #define WEBKIT_FILEAPI_SANDBOX_FILE_SYSTEM_TEST_HELPER_H_
8 #include <string>
10 #include "base/files/file_path.h"
11 #include "base/memory/ref_counted.h"
12 #include "googleurl/src/gurl.h"
13 #include "webkit/browser/fileapi/file_system_usage_cache.h"
14 #include "webkit/fileapi/file_system_types.h"
15 #include "webkit/fileapi/file_system_url.h"
16 #include "webkit/fileapi/file_system_util.h"
17 #include "webkit/quota/quota_types.h"
19 namespace base {
20 class FilePath;
23 namespace quota {
24 class QuotaManagerProxy;
27 namespace fileapi {
29 class FileSystemContext;
30 class FileSystemFileUtil;
31 class FileSystemOperationContext;
32 class LocalFileSystemOperation;
34 // Filesystem test helper class that encapsulates test environment for
35 // a given {origin, type} pair. This helper only works for sandboxed
36 // file systems (Temporary or Persistent).
37 class SandboxFileSystemTestHelper {
38 public:
39 SandboxFileSystemTestHelper(const GURL& origin, FileSystemType type);
40 SandboxFileSystemTestHelper();
41 ~SandboxFileSystemTestHelper();
43 void SetUp(const base::FilePath& base_dir);
44 // If you want to use more than one SandboxFileSystemTestHelper in
45 // a single base directory, they have to share a context, so that they don't
46 // have multiple databases fighting over the lock to the origin directory
47 // [deep down inside ObfuscatedFileUtil].
48 void SetUp(FileSystemContext* file_system_context);
49 void SetUp(const base::FilePath& base_dir,
50 quota::QuotaManagerProxy* quota_manager_proxy);
51 void TearDown();
53 base::FilePath GetOriginRootPath() const;
54 base::FilePath GetLocalPath(const base::FilePath& path);
55 base::FilePath GetLocalPathFromASCII(const std::string& path);
57 // Returns empty path if filesystem type is neither temporary nor persistent.
58 base::FilePath GetUsageCachePath() const;
60 FileSystemURL CreateURL(const base::FilePath& path) const;
61 FileSystemURL CreateURLFromUTF8(const std::string& utf8) const {
62 return CreateURL(base::FilePath::FromUTF8Unsafe(utf8));
65 // This returns cached usage size returned by QuotaUtil.
66 int64 GetCachedOriginUsage() const;
68 // This doesn't work with OFSFU.
69 int64 ComputeCurrentOriginUsage();
71 int64 ComputeCurrentDirectoryDatabaseUsage() const;
73 LocalFileSystemOperation* NewOperation();
74 FileSystemOperationContext* NewOperationContext();
76 FileSystemContext* file_system_context() const {
77 return file_system_context_.get();
80 const GURL& origin() const { return origin_; }
81 FileSystemType type() const { return type_; }
82 quota::StorageType storage_type() const {
83 return FileSystemTypeToQuotaStorageType(type_);
85 FileSystemFileUtil* file_util() const { return file_util_; }
86 FileSystemUsageCache* usage_cache();
88 private:
89 void SetUpFileSystem();
91 scoped_refptr<FileSystemContext> file_system_context_;
93 const GURL origin_;
94 const FileSystemType type_;
95 FileSystemFileUtil* file_util_;
98 } // namespace fileapi
100 #endif // WEBKIT_FILEAPI_SANDBOX_FILE_SYSTEM_TEST_HELPER_H_