| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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.h" | 5 #include "webkit/appcache/appcache_storage.h" |
| 6 | 6 |
| 7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
| 8 #include "webkit/appcache/appcache_response.h" | 8 #include "webkit/appcache/appcache_response.h" |
| 9 #include "webkit/appcache/appcache_service.h" | 9 #include "webkit/appcache/appcache_service.h" |
| 10 #include "webkit/quota/quota_client.h" | 10 #include "webkit/quota/quota_client.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 DelegateReferenceMap::value_type(delegate, this)); | 32 DelegateReferenceMap::value_type(delegate, this)); |
| 33 } | 33 } |
| 34 | 34 |
| 35 AppCacheStorage::DelegateReference::~DelegateReference() { | 35 AppCacheStorage::DelegateReference::~DelegateReference() { |
| 36 if (delegate) | 36 if (delegate) |
| 37 storage->delegate_references_.erase(delegate); | 37 storage->delegate_references_.erase(delegate); |
| 38 } | 38 } |
| 39 | 39 |
| 40 AppCacheStorage::ResponseInfoLoadTask::ResponseInfoLoadTask( | 40 AppCacheStorage::ResponseInfoLoadTask::ResponseInfoLoadTask( |
| 41 const GURL& manifest_url, | 41 const GURL& manifest_url, |
| 42 int64 group_id, |
| 42 int64 response_id, | 43 int64 response_id, |
| 43 AppCacheStorage* storage) | 44 AppCacheStorage* storage) |
| 44 : storage_(storage), | 45 : storage_(storage), |
| 45 manifest_url_(manifest_url), | 46 manifest_url_(manifest_url), |
| 47 group_id_(group_id), |
| 46 response_id_(response_id), | 48 response_id_(response_id), |
| 47 info_buffer_(new HttpResponseInfoIOBuffer), | 49 info_buffer_(new HttpResponseInfoIOBuffer), |
| 48 ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_( | 50 ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_( |
| 49 this, &ResponseInfoLoadTask::OnReadComplete)) { | 51 this, &ResponseInfoLoadTask::OnReadComplete)) { |
| 50 storage_->pending_info_loads_.insert( | 52 storage_->pending_info_loads_.insert( |
| 51 PendingResponseInfoLoads::value_type(response_id, this)); | 53 PendingResponseInfoLoads::value_type(response_id, this)); |
| 52 } | 54 } |
| 53 | 55 |
| 54 AppCacheStorage::ResponseInfoLoadTask::~ResponseInfoLoadTask() { | 56 AppCacheStorage::ResponseInfoLoadTask::~ResponseInfoLoadTask() { |
| 55 } | 57 } |
| 56 | 58 |
| 57 void AppCacheStorage::ResponseInfoLoadTask::StartIfNeeded() { | 59 void AppCacheStorage::ResponseInfoLoadTask::StartIfNeeded() { |
| 58 if (reader_.get()) | 60 if (reader_.get()) |
| 59 return; | 61 return; |
| 60 reader_.reset( | 62 reader_.reset( |
| 61 storage_->CreateResponseReader(manifest_url_, response_id_)); | 63 storage_->CreateResponseReader(manifest_url_, group_id_, response_id_)); |
| 62 reader_->ReadInfo(info_buffer_, &read_callback_); | 64 reader_->ReadInfo(info_buffer_, &read_callback_); |
| 63 } | 65 } |
| 64 | 66 |
| 65 void AppCacheStorage::ResponseInfoLoadTask::OnReadComplete(int result) { | 67 void AppCacheStorage::ResponseInfoLoadTask::OnReadComplete(int result) { |
| 66 storage_->pending_info_loads_.erase(response_id_); | 68 storage_->pending_info_loads_.erase(response_id_); |
| 67 scoped_refptr<AppCacheResponseInfo> info; | 69 scoped_refptr<AppCacheResponseInfo> info; |
| 68 if (result >= 0) { | 70 if (result >= 0) { |
| 69 info = new AppCacheResponseInfo(storage_->service(), manifest_url_, | 71 info = new AppCacheResponseInfo(storage_->service(), manifest_url_, |
| 70 response_id_, | 72 response_id_, |
| 71 info_buffer_->http_info.release(), | 73 info_buffer_->http_info.release(), |
| 72 info_buffer_->response_data_size); | 74 info_buffer_->response_data_size); |
| 73 } | 75 } |
| 74 FOR_EACH_DELEGATE(delegates_, OnResponseInfoLoaded(info.get(), response_id_)); | 76 FOR_EACH_DELEGATE(delegates_, OnResponseInfoLoaded(info.get(), response_id_)); |
| 75 delete this; | 77 delete this; |
| 76 } | 78 } |
| 77 | 79 |
| 78 void AppCacheStorage::LoadResponseInfo( | 80 void AppCacheStorage::LoadResponseInfo( |
| 79 const GURL& manifest_url, int64 id, Delegate* delegate) { | 81 const GURL& manifest_url, int64 group_id, int64 id, Delegate* delegate) { |
| 80 AppCacheResponseInfo* info = working_set_.GetResponseInfo(id); | 82 AppCacheResponseInfo* info = working_set_.GetResponseInfo(id); |
| 81 if (info) { | 83 if (info) { |
| 82 delegate->OnResponseInfoLoaded(info, id); | 84 delegate->OnResponseInfoLoaded(info, id); |
| 83 return; | 85 return; |
| 84 } | 86 } |
| 85 ResponseInfoLoadTask* info_load = | 87 ResponseInfoLoadTask* info_load = |
| 86 GetOrCreateResponseInfoLoadTask(manifest_url, id); | 88 GetOrCreateResponseInfoLoadTask(manifest_url, group_id, id); |
| 87 DCHECK(manifest_url == info_load->manifest_url()); | 89 DCHECK(manifest_url == info_load->manifest_url()); |
| 90 DCHECK(group_id == info_load->group_id()); |
| 88 DCHECK(id == info_load->response_id()); | 91 DCHECK(id == info_load->response_id()); |
| 89 info_load->AddDelegate(GetOrCreateDelegateReference(delegate)); | 92 info_load->AddDelegate(GetOrCreateDelegateReference(delegate)); |
| 90 info_load->StartIfNeeded(); | 93 info_load->StartIfNeeded(); |
| 91 } | 94 } |
| 92 | 95 |
| 93 void AppCacheStorage::UpdateUsageMapAndNotify( | 96 void AppCacheStorage::UpdateUsageMapAndNotify( |
| 94 const GURL& origin, int64 new_usage) { | 97 const GURL& origin, int64 new_usage) { |
| 95 DCHECK_GE(new_usage, 0); | 98 DCHECK_GE(new_usage, 0); |
| 96 int64 old_usage = usage_map_[origin]; | 99 int64 old_usage = usage_map_[origin]; |
| 97 if (new_usage > 0) | 100 if (new_usage > 0) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 122 void AppCacheStorage::NotifyStorageAccessed(const GURL& origin) { | 125 void AppCacheStorage::NotifyStorageAccessed(const GURL& origin) { |
| 123 if (service()->quota_manager_proxy() && | 126 if (service()->quota_manager_proxy() && |
| 124 usage_map_.find(origin) != usage_map_.end()) | 127 usage_map_.find(origin) != usage_map_.end()) |
| 125 service()->quota_manager_proxy()->NotifyStorageAccessed( | 128 service()->quota_manager_proxy()->NotifyStorageAccessed( |
| 126 quota::QuotaClient::kAppcache, | 129 quota::QuotaClient::kAppcache, |
| 127 origin, quota::kStorageTypeTemporary); | 130 origin, quota::kStorageTypeTemporary); |
| 128 } | 131 } |
| 129 | 132 |
| 130 } // namespace appcache | 133 } // namespace appcache |
| 131 | 134 |
| OLD | NEW |