| 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 #include "content/browser/indexed_db/indexed_db_quota_client.h" | 5 #include "content/browser/indexed_db/indexed_db_quota_client.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 const GetUsageCallback& callback) { | 77 const GetUsageCallback& callback) { |
| 78 DCHECK(!callback.is_null()); | 78 DCHECK(!callback.is_null()); |
| 79 DCHECK(indexed_db_context_.get()); | 79 DCHECK(indexed_db_context_.get()); |
| 80 | 80 |
| 81 // IndexedDB is in the temp namespace for now. | 81 // IndexedDB is in the temp namespace for now. |
| 82 if (type != storage::kStorageTypeTemporary) { | 82 if (type != storage::kStorageTypeTemporary) { |
| 83 callback.Run(0); | 83 callback.Run(0); |
| 84 return; | 84 return; |
| 85 } | 85 } |
| 86 | 86 |
| 87 // No task runner means unit test; no cleanup necessary. | |
| 88 if (!indexed_db_context_->TaskRunner()) { | |
| 89 callback.Run(0); | |
| 90 return; | |
| 91 } | |
| 92 | |
| 93 base::PostTaskAndReplyWithResult( | 87 base::PostTaskAndReplyWithResult( |
| 94 indexed_db_context_->TaskRunner(), FROM_HERE, | 88 indexed_db_context_->TaskRunner(), FROM_HERE, |
| 95 base::Bind(&GetOriginUsageOnIndexedDBThread, | 89 base::Bind(&GetOriginUsageOnIndexedDBThread, |
| 96 base::RetainedRef(indexed_db_context_), origin_url), | 90 base::RetainedRef(indexed_db_context_), origin_url), |
| 97 callback); | 91 callback); |
| 98 } | 92 } |
| 99 | 93 |
| 100 void IndexedDBQuotaClient::GetOriginsForType( | 94 void IndexedDBQuotaClient::GetOriginsForType( |
| 101 storage::StorageType type, | 95 storage::StorageType type, |
| 102 const GetOriginsCallback& callback) { | 96 const GetOriginsCallback& callback) { |
| 103 DCHECK(!callback.is_null()); | 97 DCHECK(!callback.is_null()); |
| 104 DCHECK(indexed_db_context_.get()); | 98 DCHECK(indexed_db_context_.get()); |
| 105 | 99 |
| 106 // All databases are in the temp namespace for now. | 100 // All databases are in the temp namespace for now. |
| 107 if (type != storage::kStorageTypeTemporary) { | 101 if (type != storage::kStorageTypeTemporary) { |
| 108 callback.Run(std::set<GURL>()); | 102 callback.Run(std::set<GURL>()); |
| 109 return; | 103 return; |
| 110 } | 104 } |
| 111 | 105 |
| 112 // No task runner means unit test; no cleanup necessary. | |
| 113 if (!indexed_db_context_->TaskRunner()) { | |
| 114 callback.Run(std::set<GURL>()); | |
| 115 return; | |
| 116 } | |
| 117 | |
| 118 std::set<GURL>* origins_to_return = new std::set<GURL>(); | 106 std::set<GURL>* origins_to_return = new std::set<GURL>(); |
| 119 indexed_db_context_->TaskRunner()->PostTaskAndReply( | 107 indexed_db_context_->TaskRunner()->PostTaskAndReply( |
| 120 FROM_HERE, | 108 FROM_HERE, |
| 121 base::BindOnce(&GetAllOriginsOnIndexedDBThread, | 109 base::BindOnce(&GetAllOriginsOnIndexedDBThread, |
| 122 base::RetainedRef(indexed_db_context_), | 110 base::RetainedRef(indexed_db_context_), |
| 123 base::Unretained(origins_to_return)), | 111 base::Unretained(origins_to_return)), |
| 124 base::BindOnce(&DidGetOrigins, callback, base::Owned(origins_to_return))); | 112 base::BindOnce(&DidGetOrigins, callback, base::Owned(origins_to_return))); |
| 125 } | 113 } |
| 126 | 114 |
| 127 void IndexedDBQuotaClient::GetOriginsForHost( | 115 void IndexedDBQuotaClient::GetOriginsForHost( |
| 128 storage::StorageType type, | 116 storage::StorageType type, |
| 129 const std::string& host, | 117 const std::string& host, |
| 130 const GetOriginsCallback& callback) { | 118 const GetOriginsCallback& callback) { |
| 131 DCHECK(!callback.is_null()); | 119 DCHECK(!callback.is_null()); |
| 132 DCHECK(indexed_db_context_.get()); | 120 DCHECK(indexed_db_context_.get()); |
| 133 | 121 |
| 134 // All databases are in the temp namespace for now. | 122 // All databases are in the temp namespace for now. |
| 135 if (type != storage::kStorageTypeTemporary) { | 123 if (type != storage::kStorageTypeTemporary) { |
| 136 callback.Run(std::set<GURL>()); | 124 callback.Run(std::set<GURL>()); |
| 137 return; | 125 return; |
| 138 } | 126 } |
| 139 | 127 |
| 140 // No task runner means unit test; no cleanup necessary. | |
| 141 if (!indexed_db_context_->TaskRunner()) { | |
| 142 callback.Run(std::set<GURL>()); | |
| 143 return; | |
| 144 } | |
| 145 | |
| 146 std::set<GURL>* origins_to_return = new std::set<GURL>(); | 128 std::set<GURL>* origins_to_return = new std::set<GURL>(); |
| 147 indexed_db_context_->TaskRunner()->PostTaskAndReply( | 129 indexed_db_context_->TaskRunner()->PostTaskAndReply( |
| 148 FROM_HERE, | 130 FROM_HERE, |
| 149 base::BindOnce(&GetOriginsForHostOnIndexedDBThread, | 131 base::BindOnce(&GetOriginsForHostOnIndexedDBThread, |
| 150 base::RetainedRef(indexed_db_context_), host, | 132 base::RetainedRef(indexed_db_context_), host, |
| 151 base::Unretained(origins_to_return)), | 133 base::Unretained(origins_to_return)), |
| 152 base::BindOnce(&DidGetOrigins, callback, base::Owned(origins_to_return))); | 134 base::BindOnce(&DidGetOrigins, callback, base::Owned(origins_to_return))); |
| 153 } | 135 } |
| 154 | 136 |
| 155 void IndexedDBQuotaClient::DeleteOriginData(const GURL& origin, | 137 void IndexedDBQuotaClient::DeleteOriginData(const GURL& origin, |
| 156 storage::StorageType type, | 138 storage::StorageType type, |
| 157 const DeletionCallback& callback) { | 139 const DeletionCallback& callback) { |
| 158 if (type != storage::kStorageTypeTemporary) { | 140 if (type != storage::kStorageTypeTemporary) { |
| 159 callback.Run(storage::kQuotaErrorNotSupported); | 141 callback.Run(storage::kQuotaErrorNotSupported); |
| 160 return; | 142 return; |
| 161 } | 143 } |
| 162 | 144 |
| 163 // No task runner means unit test; no cleanup necessary. | |
| 164 if (!indexed_db_context_->TaskRunner()) { | |
| 165 callback.Run(storage::kQuotaStatusOk); | |
| 166 return; | |
| 167 } | |
| 168 | |
| 169 base::PostTaskAndReplyWithResult( | 145 base::PostTaskAndReplyWithResult( |
| 170 indexed_db_context_->TaskRunner(), FROM_HERE, | 146 indexed_db_context_->TaskRunner(), FROM_HERE, |
| 171 base::Bind(&DeleteOriginDataOnIndexedDBThread, | 147 base::Bind(&DeleteOriginDataOnIndexedDBThread, |
| 172 base::RetainedRef(indexed_db_context_), origin), | 148 base::RetainedRef(indexed_db_context_), origin), |
| 173 callback); | 149 callback); |
| 174 } | 150 } |
| 175 | 151 |
| 176 bool IndexedDBQuotaClient::DoesSupport(storage::StorageType type) const { | 152 bool IndexedDBQuotaClient::DoesSupport(storage::StorageType type) const { |
| 177 return type == storage::kStorageTypeTemporary; | 153 return type == storage::kStorageTypeTemporary; |
| 178 } | 154 } |
| 179 | 155 |
| 180 } // namespace content | 156 } // namespace content |
| OLD | NEW |