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 "content/browser/appcache/appcache_storage.h" | 5 #include "content/browser/appcache/appcache_storage.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/stl_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "content/browser/appcache/appcache_response.h" | 10 #include "content/browser/appcache/appcache_response.h" |
11 #include "content/browser/appcache/appcache_service_impl.h" | 11 #include "content/browser/appcache/appcache_service_impl.h" |
12 #include "storage/browser/quota/quota_client.h" | 12 #include "storage/browser/quota/quota_client.h" |
13 #include "storage/browser/quota/quota_manager_proxy.h" | 13 #include "storage/browser/quota/quota_manager_proxy.h" |
14 | 14 |
15 namespace content { | 15 namespace content { |
16 | 16 |
17 // static | 17 // static |
18 const int64_t AppCacheStorage::kUnitializedId = -1; | 18 const int64_t AppCacheStorage::kUnitializedId = -1; |
19 | 19 |
20 AppCacheStorage::AppCacheStorage(AppCacheServiceImpl* service) | 20 AppCacheStorage::AppCacheStorage(AppCacheServiceImpl* service) |
21 : last_cache_id_(kUnitializedId), last_group_id_(kUnitializedId), | 21 : last_cache_id_(kUnitializedId), last_group_id_(kUnitializedId), |
22 last_response_id_(kUnitializedId), service_(service) { | 22 last_response_id_(kUnitializedId), service_(service) { |
23 } | 23 } |
24 | 24 |
25 AppCacheStorage::~AppCacheStorage() { | 25 AppCacheStorage::~AppCacheStorage() { |
26 base::STLDeleteValues(&pending_info_loads_); | |
27 DCHECK(delegate_references_.empty()); | 26 DCHECK(delegate_references_.empty()); |
28 } | 27 } |
29 | 28 |
30 AppCacheStorage::DelegateReference::DelegateReference( | 29 AppCacheStorage::DelegateReference::DelegateReference( |
31 Delegate* delegate, AppCacheStorage* storage) | 30 Delegate* delegate, AppCacheStorage* storage) |
32 : delegate(delegate), storage(storage) { | 31 : delegate(delegate), storage(storage) { |
33 storage->delegate_references_.insert( | 32 storage->delegate_references_.insert( |
34 DelegateReferenceMap::value_type(delegate, this)); | 33 DelegateReferenceMap::value_type(delegate, this)); |
35 } | 34 } |
36 | 35 |
37 AppCacheStorage::DelegateReference::~DelegateReference() { | 36 AppCacheStorage::DelegateReference::~DelegateReference() { |
38 if (delegate) | 37 if (delegate) |
39 storage->delegate_references_.erase(delegate); | 38 storage->delegate_references_.erase(delegate); |
40 } | 39 } |
41 | 40 |
42 AppCacheStorage::ResponseInfoLoadTask::ResponseInfoLoadTask( | 41 AppCacheStorage::ResponseInfoLoadTask::ResponseInfoLoadTask( |
43 const GURL& manifest_url, | 42 const GURL& manifest_url, |
44 int64_t response_id, | 43 int64_t response_id, |
45 AppCacheStorage* storage) | 44 AppCacheStorage* storage) |
46 : storage_(storage), | 45 : storage_(storage), |
47 manifest_url_(manifest_url), | 46 manifest_url_(manifest_url), |
48 response_id_(response_id), | 47 response_id_(response_id), |
49 info_buffer_(new HttpResponseInfoIOBuffer) { | 48 info_buffer_(new HttpResponseInfoIOBuffer) { |
50 storage_->pending_info_loads_.insert( | 49 storage_->pending_info_loads_.insert(PendingResponseInfoLoads::value_type( |
ncarter (slow)
2016/08/15 21:51:33
Does map::emplace(key, value) work here (letting y
Avi (use Gerrit)
2016/08/15 23:46:49
Nice, and it lets me drop the typedef.
Avi (use Gerrit)
2016/08/16 14:59:02
No, unfortunately map::emplace doesn't exist on th
ncarter (slow)
2016/08/16 18:41:19
Sorry for the wild goose chase, then. At least we
| |
51 PendingResponseInfoLoads::value_type(response_id, this)); | 50 response_id, base::WrapUnique(this))); |
52 } | 51 } |
53 | 52 |
54 AppCacheStorage::ResponseInfoLoadTask::~ResponseInfoLoadTask() { | 53 AppCacheStorage::ResponseInfoLoadTask::~ResponseInfoLoadTask() { |
55 } | 54 } |
56 | 55 |
57 void AppCacheStorage::ResponseInfoLoadTask::StartIfNeeded() { | 56 void AppCacheStorage::ResponseInfoLoadTask::StartIfNeeded() { |
58 if (reader_) | 57 if (reader_) |
59 return; | 58 return; |
60 reader_.reset(storage_->CreateResponseReader(manifest_url_, response_id_)); | 59 reader_.reset(storage_->CreateResponseReader(manifest_url_, response_id_)); |
61 reader_->ReadInfo(info_buffer_.get(), | 60 reader_->ReadInfo(info_buffer_.get(), |
62 base::Bind(&ResponseInfoLoadTask::OnReadComplete, | 61 base::Bind(&ResponseInfoLoadTask::OnReadComplete, |
63 base::Unretained(this))); | 62 base::Unretained(this))); |
64 } | 63 } |
65 | 64 |
66 void AppCacheStorage::ResponseInfoLoadTask::OnReadComplete(int result) { | 65 void AppCacheStorage::ResponseInfoLoadTask::OnReadComplete(int result) { |
66 std::unique_ptr<ResponseInfoLoadTask> this_wrapper( | |
67 std::move(storage_->pending_info_loads_[response_id_])); | |
67 storage_->pending_info_loads_.erase(response_id_); | 68 storage_->pending_info_loads_.erase(response_id_); |
69 | |
68 scoped_refptr<AppCacheResponseInfo> info; | 70 scoped_refptr<AppCacheResponseInfo> info; |
69 if (result >= 0) { | 71 if (result >= 0) { |
70 info = new AppCacheResponseInfo(storage_, manifest_url_, | 72 info = new AppCacheResponseInfo(storage_, manifest_url_, |
71 response_id_, | 73 response_id_, |
72 info_buffer_->http_info.release(), | 74 info_buffer_->http_info.release(), |
73 info_buffer_->response_data_size); | 75 info_buffer_->response_data_size); |
74 } | 76 } |
75 FOR_EACH_DELEGATE(delegates_, OnResponseInfoLoaded(info.get(), response_id_)); | 77 FOR_EACH_DELEGATE(delegates_, OnResponseInfoLoaded(info.get(), response_id_)); |
76 delete this; | 78 |
79 // returning deletes this | |
77 } | 80 } |
78 | 81 |
79 void AppCacheStorage::LoadResponseInfo(const GURL& manifest_url, | 82 void AppCacheStorage::LoadResponseInfo(const GURL& manifest_url, |
80 int64_t id, | 83 int64_t id, |
81 Delegate* delegate) { | 84 Delegate* delegate) { |
82 AppCacheResponseInfo* info = working_set_.GetResponseInfo(id); | 85 AppCacheResponseInfo* info = working_set_.GetResponseInfo(id); |
83 if (info) { | 86 if (info) { |
84 delegate->OnResponseInfoLoaded(info, id); | 87 delegate->OnResponseInfoLoaded(info, id); |
85 return; | 88 return; |
86 } | 89 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 if (service()->quota_manager_proxy() && | 130 if (service()->quota_manager_proxy() && |
128 usage_map_.find(origin) != usage_map_.end()) | 131 usage_map_.find(origin) != usage_map_.end()) |
129 service()->quota_manager_proxy()->NotifyStorageAccessed( | 132 service()->quota_manager_proxy()->NotifyStorageAccessed( |
130 storage::QuotaClient::kAppcache, | 133 storage::QuotaClient::kAppcache, |
131 origin, | 134 origin, |
132 storage::kStorageTypeTemporary); | 135 storage::kStorageTypeTemporary); |
133 } | 136 } |
134 | 137 |
135 } // namespace content | 138 } // namespace content |
136 | 139 |
OLD | NEW |