| 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/common/quota/quota_types.h" | 24 #include "storage/common/quota/quota_types.h" |
| 25 #include "url/gurl.h" | 25 #include "url/gurl.h" |
| 26 | 26 |
| 27 class GURL; | |
| 28 | |
| 29 namespace base { | 27 namespace base { |
| 30 class ListValue; | 28 class ListValue; |
| 31 class FilePath; | 29 class FilePath; |
| 32 class SequencedTaskRunner; | 30 class SequencedTaskRunner; |
| 33 } | 31 } |
| 34 | 32 |
| 35 namespace storage { | 33 namespace storage { |
| 36 class QuotaManagerProxy; | 34 class QuotaManagerProxy; |
| 37 class SpecialStoragePolicy; | 35 class SpecialStoragePolicy; |
| 38 } | 36 } |
| 39 | 37 |
| 38 namespace url { |
| 39 class Origin; |
| 40 } |
| 41 |
| 40 namespace content { | 42 namespace content { |
| 41 | 43 |
| 42 class IndexedDBConnection; | 44 class IndexedDBConnection; |
| 43 | 45 |
| 44 class CONTENT_EXPORT IndexedDBContextImpl | 46 class CONTENT_EXPORT IndexedDBContextImpl |
| 45 : NON_EXPORTED_BASE(public IndexedDBContext) { | 47 : NON_EXPORTED_BASE(public IndexedDBContext) { |
| 46 public: | 48 public: |
| 47 // Recorded in histograms, so append only. | 49 // Recorded in histograms, so append only. |
| 48 enum ForceCloseReason { | 50 enum ForceCloseReason { |
| 49 FORCE_CLOSE_DELETE_ORIGIN = 0, | 51 FORCE_CLOSE_DELETE_ORIGIN = 0, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 70 // IndexedDBContext implementation: | 72 // IndexedDBContext implementation: |
| 71 base::SequencedTaskRunner* TaskRunner() const override; | 73 base::SequencedTaskRunner* TaskRunner() const override; |
| 72 std::vector<IndexedDBInfo> GetAllOriginsInfo() override; | 74 std::vector<IndexedDBInfo> GetAllOriginsInfo() override; |
| 73 int64_t GetOriginDiskUsage(const GURL& origin_url) override; | 75 int64_t GetOriginDiskUsage(const GURL& origin_url) override; |
| 74 void DeleteForOrigin(const GURL& origin_url) override; | 76 void DeleteForOrigin(const GURL& origin_url) override; |
| 75 void CopyOriginData(const GURL& origin_url, | 77 void CopyOriginData(const GURL& origin_url, |
| 76 IndexedDBContext* dest_context) override; | 78 IndexedDBContext* dest_context) override; |
| 77 base::FilePath GetFilePathForTesting(const GURL& origin_url) const override; | 79 base::FilePath GetFilePathForTesting(const GURL& origin_url) const override; |
| 78 void SetTaskRunnerForTesting(base::SequencedTaskRunner* task_runner) override; | 80 void SetTaskRunnerForTesting(base::SequencedTaskRunner* task_runner) override; |
| 79 | 81 |
| 82 // TODO(jsbell): Replace IndexedDBContext members with these. |
| 83 int64_t GetOriginDiskUsage(const url::Origin& origin); |
| 84 void DeleteForOrigin(const url::Origin& origin); |
| 85 void CopyOriginData(const url::Origin& origin, |
| 86 IndexedDBContext* dest_context); |
| 87 base::FilePath GetFilePathForTesting(const url::Origin& origin) const; |
| 88 |
| 80 // Methods called by IndexedDBDispatcherHost for quota support. | 89 // Methods called by IndexedDBDispatcherHost for quota support. |
| 81 void ConnectionOpened(const GURL& origin_url, IndexedDBConnection* db); | 90 void ConnectionOpened(const url::Origin& origin, IndexedDBConnection* db); |
| 82 void ConnectionClosed(const GURL& origin_url, IndexedDBConnection* db); | 91 void ConnectionClosed(const url::Origin& origin, IndexedDBConnection* db); |
| 83 void TransactionComplete(const GURL& origin_url); | 92 void TransactionComplete(const url::Origin& origin); |
| 84 void DatabaseDeleted(const GURL& origin_url); | 93 void DatabaseDeleted(const url::Origin& origin); |
| 85 | 94 |
| 86 static base::FilePath GetBlobStoreFileName(const GURL& origin_url); | 95 static base::FilePath GetBlobStoreFileName(const url::Origin& origin); |
| 87 static base::FilePath GetLevelDBFileName(const GURL& origin_url); | 96 static base::FilePath GetLevelDBFileName(const url::Origin& origin); |
| 88 | 97 |
| 89 // Will be null in unit tests. | 98 // Will be null in unit tests. |
| 90 storage::QuotaManagerProxy* quota_manager_proxy() const { | 99 storage::QuotaManagerProxy* quota_manager_proxy() const { |
| 91 return quota_manager_proxy_.get(); | 100 return quota_manager_proxy_.get(); |
| 92 } | 101 } |
| 93 | 102 |
| 94 // Returns a list of all origins with backing stores. | 103 // Returns a list of all origins with backing stores. |
| 95 std::vector<GURL> GetAllOrigins(); | 104 std::vector<url::Origin> GetAllOrigins(); |
| 96 bool HasOrigin(const GURL& origin); | 105 bool HasOrigin(const url::Origin& origin); |
| 97 | 106 |
| 98 // Used by IndexedDBInternalsUI to populate internals page. | 107 // Used by IndexedDBInternalsUI to populate internals page. |
| 99 base::ListValue* GetAllOriginsDetails(); | 108 base::ListValue* GetAllOriginsDetails(); |
| 100 | 109 |
| 101 // ForceClose takes a value rather than a reference since it may release the | 110 // ForceClose takes a value rather than a reference since it may release the |
| 102 // owning object. | 111 // owning object. |
| 103 void ForceClose(const GURL origin_url, ForceCloseReason reason); | 112 void ForceClose(const url::Origin origin, ForceCloseReason reason); |
| 104 // GetStoragePaths returns all paths owned by this database, in arbitrary | 113 // GetStoragePaths returns all paths owned by this database, in arbitrary |
| 105 // order. | 114 // order. |
| 106 std::vector<base::FilePath> GetStoragePaths(const GURL& origin_url) const; | 115 std::vector<base::FilePath> GetStoragePaths(const url::Origin& origin) const; |
| 107 | 116 |
| 108 base::FilePath data_path() const { return data_path_; } | 117 base::FilePath data_path() const { return data_path_; } |
| 109 size_t GetConnectionCount(const GURL& origin_url); | 118 size_t GetConnectionCount(const url::Origin& origin); |
| 110 int GetOriginBlobFileCount(const GURL& origin_url); | 119 int GetOriginBlobFileCount(const url::Origin& origin); |
| 111 | 120 |
| 112 // For unit tests allow to override the |data_path_|. | 121 // For unit tests allow to override the |data_path_|. |
| 113 void set_data_path_for_testing(const base::FilePath& data_path) { | 122 void set_data_path_for_testing(const base::FilePath& data_path) { |
| 114 data_path_ = data_path; | 123 data_path_ = data_path; |
| 115 } | 124 } |
| 116 | 125 |
| 117 bool is_incognito() const { return data_path_.empty(); } | 126 bool is_incognito() const { return data_path_.empty(); } |
| 118 | 127 |
| 119 protected: | 128 protected: |
| 120 ~IndexedDBContextImpl() override; | 129 ~IndexedDBContextImpl() override; |
| 121 | 130 |
| 122 private: | 131 private: |
| 123 FRIEND_TEST_ALL_PREFIXES(IndexedDBTest, ClearLocalState); | 132 FRIEND_TEST_ALL_PREFIXES(IndexedDBTest, ClearLocalState); |
| 124 FRIEND_TEST_ALL_PREFIXES(IndexedDBTest, ClearSessionOnlyDatabases); | 133 FRIEND_TEST_ALL_PREFIXES(IndexedDBTest, ClearSessionOnlyDatabases); |
| 125 FRIEND_TEST_ALL_PREFIXES(IndexedDBTest, SetForceKeepSessionState); | 134 FRIEND_TEST_ALL_PREFIXES(IndexedDBTest, SetForceKeepSessionState); |
| 126 FRIEND_TEST_ALL_PREFIXES(IndexedDBTest, ForceCloseOpenDatabasesOnDelete); | 135 FRIEND_TEST_ALL_PREFIXES(IndexedDBTest, ForceCloseOpenDatabasesOnDelete); |
| 127 friend class IndexedDBQuotaClientTest; | 136 friend class IndexedDBQuotaClientTest; |
| 128 | 137 |
| 129 typedef std::map<GURL, int64_t> OriginToSizeMap; | 138 typedef std::map<url::Origin, int64_t> OriginToSizeMap; |
| 130 class IndexedDBGetUsageAndQuotaCallback; | 139 class IndexedDBGetUsageAndQuotaCallback; |
| 131 | 140 |
| 132 base::FilePath GetBlobStorePath(const GURL& origin_url) const; | 141 base::FilePath GetBlobStorePath(const url::Origin& origin) const; |
| 133 base::FilePath GetLevelDBPath(const GURL& origin_url) const; | 142 base::FilePath GetLevelDBPath(const url::Origin& origin) const; |
| 134 | 143 |
| 135 int64_t ReadUsageFromDisk(const GURL& origin_url) const; | 144 int64_t ReadUsageFromDisk(const url::Origin& origin) const; |
| 136 void EnsureDiskUsageCacheInitialized(const GURL& origin_url); | 145 void EnsureDiskUsageCacheInitialized(const url::Origin& origin); |
| 137 void QueryDiskAndUpdateQuotaUsage(const GURL& origin_url); | 146 void QueryDiskAndUpdateQuotaUsage(const url::Origin& origin); |
| 138 base::Time GetOriginLastModified(const GURL& origin_url); | 147 base::Time GetOriginLastModified(const url::Origin& origin); |
| 139 | 148 |
| 140 std::set<GURL>* GetOriginSet(); | 149 std::set<url::Origin>* GetOriginSet(); |
| 141 bool AddToOriginSet(const GURL& origin_url) { | 150 bool AddToOriginSet(const url::Origin& origin) { |
| 142 return GetOriginSet()->insert(origin_url).second; | 151 return GetOriginSet()->insert(origin).second; |
| 143 } | 152 } |
| 144 void RemoveFromOriginSet(const GURL& origin_url) { | 153 void RemoveFromOriginSet(const url::Origin& origin) { |
| 145 GetOriginSet()->erase(origin_url); | 154 GetOriginSet()->erase(origin); |
| 146 } | 155 } |
| 147 | 156 |
| 148 // Only for testing. | 157 // Only for testing. |
| 149 void ResetCaches(); | 158 void ResetCaches(); |
| 150 | 159 |
| 151 scoped_refptr<IndexedDBFactory> factory_; | 160 scoped_refptr<IndexedDBFactory> factory_; |
| 152 base::FilePath data_path_; | 161 base::FilePath data_path_; |
| 153 // If true, nothing (not even session-only data) should be deleted on exit. | 162 // If true, nothing (not even session-only data) should be deleted on exit. |
| 154 bool force_keep_session_state_; | 163 bool force_keep_session_state_; |
| 155 scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy_; | 164 scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy_; |
| 156 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy_; | 165 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy_; |
| 157 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 166 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 158 std::unique_ptr<std::set<GURL>> origin_set_; | 167 std::unique_ptr<std::set<url::Origin>> origin_set_; |
| 159 OriginToSizeMap origin_size_map_; | 168 OriginToSizeMap origin_size_map_; |
| 160 | 169 |
| 161 DISALLOW_COPY_AND_ASSIGN(IndexedDBContextImpl); | 170 DISALLOW_COPY_AND_ASSIGN(IndexedDBContextImpl); |
| 162 }; | 171 }; |
| 163 | 172 |
| 164 } // namespace content | 173 } // namespace content |
| 165 | 174 |
| 166 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONTEXT_IMPL_H_ | 175 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONTEXT_IMPL_H_ |
| OLD | NEW |