| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <map> | 11 #include <map> |
| 12 #include <memory> | 12 #include <memory> |
| 13 #include <set> | 13 #include <set> |
| 14 #include <string> | 14 #include <string> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
| 18 #include "base/files/file_path.h" | 18 #include "base/files/file_path.h" |
| 19 #include "base/gtest_prod_util.h" | 19 #include "base/gtest_prod_util.h" |
| 20 #include "base/macros.h" | 20 #include "base/macros.h" |
| 21 #include "content/browser/browser_main_loop.h" | 21 #include "content/browser/browser_main_loop.h" |
| 22 #include "content/browser/indexed_db/indexed_db_factory.h" | 22 #include "content/browser/indexed_db/indexed_db_factory.h" |
| 23 #include "content/public/browser/indexed_db_context.h" | 23 #include "content/public/browser/indexed_db_context.h" |
| 24 #include "storage/browser/quota/quota_manager_proxy.h" |
| 25 #include "storage/browser/quota/special_storage_policy.h" |
| 24 #include "storage/common/quota/quota_types.h" | 26 #include "storage/common/quota/quota_types.h" |
| 25 #include "url/gurl.h" | 27 #include "url/gurl.h" |
| 26 | 28 |
| 27 namespace base { | 29 namespace base { |
| 28 class ListValue; | 30 class ListValue; |
| 29 class FilePath; | 31 class FilePath; |
| 30 class SequencedTaskRunner; | 32 class SequencedTaskRunner; |
| 31 } | 33 } |
| 32 | 34 |
| 33 namespace storage { | |
| 34 class QuotaManagerProxy; | |
| 35 class SpecialStoragePolicy; | |
| 36 } | |
| 37 | |
| 38 namespace url { | 35 namespace url { |
| 39 class Origin; | 36 class Origin; |
| 40 } | 37 } |
| 41 | 38 |
| 42 namespace content { | 39 namespace content { |
| 43 | 40 |
| 44 class IndexedDBConnection; | 41 class IndexedDBConnection; |
| 45 | 42 |
| 46 class CONTENT_EXPORT IndexedDBContextImpl | 43 class CONTENT_EXPORT IndexedDBContextImpl |
| 47 : NON_EXPORTED_BASE(public IndexedDBContext) { | 44 : NON_EXPORTED_BASE(public IndexedDBContext) { |
| 48 public: | 45 public: |
| 49 // Recorded in histograms, so append only. | 46 // Recorded in histograms, so append only. |
| 50 enum ForceCloseReason { | 47 enum ForceCloseReason { |
| 51 FORCE_CLOSE_DELETE_ORIGIN = 0, | 48 FORCE_CLOSE_DELETE_ORIGIN = 0, |
| 52 FORCE_CLOSE_BACKING_STORE_FAILURE, | 49 FORCE_CLOSE_BACKING_STORE_FAILURE, |
| 53 FORCE_CLOSE_INTERNALS_PAGE, | 50 FORCE_CLOSE_INTERNALS_PAGE, |
| 54 FORCE_CLOSE_COPY_ORIGIN, | 51 FORCE_CLOSE_COPY_ORIGIN, |
| 55 FORCE_CLOSE_REASON_MAX | 52 FORCE_CLOSE_REASON_MAX |
| 56 }; | 53 }; |
| 57 | 54 |
| 58 // The indexed db directory. | 55 // The indexed db directory. |
| 59 static const base::FilePath::CharType kIndexedDBDirectory[]; | 56 static const base::FilePath::CharType kIndexedDBDirectory[]; |
| 60 | 57 |
| 61 // If |data_path| is empty, nothing will be saved to disk. | 58 // If |data_path| is empty, nothing will be saved to disk. |
| 62 IndexedDBContextImpl(const base::FilePath& data_path, | 59 IndexedDBContextImpl( |
| 63 storage::SpecialStoragePolicy* special_storage_policy, | 60 const base::FilePath& data_path, |
| 64 storage::QuotaManagerProxy* quota_manager_proxy, | 61 scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy, |
| 65 scoped_refptr<base::SequencedTaskRunner> task_runner); | 62 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy); |
| 66 | 63 |
| 67 IndexedDBFactory* GetIDBFactory(); | 64 IndexedDBFactory* GetIDBFactory(); |
| 68 | 65 |
| 69 // Disables the exit-time deletion of session-only data. | 66 // Disables the exit-time deletion of session-only data. |
| 70 void SetForceKeepSessionState() { force_keep_session_state_ = true; } | 67 void SetForceKeepSessionState() { force_keep_session_state_ = true; } |
| 71 | 68 |
| 72 // IndexedDBContext implementation: | 69 // IndexedDBContext implementation: |
| 73 base::SequencedTaskRunner* TaskRunner() const override; | 70 base::SequencedTaskRunner* TaskRunner() const override; |
| 74 std::vector<IndexedDBInfo> GetAllOriginsInfo() override; | 71 std::vector<IndexedDBInfo> GetAllOriginsInfo() override; |
| 75 int64_t GetOriginDiskUsage(const GURL& origin_url) override; | 72 int64_t GetOriginDiskUsage(const GURL& origin_url) override; |
| 76 void DeleteForOrigin(const GURL& origin_url) override; | 73 void DeleteForOrigin(const GURL& origin_url) override; |
| 77 void CopyOriginData(const GURL& origin_url, | 74 void CopyOriginData(const GURL& origin_url, |
| 78 IndexedDBContext* dest_context) override; | 75 IndexedDBContext* dest_context) override; |
| 79 base::FilePath GetFilePathForTesting(const GURL& origin_url) const override; | 76 base::FilePath GetFilePathForTesting(const GURL& origin_url) const override; |
| 80 void SetTaskRunnerForTesting(base::SequencedTaskRunner* task_runner) override; | 77 void ResetCachesForTesting() override; |
| 81 | 78 |
| 82 // TODO(jsbell): Replace IndexedDBContext members with these. | 79 // TODO(jsbell): Replace IndexedDBContext members with these. |
| 83 int64_t GetOriginDiskUsage(const url::Origin& origin); | 80 int64_t GetOriginDiskUsage(const url::Origin& origin); |
| 84 void DeleteForOrigin(const url::Origin& origin); | 81 void DeleteForOrigin(const url::Origin& origin); |
| 85 void CopyOriginData(const url::Origin& origin, | 82 void CopyOriginData(const url::Origin& origin, |
| 86 IndexedDBContext* dest_context); | 83 IndexedDBContext* dest_context); |
| 87 base::FilePath GetFilePathForTesting(const url::Origin& origin) const; | 84 base::FilePath GetFilePathForTesting(const url::Origin& origin) const; |
| 88 | 85 |
| 89 // Methods called by IndexedDBDispatcherHost for quota support. | 86 // Methods called by IndexedDBDispatcherHost for quota support. |
| 90 void ConnectionOpened(const url::Origin& origin, IndexedDBConnection* db); | 87 void ConnectionOpened(const url::Origin& origin, IndexedDBConnection* db); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 111 // owning object. | 108 // owning object. |
| 112 void ForceClose(const url::Origin origin, ForceCloseReason reason); | 109 void ForceClose(const url::Origin origin, ForceCloseReason reason); |
| 113 // GetStoragePaths returns all paths owned by this database, in arbitrary | 110 // GetStoragePaths returns all paths owned by this database, in arbitrary |
| 114 // order. | 111 // order. |
| 115 std::vector<base::FilePath> GetStoragePaths(const url::Origin& origin) const; | 112 std::vector<base::FilePath> GetStoragePaths(const url::Origin& origin) const; |
| 116 | 113 |
| 117 base::FilePath data_path() const { return data_path_; } | 114 base::FilePath data_path() const { return data_path_; } |
| 118 size_t GetConnectionCount(const url::Origin& origin); | 115 size_t GetConnectionCount(const url::Origin& origin); |
| 119 int GetOriginBlobFileCount(const url::Origin& origin); | 116 int GetOriginBlobFileCount(const url::Origin& origin); |
| 120 | 117 |
| 118 // TODO(jsbell): Update tests to eliminate the need for this. |
| 119 void SetTaskRunnerForTesting( |
| 120 scoped_refptr<base::SequencedTaskRunner> task_runner); |
| 121 |
| 121 // For unit tests allow to override the |data_path_|. | 122 // For unit tests allow to override the |data_path_|. |
| 122 void set_data_path_for_testing(const base::FilePath& data_path) { | 123 void set_data_path_for_testing(const base::FilePath& data_path) { |
| 123 data_path_ = data_path; | 124 data_path_ = data_path; |
| 124 } | 125 } |
| 125 | 126 |
| 126 bool is_incognito() const { return data_path_.empty(); } | 127 bool is_incognito() const { return data_path_.empty(); } |
| 127 | 128 |
| 128 protected: | 129 protected: |
| 129 ~IndexedDBContextImpl() override; | 130 ~IndexedDBContextImpl() override; |
| 130 | 131 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 146 base::Time GetOriginLastModified(const url::Origin& origin); | 147 base::Time GetOriginLastModified(const url::Origin& origin); |
| 147 | 148 |
| 148 std::set<url::Origin>* GetOriginSet(); | 149 std::set<url::Origin>* GetOriginSet(); |
| 149 bool AddToOriginSet(const url::Origin& origin) { | 150 bool AddToOriginSet(const url::Origin& origin) { |
| 150 return GetOriginSet()->insert(origin).second; | 151 return GetOriginSet()->insert(origin).second; |
| 151 } | 152 } |
| 152 void RemoveFromOriginSet(const url::Origin& origin) { | 153 void RemoveFromOriginSet(const url::Origin& origin) { |
| 153 GetOriginSet()->erase(origin); | 154 GetOriginSet()->erase(origin); |
| 154 } | 155 } |
| 155 | 156 |
| 156 // Only for testing. | |
| 157 void ResetCaches(); | |
| 158 | |
| 159 scoped_refptr<IndexedDBFactory> factory_; | 157 scoped_refptr<IndexedDBFactory> factory_; |
| 160 base::FilePath data_path_; | 158 base::FilePath data_path_; |
| 161 // If true, nothing (not even session-only data) should be deleted on exit. | 159 // If true, nothing (not even session-only data) should be deleted on exit. |
| 162 bool force_keep_session_state_; | 160 bool force_keep_session_state_; |
| 163 scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy_; | 161 scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy_; |
| 164 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy_; | 162 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy_; |
| 165 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 163 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 166 std::unique_ptr<std::set<url::Origin>> origin_set_; | 164 std::unique_ptr<std::set<url::Origin>> origin_set_; |
| 167 std::map<url::Origin, int64_t> origin_size_map_; | 165 std::map<url::Origin, int64_t> origin_size_map_; |
| 168 | 166 |
| 169 DISALLOW_COPY_AND_ASSIGN(IndexedDBContextImpl); | 167 DISALLOW_COPY_AND_ASSIGN(IndexedDBContextImpl); |
| 170 }; | 168 }; |
| 171 | 169 |
| 172 } // namespace content | 170 } // namespace content |
| 173 | 171 |
| 174 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONTEXT_IMPL_H_ | 172 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONTEXT_IMPL_H_ |
| OLD | NEW |