Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(236)

Side by Side Diff: content/browser/indexed_db/indexed_db_context_impl.cc

Issue 18147009: IndexedDB: Remove unnecessary scoped_refptr<T>::get() calls (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: clang-format Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_context_impl.h" 5 #include "content/browser/indexed_db/indexed_db_context_impl.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 if (!data_path.empty()) 101 if (!data_path.empty())
102 data_path_ = data_path.Append(kIndexedDBDirectory); 102 data_path_ = data_path.Append(kIndexedDBDirectory);
103 if (quota_manager_proxy && 103 if (quota_manager_proxy &&
104 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) { 104 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) {
105 quota_manager_proxy->RegisterClient(new IndexedDBQuotaClient(this)); 105 quota_manager_proxy->RegisterClient(new IndexedDBQuotaClient(this));
106 } 106 }
107 } 107 }
108 108
109 IndexedDBFactory* IndexedDBContextImpl::GetIDBFactory() { 109 IndexedDBFactory* IndexedDBContextImpl::GetIDBFactory() {
110 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); 110 DCHECK(TaskRunner()->RunsTasksOnCurrentThread());
111 if (!idb_factory_.get()) { 111 if (!idb_factory_) {
112 // Prime our cache of origins with existing databases so we can 112 // Prime our cache of origins with existing databases so we can
113 // detect when dbs are newly created. 113 // detect when dbs are newly created.
114 GetOriginSet(); 114 GetOriginSet();
115 idb_factory_ = IndexedDBFactory::Create(); 115 idb_factory_ = IndexedDBFactory::Create();
116 } 116 }
117 return idb_factory_.get(); 117 return idb_factory_;
118 } 118 }
119 119
120 std::vector<GURL> IndexedDBContextImpl::GetAllOrigins() { 120 std::vector<GURL> IndexedDBContextImpl::GetAllOrigins() {
121 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); 121 DCHECK(TaskRunner()->RunsTasksOnCurrentThread());
122 std::vector<GURL> origins; 122 std::vector<GURL> origins;
123 std::set<GURL>* origins_set = GetOriginSet(); 123 std::set<GURL>* origins_set = GetOriginSet();
124 for (std::set<GURL>::const_iterator iter = origins_set->begin(); 124 for (std::set<GURL>::const_iterator iter = origins_set->begin();
125 iter != origins_set->end(); 125 iter != origins_set->end();
126 ++iter) { 126 ++iter) {
127 origins.push_back(*iter); 127 origins.push_back(*iter);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 IndexedDBConnection* connection = *it; 198 IndexedDBConnection* connection = *it;
199 connections.erase(it++); 199 connections.erase(it++);
200 connection->ForceClose(); 200 connection->ForceClose();
201 } 201 }
202 DCHECK_EQ(connections_[origin_url].size(), 0UL); 202 DCHECK_EQ(connections_[origin_url].size(), 0UL);
203 connections_.erase(origin_url); 203 connections_.erase(origin_url);
204 } 204 }
205 } 205 }
206 206
207 base::FilePath IndexedDBContextImpl::GetFilePath(const GURL& origin_url) { 207 base::FilePath IndexedDBContextImpl::GetFilePath(const GURL& origin_url) {
208 std::string origin_id = 208 std::string origin_id = webkit_database::GetIdentifierFromOrigin(origin_url);
209 webkit_database::GetIdentifierFromOrigin(origin_url);
210 return GetIndexedDBFilePath(origin_id); 209 return GetIndexedDBFilePath(origin_id);
211 } 210 }
212 211
213 base::FilePath IndexedDBContextImpl::GetFilePathForTesting( 212 base::FilePath IndexedDBContextImpl::GetFilePathForTesting(
214 const std::string& origin_id) const { 213 const std::string& origin_id) const {
215 return GetIndexedDBFilePath(origin_id); 214 return GetIndexedDBFilePath(origin_id);
216 } 215 }
217 216
218 void IndexedDBContextImpl::SetTaskRunnerForTesting( 217 void IndexedDBContextImpl::SetTaskRunnerForTesting(
219 base::SequencedTaskRunner* task_runner) { 218 base::SequencedTaskRunner* task_runner) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 bool over_quota = additional_bytes > space_available_map_[origin_url]; 276 bool over_quota = additional_bytes > space_available_map_[origin_url];
278 return over_quota; 277 return over_quota;
279 } 278 }
280 279
281 bool IndexedDBContextImpl::IsOverQuota(const GURL& origin_url) { 280 bool IndexedDBContextImpl::IsOverQuota(const GURL& origin_url) {
282 const int kOneAdditionalByte = 1; 281 const int kOneAdditionalByte = 1;
283 return WouldBeOverQuota(origin_url, kOneAdditionalByte); 282 return WouldBeOverQuota(origin_url, kOneAdditionalByte);
284 } 283 }
285 284
286 quota::QuotaManagerProxy* IndexedDBContextImpl::quota_manager_proxy() { 285 quota::QuotaManagerProxy* IndexedDBContextImpl::quota_manager_proxy() {
287 return quota_manager_proxy_.get(); 286 return quota_manager_proxy_;
288 } 287 }
289 288
290 IndexedDBContextImpl::~IndexedDBContextImpl() { 289 IndexedDBContextImpl::~IndexedDBContextImpl() {
291 if (idb_factory_.get()) { 290 if (idb_factory_) {
292 IndexedDBFactory* factory = idb_factory_.get(); 291 IndexedDBFactory* factory = idb_factory_;
293 factory->AddRef(); 292 factory->AddRef();
294 idb_factory_ = NULL; 293 idb_factory_ = NULL;
295 if (!task_runner_->ReleaseSoon(FROM_HERE, factory)) { 294 if (!task_runner_->ReleaseSoon(FROM_HERE, factory)) {
296 factory->Release(); 295 factory->Release();
297 } 296 }
298 } 297 }
299 298
300 if (data_path_.empty()) 299 if (data_path_.empty())
301 return; 300 return;
302 301
303 if (force_keep_session_state_) 302 if (force_keep_session_state_)
304 return; 303 return;
305 304
306 bool has_session_only_databases = 305 bool has_session_only_databases =
307 special_storage_policy_.get() && 306 special_storage_policy_ &&
308 special_storage_policy_->HasSessionOnlyOrigins(); 307 special_storage_policy_->HasSessionOnlyOrigins();
309 308
310 // Clearning only session-only databases, and there are none. 309 // Clearning only session-only databases, and there are none.
311 if (!has_session_only_databases) 310 if (!has_session_only_databases)
312 return; 311 return;
313 312
314 TaskRunner()->PostTask( 313 TaskRunner()->PostTask(
315 FROM_HERE, 314 FROM_HERE,
316 base::Bind( 315 base::Bind(
317 &ClearSessionOnlyOrigins, data_path_, special_storage_policy_)); 316 &ClearSessionOnlyOrigins, data_path_, special_storage_policy_));
318 } 317 }
319 318
320 base::FilePath IndexedDBContextImpl::GetIndexedDBFilePath( 319 base::FilePath IndexedDBContextImpl::GetIndexedDBFilePath(
321 const std::string& origin_id) const { 320 const std::string& origin_id) const {
322 DCHECK(!data_path_.empty()); 321 DCHECK(!data_path_.empty());
323 return data_path_.AppendASCII(origin_id). 322 return data_path_.AppendASCII(origin_id).AddExtension(kIndexedDBExtension)
324 AddExtension(kIndexedDBExtension). 323 .AddExtension(kLevelDBExtension);
325 AddExtension(kLevelDBExtension);
326 } 324 }
327 325
328 int64 IndexedDBContextImpl::ReadUsageFromDisk(const GURL& origin_url) const { 326 int64 IndexedDBContextImpl::ReadUsageFromDisk(const GURL& origin_url) const {
329 if (data_path_.empty()) 327 if (data_path_.empty())
330 return 0; 328 return 0;
331 std::string origin_id = 329 std::string origin_id = webkit_database::GetIdentifierFromOrigin(origin_url);
332 webkit_database::GetIdentifierFromOrigin(origin_url);
333 base::FilePath file_path = GetIndexedDBFilePath(origin_id); 330 base::FilePath file_path = GetIndexedDBFilePath(origin_id);
334 return base::ComputeDirectorySize(file_path); 331 return base::ComputeDirectorySize(file_path);
335 } 332 }
336 333
337 void IndexedDBContextImpl::EnsureDiskUsageCacheInitialized( 334 void IndexedDBContextImpl::EnsureDiskUsageCacheInitialized(
338 const GURL& origin_url) { 335 const GURL& origin_url) {
339 if (origin_size_map_.find(origin_url) == origin_size_map_.end()) 336 if (origin_size_map_.find(origin_url) == origin_size_map_.end())
340 origin_size_map_[origin_url] = ReadUsageFromDisk(origin_url); 337 origin_size_map_[origin_url] = ReadUsageFromDisk(origin_url);
341 } 338 }
342 339
(...skipping 19 matching lines...) Expand all
362 quota::QuotaStatusCode status, 359 quota::QuotaStatusCode status,
363 int64 usage, 360 int64 usage,
364 int64 quota) { 361 int64 quota) {
365 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 362 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
366 DCHECK(status == quota::kQuotaStatusOk || status == quota::kQuotaErrorAbort) 363 DCHECK(status == quota::kQuotaStatusOk || status == quota::kQuotaErrorAbort)
367 << "status was " << status; 364 << "status was " << status;
368 if (status == quota::kQuotaErrorAbort) { 365 if (status == quota::kQuotaErrorAbort) {
369 // We seem to no longer care to wait around for the answer. 366 // We seem to no longer care to wait around for the answer.
370 return; 367 return;
371 } 368 }
372 TaskRunner()->PostTask( 369 TaskRunner()->PostTask(FROM_HERE,
373 FROM_HERE, 370 base::Bind(&IndexedDBContextImpl::GotUpdatedQuota,
374 base::Bind(&IndexedDBContextImpl::GotUpdatedQuota, 371 this,
375 this, 372 origin_url,
376 origin_url, 373 usage,
377 usage, 374 quota));
378 quota));
379 } 375 }
380 376
381 void IndexedDBContextImpl::GotUpdatedQuota(const GURL& origin_url, 377 void IndexedDBContextImpl::GotUpdatedQuota(const GURL& origin_url,
382 int64 usage, 378 int64 usage,
383 int64 quota) { 379 int64 quota) {
384 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); 380 DCHECK(TaskRunner()->RunsTasksOnCurrentThread());
385 space_available_map_[origin_url] = quota - usage; 381 space_available_map_[origin_url] = quota - usage;
386 } 382 }
387 383
388 void IndexedDBContextImpl::QueryAvailableQuota(const GURL& origin_url) { 384 void IndexedDBContextImpl::QueryAvailableQuota(const GURL& origin_url) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 origin_set_.reset(); 420 origin_set_.reset();
425 origin_size_map_.clear(); 421 origin_size_map_.clear();
426 space_available_map_.clear(); 422 space_available_map_.clear();
427 } 423 }
428 424
429 base::TaskRunner* IndexedDBContextImpl::TaskRunner() const { 425 base::TaskRunner* IndexedDBContextImpl::TaskRunner() const {
430 return task_runner_; 426 return task_runner_;
431 } 427 }
432 428
433 } // namespace content 429 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_browsertest.cc ('k') | content/browser/indexed_db/indexed_db_database.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698