OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONTEXT_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONTEXT_IMPL_H_ |
6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONTEXT_IMPL_H_ | 6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONTEXT_IMPL_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "webkit/common/quota/quota_types.h" | 21 #include "webkit/common/quota/quota_types.h" |
22 | 22 |
23 class GURL; | 23 class GURL; |
24 | 24 |
25 namespace base { | 25 namespace base { |
26 class ListValue; | 26 class ListValue; |
27 class FilePath; | 27 class FilePath; |
28 class SequencedTaskRunner; | 28 class SequencedTaskRunner; |
29 } | 29 } |
30 | 30 |
31 namespace quota { | 31 namespace storage { |
32 class QuotaManagerProxy; | 32 class QuotaManagerProxy; |
33 class SpecialStoragePolicy; | 33 class SpecialStoragePolicy; |
34 } | 34 } |
35 | 35 |
36 namespace content { | 36 namespace content { |
37 | 37 |
38 class IndexedDBConnection; | 38 class IndexedDBConnection; |
39 | 39 |
40 class CONTENT_EXPORT IndexedDBContextImpl | 40 class CONTENT_EXPORT IndexedDBContextImpl |
41 : NON_EXPORTED_BASE(public IndexedDBContext) { | 41 : NON_EXPORTED_BASE(public IndexedDBContext) { |
42 public: | 42 public: |
43 // If |data_path| is empty, nothing will be saved to disk. | 43 // If |data_path| is empty, nothing will be saved to disk. |
44 IndexedDBContextImpl(const base::FilePath& data_path, | 44 IndexedDBContextImpl(const base::FilePath& data_path, |
45 quota::SpecialStoragePolicy* special_storage_policy, | 45 storage::SpecialStoragePolicy* special_storage_policy, |
46 quota::QuotaManagerProxy* quota_manager_proxy, | 46 storage::QuotaManagerProxy* quota_manager_proxy, |
47 base::SequencedTaskRunner* task_runner); | 47 base::SequencedTaskRunner* task_runner); |
48 | 48 |
49 IndexedDBFactory* GetIDBFactory(); | 49 IndexedDBFactory* GetIDBFactory(); |
50 | 50 |
51 // The indexed db directory. | 51 // The indexed db directory. |
52 static const base::FilePath::CharType kIndexedDBDirectory[]; | 52 static const base::FilePath::CharType kIndexedDBDirectory[]; |
53 | 53 |
54 // Disables the exit-time deletion of session-only data. | 54 // Disables the exit-time deletion of session-only data. |
55 void SetForceKeepSessionState() { force_keep_session_state_ = true; } | 55 void SetForceKeepSessionState() { force_keep_session_state_ = true; } |
56 | 56 |
57 // IndexedDBContext implementation: | 57 // IndexedDBContext implementation: |
58 virtual base::SequencedTaskRunner* TaskRunner() const OVERRIDE; | 58 virtual base::SequencedTaskRunner* TaskRunner() const OVERRIDE; |
59 virtual std::vector<IndexedDBInfo> GetAllOriginsInfo() OVERRIDE; | 59 virtual std::vector<IndexedDBInfo> GetAllOriginsInfo() OVERRIDE; |
60 virtual int64 GetOriginDiskUsage(const GURL& origin_url) OVERRIDE; | 60 virtual int64 GetOriginDiskUsage(const GURL& origin_url) OVERRIDE; |
61 virtual void DeleteForOrigin(const GURL& origin_url) OVERRIDE; | 61 virtual void DeleteForOrigin(const GURL& origin_url) OVERRIDE; |
62 virtual base::FilePath GetFilePathForTesting( | 62 virtual base::FilePath GetFilePathForTesting( |
63 const std::string& origin_id) const OVERRIDE; | 63 const std::string& origin_id) const OVERRIDE; |
64 virtual void SetTaskRunnerForTesting(base::SequencedTaskRunner* task_runner) | 64 virtual void SetTaskRunnerForTesting(base::SequencedTaskRunner* task_runner) |
65 OVERRIDE; | 65 OVERRIDE; |
66 | 66 |
67 // Methods called by IndexedDBDispatcherHost for quota support. | 67 // Methods called by IndexedDBDispatcherHost for quota support. |
68 void ConnectionOpened(const GURL& origin_url, IndexedDBConnection* db); | 68 void ConnectionOpened(const GURL& origin_url, IndexedDBConnection* db); |
69 void ConnectionClosed(const GURL& origin_url, IndexedDBConnection* db); | 69 void ConnectionClosed(const GURL& origin_url, IndexedDBConnection* db); |
70 void TransactionComplete(const GURL& origin_url); | 70 void TransactionComplete(const GURL& origin_url); |
71 void DatabaseDeleted(const GURL& origin_url); | 71 void DatabaseDeleted(const GURL& origin_url); |
72 bool WouldBeOverQuota(const GURL& origin_url, int64 additional_bytes); | 72 bool WouldBeOverQuota(const GURL& origin_url, int64 additional_bytes); |
73 bool IsOverQuota(const GURL& origin_url); | 73 bool IsOverQuota(const GURL& origin_url); |
74 | 74 |
75 quota::QuotaManagerProxy* quota_manager_proxy(); | 75 storage::QuotaManagerProxy* quota_manager_proxy(); |
76 | 76 |
77 std::vector<GURL> GetAllOrigins(); | 77 std::vector<GURL> GetAllOrigins(); |
78 base::Time GetOriginLastModified(const GURL& origin_url); | 78 base::Time GetOriginLastModified(const GURL& origin_url); |
79 base::ListValue* GetAllOriginsDetails(); | 79 base::ListValue* GetAllOriginsDetails(); |
80 | 80 |
81 // Recorded in histograms, so append only. | 81 // Recorded in histograms, so append only. |
82 enum ForceCloseReason { | 82 enum ForceCloseReason { |
83 FORCE_CLOSE_DELETE_ORIGIN = 0, | 83 FORCE_CLOSE_DELETE_ORIGIN = 0, |
84 FORCE_CLOSE_BACKING_STORE_FAILURE, | 84 FORCE_CLOSE_BACKING_STORE_FAILURE, |
85 FORCE_CLOSE_INTERNALS_PAGE, | 85 FORCE_CLOSE_INTERNALS_PAGE, |
(...skipping 30 matching lines...) Expand all Loading... |
116 friend class IndexedDBQuotaClientTest; | 116 friend class IndexedDBQuotaClientTest; |
117 | 117 |
118 typedef std::map<GURL, int64> OriginToSizeMap; | 118 typedef std::map<GURL, int64> OriginToSizeMap; |
119 class IndexedDBGetUsageAndQuotaCallback; | 119 class IndexedDBGetUsageAndQuotaCallback; |
120 | 120 |
121 base::FilePath GetIndexedDBFilePath(const std::string& origin_id) const; | 121 base::FilePath GetIndexedDBFilePath(const std::string& origin_id) const; |
122 int64 ReadUsageFromDisk(const GURL& origin_url) const; | 122 int64 ReadUsageFromDisk(const GURL& origin_url) const; |
123 void EnsureDiskUsageCacheInitialized(const GURL& origin_url); | 123 void EnsureDiskUsageCacheInitialized(const GURL& origin_url); |
124 void QueryDiskAndUpdateQuotaUsage(const GURL& origin_url); | 124 void QueryDiskAndUpdateQuotaUsage(const GURL& origin_url); |
125 void GotUsageAndQuota(const GURL& origin_url, | 125 void GotUsageAndQuota(const GURL& origin_url, |
126 quota::QuotaStatusCode, | 126 storage::QuotaStatusCode, |
127 int64 usage, | 127 int64 usage, |
128 int64 quota); | 128 int64 quota); |
129 void GotUpdatedQuota(const GURL& origin_url, int64 usage, int64 quota); | 129 void GotUpdatedQuota(const GURL& origin_url, int64 usage, int64 quota); |
130 void QueryAvailableQuota(const GURL& origin_url); | 130 void QueryAvailableQuota(const GURL& origin_url); |
131 | 131 |
132 std::set<GURL>* GetOriginSet(); | 132 std::set<GURL>* GetOriginSet(); |
133 bool AddToOriginSet(const GURL& origin_url) { | 133 bool AddToOriginSet(const GURL& origin_url) { |
134 return GetOriginSet()->insert(origin_url).second; | 134 return GetOriginSet()->insert(origin_url).second; |
135 } | 135 } |
136 void RemoveFromOriginSet(const GURL& origin_url) { | 136 void RemoveFromOriginSet(const GURL& origin_url) { |
137 GetOriginSet()->erase(origin_url); | 137 GetOriginSet()->erase(origin_url); |
138 } | 138 } |
139 | 139 |
140 // Only for testing. | 140 // Only for testing. |
141 void ResetCaches(); | 141 void ResetCaches(); |
142 | 142 |
143 scoped_refptr<IndexedDBFactory> factory_; | 143 scoped_refptr<IndexedDBFactory> factory_; |
144 base::FilePath data_path_; | 144 base::FilePath data_path_; |
145 // If true, nothing (not even session-only data) should be deleted on exit. | 145 // If true, nothing (not even session-only data) should be deleted on exit. |
146 bool force_keep_session_state_; | 146 bool force_keep_session_state_; |
147 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_; | 147 scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy_; |
148 scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_; | 148 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy_; |
149 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 149 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
150 scoped_ptr<std::set<GURL> > origin_set_; | 150 scoped_ptr<std::set<GURL> > origin_set_; |
151 OriginToSizeMap origin_size_map_; | 151 OriginToSizeMap origin_size_map_; |
152 OriginToSizeMap space_available_map_; | 152 OriginToSizeMap space_available_map_; |
153 | 153 |
154 DISALLOW_COPY_AND_ASSIGN(IndexedDBContextImpl); | 154 DISALLOW_COPY_AND_ASSIGN(IndexedDBContextImpl); |
155 }; | 155 }; |
156 | 156 |
157 } // namespace content | 157 } // namespace content |
158 | 158 |
159 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONTEXT_IMPL_H_ | 159 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONTEXT_IMPL_H_ |
OLD | NEW |