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

Side by Side Diff: webkit/appcache/appcache_storage_impl.cc

Issue 16155009: Update webkit/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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
« no previous file with comments | « webkit/appcache/appcache_storage.cc ('k') | webkit/appcache/appcache_storage_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "webkit/appcache/appcache_storage_impl.h" 5 #include "webkit/appcache/appcache_storage_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 sql::Connection* connection = database->db_connection(); 95 sql::Connection* connection = database->db_connection();
96 if (!connection) { 96 if (!connection) {
97 NOTREACHED() << "Missing database connection."; 97 NOTREACHED() << "Missing database connection.";
98 return; 98 return;
99 } 99 }
100 100
101 std::set<GURL>::const_iterator origin; 101 std::set<GURL>::const_iterator origin;
102 for (origin = origins.begin(); origin != origins.end(); ++origin) { 102 for (origin = origins.begin(); origin != origins.end(); ++origin) {
103 if (!special_storage_policy->IsStorageSessionOnly(*origin)) 103 if (!special_storage_policy->IsStorageSessionOnly(*origin))
104 continue; 104 continue;
105 if (special_storage_policy && 105 if (special_storage_policy.get() &&
106 special_storage_policy->IsStorageProtected(*origin)) 106 special_storage_policy->IsStorageProtected(*origin))
107 continue; 107 continue;
108 108
109 std::vector<AppCacheDatabase::GroupRecord> groups; 109 std::vector<AppCacheDatabase::GroupRecord> groups;
110 database->FindGroupsForOrigin(*origin, &groups); 110 database->FindGroupsForOrigin(*origin, &groups);
111 std::vector<AppCacheDatabase::GroupRecord>::const_iterator group; 111 std::vector<AppCacheDatabase::GroupRecord>::const_iterator group;
112 for (group = groups.begin(); group != groups.end(); ++group) { 112 for (group = groups.begin(); group != groups.end(); ++group) {
113 sql::Transaction transaction(connection); 113 sql::Transaction transaction(connection);
114 if (!transaction.Begin()) { 114 if (!transaction.Begin()) {
115 NOTREACHED() << "Failed to start transaction"; 115 NOTREACHED() << "Failed to start transaction";
(...skipping 12 matching lines...) Expand all
128 } // namespace 128 } // namespace
129 129
130 // DatabaseTask ----------------------------------------- 130 // DatabaseTask -----------------------------------------
131 131
132 class AppCacheStorageImpl::DatabaseTask 132 class AppCacheStorageImpl::DatabaseTask
133 : public base::RefCountedThreadSafe<DatabaseTask> { 133 : public base::RefCountedThreadSafe<DatabaseTask> {
134 public: 134 public:
135 explicit DatabaseTask(AppCacheStorageImpl* storage) 135 explicit DatabaseTask(AppCacheStorageImpl* storage)
136 : storage_(storage), database_(storage->database_), 136 : storage_(storage), database_(storage->database_),
137 io_thread_(base::MessageLoopProxy::current()) { 137 io_thread_(base::MessageLoopProxy::current()) {
138 DCHECK(io_thread_); 138 DCHECK(io_thread_.get());
139 } 139 }
140 140
141 void AddDelegate(DelegateReference* delegate_reference) { 141 void AddDelegate(DelegateReference* delegate_reference) {
142 delegates_.push_back(make_scoped_refptr(delegate_reference)); 142 delegates_.push_back(make_scoped_refptr(delegate_reference));
143 } 143 }
144 144
145 // Schedules a task to be Run() on the DB thread. Tasks 145 // Schedules a task to be Run() on the DB thread. Tasks
146 // are run in the order in which they are scheduled. 146 // are run in the order in which they are scheduled.
147 void Schedule(); 147 void Schedule();
148 148
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 info.cache_id = cache_record.cache_id; 362 info.cache_id = cache_record.cache_id;
363 info.group_id = group->group_id; 363 info.group_id = group->group_id;
364 info.is_complete = true; 364 info.is_complete = true;
365 infos.push_back(info); 365 infos.push_back(info);
366 } 366 }
367 } 367 }
368 } 368 }
369 369
370 void AppCacheStorageImpl::GetAllInfoTask::RunCompleted() { 370 void AppCacheStorageImpl::GetAllInfoTask::RunCompleted() {
371 DCHECK(delegates_.size() == 1); 371 DCHECK(delegates_.size() == 1);
372 FOR_EACH_DELEGATE(delegates_, OnAllInfo(info_collection_)); 372 FOR_EACH_DELEGATE(delegates_, OnAllInfo(info_collection_.get()));
373 } 373 }
374 374
375 // StoreOrLoadTask ------- 375 // StoreOrLoadTask -------
376 376
377 class AppCacheStorageImpl::StoreOrLoadTask : public DatabaseTask { 377 class AppCacheStorageImpl::StoreOrLoadTask : public DatabaseTask {
378 protected: 378 protected:
379 explicit StoreOrLoadTask(AppCacheStorageImpl* storage) 379 explicit StoreOrLoadTask(AppCacheStorageImpl* storage)
380 : DatabaseTask(storage) {} 380 : DatabaseTask(storage) {}
381 virtual ~StoreOrLoadTask() {} 381 virtual ~StoreOrLoadTask() {}
382 382
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 } 506 }
507 507
508 void AppCacheStorageImpl::CacheLoadTask::RunCompleted() { 508 void AppCacheStorageImpl::CacheLoadTask::RunCompleted() {
509 storage_->pending_cache_loads_.erase(cache_id_); 509 storage_->pending_cache_loads_.erase(cache_id_);
510 scoped_refptr<AppCache> cache; 510 scoped_refptr<AppCache> cache;
511 scoped_refptr<AppCacheGroup> group; 511 scoped_refptr<AppCacheGroup> group;
512 if (success_ && !storage_->is_disabled()) { 512 if (success_ && !storage_->is_disabled()) {
513 DCHECK(cache_record_.cache_id == cache_id_); 513 DCHECK(cache_record_.cache_id == cache_id_);
514 CreateCacheAndGroupFromRecords(&cache, &group); 514 CreateCacheAndGroupFromRecords(&cache, &group);
515 } 515 }
516 FOR_EACH_DELEGATE(delegates_, OnCacheLoaded(cache, cache_id_)); 516 FOR_EACH_DELEGATE(delegates_, OnCacheLoaded(cache.get(), cache_id_));
517 } 517 }
518 518
519 // GroupLoadTask ------- 519 // GroupLoadTask -------
520 520
521 class AppCacheStorageImpl::GroupLoadTask : public StoreOrLoadTask { 521 class AppCacheStorageImpl::GroupLoadTask : public StoreOrLoadTask {
522 public: 522 public:
523 GroupLoadTask(GURL manifest_url, AppCacheStorageImpl* storage) 523 GroupLoadTask(GURL manifest_url, AppCacheStorageImpl* storage)
524 : StoreOrLoadTask(storage), manifest_url_(manifest_url), 524 : StoreOrLoadTask(storage), manifest_url_(manifest_url),
525 success_(false) {} 525 success_(false) {}
526 526
(...skipping 23 matching lines...) Expand all
550 void AppCacheStorageImpl::GroupLoadTask::RunCompleted() { 550 void AppCacheStorageImpl::GroupLoadTask::RunCompleted() {
551 storage_->pending_group_loads_.erase(manifest_url_); 551 storage_->pending_group_loads_.erase(manifest_url_);
552 scoped_refptr<AppCacheGroup> group; 552 scoped_refptr<AppCacheGroup> group;
553 scoped_refptr<AppCache> cache; 553 scoped_refptr<AppCache> cache;
554 if (!storage_->is_disabled()) { 554 if (!storage_->is_disabled()) {
555 if (success_) { 555 if (success_) {
556 DCHECK(group_record_.manifest_url == manifest_url_); 556 DCHECK(group_record_.manifest_url == manifest_url_);
557 CreateCacheAndGroupFromRecords(&cache, &group); 557 CreateCacheAndGroupFromRecords(&cache, &group);
558 } else { 558 } else {
559 group = storage_->working_set_.GetGroup(manifest_url_); 559 group = storage_->working_set_.GetGroup(manifest_url_);
560 if (!group) { 560 if (!group.get()) {
561 group = new AppCacheGroup( 561 group =
562 storage_, manifest_url_, storage_->NewGroupId()); 562 new AppCacheGroup(storage_, manifest_url_, storage_->NewGroupId());
563 } 563 }
564 } 564 }
565 } 565 }
566 FOR_EACH_DELEGATE(delegates_, OnGroupLoaded(group, manifest_url_)); 566 FOR_EACH_DELEGATE(delegates_, OnGroupLoaded(group.get(), manifest_url_));
567 } 567 }
568 568
569 // StoreGroupAndCacheTask ------- 569 // StoreGroupAndCacheTask -------
570 570
571 class AppCacheStorageImpl::StoreGroupAndCacheTask : public StoreOrLoadTask { 571 class AppCacheStorageImpl::StoreGroupAndCacheTask : public StoreOrLoadTask {
572 public: 572 public:
573 StoreGroupAndCacheTask(AppCacheStorageImpl* storage, AppCacheGroup* group, 573 StoreGroupAndCacheTask(AppCacheStorageImpl* storage, AppCacheGroup* group,
574 AppCache* newest_cache); 574 AppCache* newest_cache);
575 575
576 void GetQuotaThenSchedule(); 576 void GetQuotaThenSchedule();
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 return; 745 return;
746 } 746 }
747 747
748 success_ = transaction.Commit(); 748 success_ = transaction.Commit();
749 } 749 }
750 750
751 void AppCacheStorageImpl::StoreGroupAndCacheTask::RunCompleted() { 751 void AppCacheStorageImpl::StoreGroupAndCacheTask::RunCompleted() {
752 if (success_) { 752 if (success_) {
753 storage_->UpdateUsageMapAndNotify( 753 storage_->UpdateUsageMapAndNotify(
754 group_->manifest_url().GetOrigin(), new_origin_usage_); 754 group_->manifest_url().GetOrigin(), new_origin_usage_);
755 if (cache_ != group_->newest_complete_cache()) { 755 if (cache_.get() != group_->newest_complete_cache()) {
756 cache_->set_complete(true); 756 cache_->set_complete(true);
757 group_->AddCache(cache_); 757 group_->AddCache(cache_.get());
758 } 758 }
759 if (group_->creation_time().is_null()) 759 if (group_->creation_time().is_null())
760 group_->set_creation_time(group_record_.creation_time); 760 group_->set_creation_time(group_record_.creation_time);
761 group_->AddNewlyDeletableResponseIds(&newly_deletable_response_ids_); 761 group_->AddNewlyDeletableResponseIds(&newly_deletable_response_ids_);
762 } 762 }
763 FOR_EACH_DELEGATE(delegates_, 763 FOR_EACH_DELEGATE(
764 OnGroupAndNewestCacheStored(group_, cache_, success_, 764 delegates_,
765 would_exceed_quota_)); 765 OnGroupAndNewestCacheStored(
766 group_.get(), cache_.get(), success_, would_exceed_quota_));
766 group_ = NULL; 767 group_ = NULL;
767 cache_ = NULL; 768 cache_ = NULL;
768 769
769 // TODO(michaeln): if (would_exceed_quota_) what if the current usage 770 // TODO(michaeln): if (would_exceed_quota_) what if the current usage
770 // also exceeds the quota? http://crbug.com/83968 771 // also exceeds the quota? http://crbug.com/83968
771 } 772 }
772 773
773 void AppCacheStorageImpl::StoreGroupAndCacheTask::CancelCompletion() { 774 void AppCacheStorageImpl::StoreGroupAndCacheTask::CancelCompletion() {
774 // Overriden to safely drop our reference to the group and cache 775 // Overriden to safely drop our reference to the group and cache
775 // which are not thread safe refcounted. 776 // which are not thread safe refcounted.
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
1163 void AppCacheStorageImpl::MakeGroupObsoleteTask::RunCompleted() { 1164 void AppCacheStorageImpl::MakeGroupObsoleteTask::RunCompleted() {
1164 if (success_) { 1165 if (success_) {
1165 group_->set_obsolete(true); 1166 group_->set_obsolete(true);
1166 if (!storage_->is_disabled()) { 1167 if (!storage_->is_disabled()) {
1167 storage_->UpdateUsageMapAndNotify(origin_, new_origin_usage_); 1168 storage_->UpdateUsageMapAndNotify(origin_, new_origin_usage_);
1168 group_->AddNewlyDeletableResponseIds(&newly_deletable_response_ids_); 1169 group_->AddNewlyDeletableResponseIds(&newly_deletable_response_ids_);
1169 1170
1170 // Also remove from the working set, caches for an 'obsolete' group 1171 // Also remove from the working set, caches for an 'obsolete' group
1171 // may linger in use, but the group itself cannot be looked up by 1172 // may linger in use, but the group itself cannot be looked up by
1172 // 'manifest_url' in the working set any longer. 1173 // 'manifest_url' in the working set any longer.
1173 storage_->working_set()->RemoveGroup(group_); 1174 storage_->working_set()->RemoveGroup(group_.get());
1174 } 1175 }
1175 } 1176 }
1176 FOR_EACH_DELEGATE(delegates_, OnGroupMadeObsolete(group_, success_)); 1177 FOR_EACH_DELEGATE(delegates_, OnGroupMadeObsolete(group_.get(), success_));
1177 group_ = NULL; 1178 group_ = NULL;
1178 } 1179 }
1179 1180
1180 void AppCacheStorageImpl::MakeGroupObsoleteTask::CancelCompletion() { 1181 void AppCacheStorageImpl::MakeGroupObsoleteTask::CancelCompletion() {
1181 // Overriden to safely drop our reference to the group 1182 // Overriden to safely drop our reference to the group
1182 // which is not thread safe refcounted. 1183 // which is not thread safe refcounted.
1183 DatabaseTask::CancelCompletion(); 1184 DatabaseTask::CancelCompletion();
1184 group_ = NULL; 1185 group_ = NULL;
1185 } 1186 }
1186 1187
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
1368 delegate->OnCacheLoaded(cache, id); 1369 delegate->OnCacheLoaded(cache, id);
1369 if (cache->owning_group()) { 1370 if (cache->owning_group()) {
1370 scoped_refptr<DatabaseTask> update_task( 1371 scoped_refptr<DatabaseTask> update_task(
1371 new UpdateGroupLastAccessTimeTask( 1372 new UpdateGroupLastAccessTimeTask(
1372 this, cache->owning_group(), base::Time::Now())); 1373 this, cache->owning_group(), base::Time::Now()));
1373 update_task->Schedule(); 1374 update_task->Schedule();
1374 } 1375 }
1375 return; 1376 return;
1376 } 1377 }
1377 scoped_refptr<CacheLoadTask> task(GetPendingCacheLoadTask(id)); 1378 scoped_refptr<CacheLoadTask> task(GetPendingCacheLoadTask(id));
1378 if (task) { 1379 if (task.get()) {
1379 task->AddDelegate(GetOrCreateDelegateReference(delegate)); 1380 task->AddDelegate(GetOrCreateDelegateReference(delegate));
1380 return; 1381 return;
1381 } 1382 }
1382 task = new CacheLoadTask(id, this); 1383 task = new CacheLoadTask(id, this);
1383 task->AddDelegate(GetOrCreateDelegateReference(delegate)); 1384 task->AddDelegate(GetOrCreateDelegateReference(delegate));
1384 task->Schedule(); 1385 task->Schedule();
1385 pending_cache_loads_[id] = task; 1386 pending_cache_loads_[id] = task.get();
1386 } 1387 }
1387 1388
1388 void AppCacheStorageImpl::LoadOrCreateGroup( 1389 void AppCacheStorageImpl::LoadOrCreateGroup(
1389 const GURL& manifest_url, Delegate* delegate) { 1390 const GURL& manifest_url, Delegate* delegate) {
1390 DCHECK(delegate); 1391 DCHECK(delegate);
1391 if (is_disabled_) { 1392 if (is_disabled_) {
1392 delegate->OnGroupLoaded(NULL, manifest_url); 1393 delegate->OnGroupLoaded(NULL, manifest_url);
1393 return; 1394 return;
1394 } 1395 }
1395 1396
1396 AppCacheGroup* group = working_set_.GetGroup(manifest_url); 1397 AppCacheGroup* group = working_set_.GetGroup(manifest_url);
1397 if (group) { 1398 if (group) {
1398 delegate->OnGroupLoaded(group, manifest_url); 1399 delegate->OnGroupLoaded(group, manifest_url);
1399 scoped_refptr<DatabaseTask> update_task( 1400 scoped_refptr<DatabaseTask> update_task(
1400 new UpdateGroupLastAccessTimeTask( 1401 new UpdateGroupLastAccessTimeTask(
1401 this, group, base::Time::Now())); 1402 this, group, base::Time::Now()));
1402 update_task->Schedule(); 1403 update_task->Schedule();
1403 return; 1404 return;
1404 } 1405 }
1405 1406
1406 scoped_refptr<GroupLoadTask> task(GetPendingGroupLoadTask(manifest_url)); 1407 scoped_refptr<GroupLoadTask> task(GetPendingGroupLoadTask(manifest_url));
1407 if (task) { 1408 if (task.get()) {
1408 task->AddDelegate(GetOrCreateDelegateReference(delegate)); 1409 task->AddDelegate(GetOrCreateDelegateReference(delegate));
1409 return; 1410 return;
1410 } 1411 }
1411 1412
1412 if (usage_map_.find(manifest_url.GetOrigin()) == usage_map_.end()) { 1413 if (usage_map_.find(manifest_url.GetOrigin()) == usage_map_.end()) {
1413 // No need to query the database, return a new group immediately. 1414 // No need to query the database, return a new group immediately.
1414 scoped_refptr<AppCacheGroup> group(new AppCacheGroup( 1415 scoped_refptr<AppCacheGroup> group(new AppCacheGroup(
1415 service_->storage(), manifest_url, NewGroupId())); 1416 service_->storage(), manifest_url, NewGroupId()));
1416 delegate->OnGroupLoaded(group, manifest_url); 1417 delegate->OnGroupLoaded(group.get(), manifest_url);
1417 return; 1418 return;
1418 } 1419 }
1419 1420
1420 task = new GroupLoadTask(manifest_url, this); 1421 task = new GroupLoadTask(manifest_url, this);
1421 task->AddDelegate(GetOrCreateDelegateReference(delegate)); 1422 task->AddDelegate(GetOrCreateDelegateReference(delegate));
1422 task->Schedule(); 1423 task->Schedule();
1423 pending_group_loads_[manifest_url] = task.get(); 1424 pending_group_loads_[manifest_url] = task.get();
1424 } 1425 }
1425 1426
1426 void AppCacheStorageImpl::StoreGroupAndNewestCache( 1427 void AppCacheStorageImpl::StoreGroupAndNewestCache(
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
1773 int rv = net::OK; 1774 int rv = net::OK;
1774 disk_cache_.reset(new AppCacheDiskCache); 1775 disk_cache_.reset(new AppCacheDiskCache);
1775 if (is_incognito_) { 1776 if (is_incognito_) {
1776 rv = disk_cache_->InitWithMemBackend( 1777 rv = disk_cache_->InitWithMemBackend(
1777 kMaxMemDiskCacheSize, 1778 kMaxMemDiskCacheSize,
1778 base::Bind(&AppCacheStorageImpl::OnDiskCacheInitialized, 1779 base::Bind(&AppCacheStorageImpl::OnDiskCacheInitialized,
1779 base::Unretained(this))); 1780 base::Unretained(this)));
1780 } else { 1781 } else {
1781 rv = disk_cache_->InitWithDiskBackend( 1782 rv = disk_cache_->InitWithDiskBackend(
1782 cache_directory_.Append(kDiskCacheDirectoryName), 1783 cache_directory_.Append(kDiskCacheDirectoryName),
1783 kMaxDiskCacheSize, false, cache_thread_, 1784 kMaxDiskCacheSize,
1785 false,
1786 cache_thread_.get(),
1784 base::Bind(&AppCacheStorageImpl::OnDiskCacheInitialized, 1787 base::Bind(&AppCacheStorageImpl::OnDiskCacheInitialized,
1785 base::Unretained(this))); 1788 base::Unretained(this)));
1786 } 1789 }
1787 1790
1788 // We should not keep this reference around. 1791 // We should not keep this reference around.
1789 cache_thread_ = NULL; 1792 cache_thread_ = NULL;
1790 1793
1791 if (rv != net::ERR_IO_PENDING) 1794 if (rv != net::ERR_IO_PENDING)
1792 OnDiskCacheInitialized(rv); 1795 OnDiskCacheInitialized(rv);
1793 } 1796 }
(...skipping 13 matching lines...) Expand all
1807 if (!is_incognito_) { 1810 if (!is_incognito_) {
1808 VLOG(1) << "Deleting existing appcache data and starting over."; 1811 VLOG(1) << "Deleting existing appcache data and starting over.";
1809 db_thread_->PostTask( 1812 db_thread_->PostTask(
1810 FROM_HERE, base::Bind(base::IgnoreResult(&file_util::Delete), 1813 FROM_HERE, base::Bind(base::IgnoreResult(&file_util::Delete),
1811 cache_directory_, true)); 1814 cache_directory_, true));
1812 } 1815 }
1813 } 1816 }
1814 } 1817 }
1815 1818
1816 } // namespace appcache 1819 } // namespace appcache
OLDNEW
« no previous file with comments | « webkit/appcache/appcache_storage.cc ('k') | webkit/appcache/appcache_storage_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698