Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / storage / browser / fileapi / quota / quota_backend_impl.h
1 // Copyright 2013 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.
4
5 #ifndef STORAGE_BROWSER_FILEAPI_QUOTA_QUOTA_BACKEND_IMPL_H_
6 #define STORAGE_BROWSER_FILEAPI_QUOTA_QUOTA_BACKEND_IMPL_H_
7
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/weak_ptr.h"
10 #include "storage/browser/fileapi/quota/quota_reservation_manager.h"
11 #include "storage/browser/fileapi/sandbox_file_system_backend_delegate.h"
12 #include "storage/browser/storage_browser_export.h"
13 #include "storage/common/quota/quota_status_code.h"
14
15 namespace base {
16 class SequencedTaskRunner;
17 }
18
19 namespace content {
20 class QuotaBackendImplTest;
21 }
22
23 namespace storage {
24 class QuotaManagerProxy;
25 }
26
27 namespace storage {
28
29 class FileSystemUsageCache;
30 class ObfuscatedFileUtil;
31
32 // An instance of this class is owned by QuotaReservationManager.
33 class STORAGE_EXPORT QuotaBackendImpl
34     : public QuotaReservationManager::QuotaBackend {
35  public:
36   typedef QuotaReservationManager::ReserveQuotaCallback
37       ReserveQuotaCallback;
38
39   QuotaBackendImpl(base::SequencedTaskRunner* file_task_runner,
40                    ObfuscatedFileUtil* obfuscated_file_util,
41                    FileSystemUsageCache* file_system_usage_cache,
42                    storage::QuotaManagerProxy* quota_manager_proxy);
43   ~QuotaBackendImpl() override;
44
45   // QuotaReservationManager::QuotaBackend overrides.
46   void ReserveQuota(const GURL& origin,
47                     FileSystemType type,
48                     int64 delta,
49                     const ReserveQuotaCallback& callback) override;
50   void ReleaseReservedQuota(const GURL& origin,
51                             FileSystemType type,
52                             int64 size) override;
53   void CommitQuotaUsage(const GURL& origin,
54                         FileSystemType type,
55                         int64 delta) override;
56   void IncrementDirtyCount(const GURL& origin, FileSystemType type) override;
57   void DecrementDirtyCount(const GURL& origin, FileSystemType type) override;
58
59  private:
60   friend class content::QuotaBackendImplTest;
61
62   struct QuotaReservationInfo {
63     QuotaReservationInfo(const GURL& origin, FileSystemType type, int64 delta);
64     ~QuotaReservationInfo();
65
66     GURL origin;
67     FileSystemType type;
68     int64 delta;
69   };
70
71   void DidGetUsageAndQuotaForReserveQuota(const QuotaReservationInfo& info,
72                                           const ReserveQuotaCallback& callback,
73                                           storage::QuotaStatusCode status,
74                                           int64 usage,
75                                           int64 quota);
76
77   void ReserveQuotaInternal(
78       const QuotaReservationInfo& info);
79   base::File::Error GetUsageCachePath(
80       const GURL& origin,
81       FileSystemType type,
82       base::FilePath* usage_file_path);
83
84   scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
85
86   // Owned by SandboxFileSystemBackendDelegate.
87   ObfuscatedFileUtil* obfuscated_file_util_;
88   FileSystemUsageCache* file_system_usage_cache_;
89
90   scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy_;
91
92   base::WeakPtrFactory<QuotaBackendImpl> weak_ptr_factory_;
93
94   DISALLOW_COPY_AND_ASSIGN(QuotaBackendImpl);
95 };
96
97 }  // namespace storage
98
99 #endif  // STORAGE_BROWSER_FILEAPI_QUOTA_QUOTA_BACKEND_IMPL_H_