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

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

Issue 8215002: base::Bind: Cleanup in test_shell. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fix. Created 9 years, 2 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_host.h ('k') | webkit/appcache/appcache_host_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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_host.h" 5 #include "webkit/appcache/appcache_host.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "webkit/appcache/appcache.h" 10 #include "webkit/appcache/appcache.h"
(...skipping 23 matching lines...) Expand all
34 } // Anonymous namespace 34 } // Anonymous namespace
35 35
36 AppCacheHost::AppCacheHost(int host_id, AppCacheFrontend* frontend, 36 AppCacheHost::AppCacheHost(int host_id, AppCacheFrontend* frontend,
37 AppCacheService* service) 37 AppCacheService* service)
38 : host_id_(host_id), 38 : host_id_(host_id),
39 spawning_host_id_(kNoHostId), spawning_process_id_(0), 39 spawning_host_id_(kNoHostId), spawning_process_id_(0),
40 parent_host_id_(kNoHostId), parent_process_id_(0), 40 parent_host_id_(kNoHostId), parent_process_id_(0),
41 pending_main_resource_cache_id_(kNoCacheId), 41 pending_main_resource_cache_id_(kNoCacheId),
42 pending_selected_cache_id_(kNoCacheId), 42 pending_selected_cache_id_(kNoCacheId),
43 frontend_(frontend), service_(service), 43 frontend_(frontend), service_(service),
44 pending_get_status_callback_(NULL), pending_start_update_callback_(NULL), 44 pending_callback_param_(NULL),
45 pending_swap_cache_callback_(NULL), pending_callback_param_(NULL),
46 main_resource_was_fallback_(false), main_resource_blocked_(false), 45 main_resource_was_fallback_(false), main_resource_blocked_(false),
47 associated_cache_info_pending_(false) { 46 associated_cache_info_pending_(false) {
48 } 47 }
49 48
50 AppCacheHost::~AppCacheHost() { 49 AppCacheHost::~AppCacheHost() {
51 FOR_EACH_OBSERVER(Observer, observers_, OnDestructionImminent(this)); 50 FOR_EACH_OBSERVER(Observer, observers_, OnDestructionImminent(this));
52 if (associated_cache_.get()) 51 if (associated_cache_.get())
53 associated_cache_->UnassociateHost(this); 52 associated_cache_->UnassociateHost(this);
54 if (group_being_updated_.get()) 53 if (group_being_updated_.get())
55 group_being_updated_->RemoveUpdateObserver(this); 54 group_being_updated_->RemoveUpdateObserver(this);
56 service_->storage()->CancelDelegateCallbacks(this); 55 service_->storage()->CancelDelegateCallbacks(this);
57 if (service()->quota_manager_proxy() && !origin_in_use_.is_empty()) 56 if (service()->quota_manager_proxy() && !origin_in_use_.is_empty())
58 service()->quota_manager_proxy()->NotifyOriginNoLongerInUse(origin_in_use_); 57 service()->quota_manager_proxy()->NotifyOriginNoLongerInUse(origin_in_use_);
59 } 58 }
60 59
61 void AppCacheHost::AddObserver(Observer* observer) { 60 void AppCacheHost::AddObserver(Observer* observer) {
62 observers_.AddObserver(observer); 61 observers_.AddObserver(observer);
63 } 62 }
64 63
65 void AppCacheHost::RemoveObserver(Observer* observer) { 64 void AppCacheHost::RemoveObserver(Observer* observer) {
66 observers_.RemoveObserver(observer); 65 observers_.RemoveObserver(observer);
67 } 66 }
68 67
69 void AppCacheHost::SelectCache(const GURL& document_url, 68 void AppCacheHost::SelectCache(const GURL& document_url,
70 const int64 cache_document_was_loaded_from, 69 const int64 cache_document_was_loaded_from,
71 const GURL& manifest_url) { 70 const GURL& manifest_url) {
72 DCHECK(!pending_start_update_callback_ && 71 DCHECK(pending_start_update_callback_.is_null() &&
73 !pending_swap_cache_callback_ && 72 pending_swap_cache_callback_.is_null() &&
74 !pending_get_status_callback_ && 73 pending_get_status_callback_.is_null() &&
75 !is_selection_pending()); 74 !is_selection_pending());
76 75
77 origin_in_use_ = document_url.GetOrigin(); 76 origin_in_use_ = document_url.GetOrigin();
78 if (service()->quota_manager_proxy() && !origin_in_use_.is_empty()) 77 if (service()->quota_manager_proxy() && !origin_in_use_.is_empty())
79 service()->quota_manager_proxy()->NotifyOriginInUse(origin_in_use_); 78 service()->quota_manager_proxy()->NotifyOriginInUse(origin_in_use_);
80 79
81 if (main_resource_blocked_) 80 if (main_resource_blocked_)
82 frontend_->OnContentBlocked(host_id_, 81 frontend_->OnContentBlocked(host_id_,
83 blocked_manifest_url_); 82 blocked_manifest_url_);
84 83
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 return; 117 return;
119 } 118 }
120 119
121 // TODO(michaeln): If there was a manifest URL, the user agent may report 120 // TODO(michaeln): If there was a manifest URL, the user agent may report
122 // to the user that it was ignored, to aid in application development. 121 // to the user that it was ignored, to aid in application development.
123 FinishCacheSelection(NULL, NULL); 122 FinishCacheSelection(NULL, NULL);
124 } 123 }
125 124
126 void AppCacheHost::SelectCacheForWorker(int parent_process_id, 125 void AppCacheHost::SelectCacheForWorker(int parent_process_id,
127 int parent_host_id) { 126 int parent_host_id) {
128 DCHECK(!pending_start_update_callback_ && 127 DCHECK(pending_start_update_callback_.is_null() &&
129 !pending_swap_cache_callback_ && 128 pending_swap_cache_callback_.is_null() &&
130 !pending_get_status_callback_ && 129 pending_get_status_callback_.is_null() &&
131 !is_selection_pending()); 130 !is_selection_pending());
132 131
133 parent_process_id_ = parent_process_id; 132 parent_process_id_ = parent_process_id;
134 parent_host_id_ = parent_host_id; 133 parent_host_id_ = parent_host_id;
135 FinishCacheSelection(NULL, NULL); 134 FinishCacheSelection(NULL, NULL);
136 } 135 }
137 136
138 void AppCacheHost::SelectCacheForSharedWorker(int64 appcache_id) { 137 void AppCacheHost::SelectCacheForSharedWorker(int64 appcache_id) {
139 DCHECK(!pending_start_update_callback_ && 138 DCHECK(pending_start_update_callback_.is_null() &&
140 !pending_swap_cache_callback_ && 139 pending_swap_cache_callback_.is_null() &&
141 !pending_get_status_callback_ && 140 pending_get_status_callback_.is_null() &&
142 !is_selection_pending()); 141 !is_selection_pending());
143 142
144 if (appcache_id != kNoCacheId) { 143 if (appcache_id != kNoCacheId) {
145 LoadSelectedCache(appcache_id); 144 LoadSelectedCache(appcache_id);
146 return; 145 return;
147 } 146 }
148 FinishCacheSelection(NULL, NULL); 147 FinishCacheSelection(NULL, NULL);
149 } 148 }
150 149
151 // TODO(michaeln): change method name to MarkEntryAsForeign for consistency 150 // TODO(michaeln): change method name to MarkEntryAsForeign for consistency
152 void AppCacheHost::MarkAsForeignEntry(const GURL& document_url, 151 void AppCacheHost::MarkAsForeignEntry(const GURL& document_url,
153 int64 cache_document_was_loaded_from) { 152 int64 cache_document_was_loaded_from) {
154 // The document url is not the resource url in the fallback case. 153 // The document url is not the resource url in the fallback case.
155 service_->storage()->MarkEntryAsForeign( 154 service_->storage()->MarkEntryAsForeign(
156 main_resource_was_fallback_ ? fallback_url_ : document_url, 155 main_resource_was_fallback_ ? fallback_url_ : document_url,
157 cache_document_was_loaded_from); 156 cache_document_was_loaded_from);
158 SelectCache(document_url, kNoCacheId, GURL()); 157 SelectCache(document_url, kNoCacheId, GURL());
159 } 158 }
160 159
161 void AppCacheHost::GetStatusWithCallback(GetStatusCallback* callback, 160 void AppCacheHost::GetStatusWithCallback(const GetStatusCallback& callback,
162 void* callback_param) { 161 void* callback_param) {
163 DCHECK(!pending_start_update_callback_ && 162 DCHECK(pending_start_update_callback_.is_null() &&
164 !pending_swap_cache_callback_ && 163 pending_swap_cache_callback_.is_null() &&
165 !pending_get_status_callback_); 164 pending_get_status_callback_.is_null());
166 165
167 pending_get_status_callback_ = callback; 166 pending_get_status_callback_ = callback;
168 pending_callback_param_ = callback_param; 167 pending_callback_param_ = callback_param;
169 if (is_selection_pending()) 168 if (is_selection_pending())
170 return; 169 return;
171 170
172 DoPendingGetStatus(); 171 DoPendingGetStatus();
173 } 172 }
174 173
175 void AppCacheHost::DoPendingGetStatus() { 174 void AppCacheHost::DoPendingGetStatus() {
176 DCHECK(pending_get_status_callback_); 175 DCHECK_EQ(false, pending_get_status_callback_.is_null());
177 176
178 pending_get_status_callback_->Run( 177 pending_get_status_callback_.Run(GetStatus(), pending_callback_param_);
179 GetStatus(), pending_callback_param_); 178 pending_get_status_callback_.Reset();
180
181 pending_get_status_callback_ = NULL;
182 pending_callback_param_ = NULL; 179 pending_callback_param_ = NULL;
183 } 180 }
184 181
185 void AppCacheHost::StartUpdateWithCallback(StartUpdateCallback* callback, 182 void AppCacheHost::StartUpdateWithCallback(const StartUpdateCallback& callback,
186 void* callback_param) { 183 void* callback_param) {
187 DCHECK(!pending_start_update_callback_ && 184 DCHECK(pending_start_update_callback_.is_null() &&
188 !pending_swap_cache_callback_ && 185 pending_swap_cache_callback_.is_null() &&
189 !pending_get_status_callback_); 186 pending_get_status_callback_.is_null());
190 187
191 pending_start_update_callback_ = callback; 188 pending_start_update_callback_ = callback;
192 pending_callback_param_ = callback_param; 189 pending_callback_param_ = callback_param;
193 if (is_selection_pending()) 190 if (is_selection_pending())
194 return; 191 return;
195 192
196 DoPendingStartUpdate(); 193 DoPendingStartUpdate();
197 } 194 }
198 195
199 void AppCacheHost::DoPendingStartUpdate() { 196 void AppCacheHost::DoPendingStartUpdate() {
200 DCHECK(pending_start_update_callback_); 197 DCHECK_EQ(false, pending_start_update_callback_.is_null());
201 198
202 // 6.9.8 Application cache API 199 // 6.9.8 Application cache API
203 bool success = false; 200 bool success = false;
204 if (associated_cache_ && associated_cache_->owning_group()) { 201 if (associated_cache_ && associated_cache_->owning_group()) {
205 AppCacheGroup* group = associated_cache_->owning_group(); 202 AppCacheGroup* group = associated_cache_->owning_group();
206 if (!group->is_obsolete() && !group->is_being_deleted()) { 203 if (!group->is_obsolete() && !group->is_being_deleted()) {
207 success = true; 204 success = true;
208 group->StartUpdate(); 205 group->StartUpdate();
209 } 206 }
210 } 207 }
211 208
212 pending_start_update_callback_->Run( 209 pending_start_update_callback_.Run(success, pending_callback_param_);
213 success, pending_callback_param_); 210 pending_start_update_callback_.Reset();
214
215 pending_start_update_callback_ = NULL;
216 pending_callback_param_ = NULL; 211 pending_callback_param_ = NULL;
217 } 212 }
218 213
219 void AppCacheHost::SwapCacheWithCallback(SwapCacheCallback* callback, 214 void AppCacheHost::SwapCacheWithCallback(const SwapCacheCallback& callback,
220 void* callback_param) { 215 void* callback_param) {
221 DCHECK(!pending_start_update_callback_ && 216 DCHECK(pending_start_update_callback_.is_null() &&
222 !pending_swap_cache_callback_ && 217 pending_swap_cache_callback_.is_null() &&
223 !pending_get_status_callback_); 218 pending_get_status_callback_.is_null());
224 219
225 pending_swap_cache_callback_ = callback; 220 pending_swap_cache_callback_ = callback;
226 pending_callback_param_ = callback_param; 221 pending_callback_param_ = callback_param;
227 if (is_selection_pending()) 222 if (is_selection_pending())
228 return; 223 return;
229 224
230 DoPendingSwapCache(); 225 DoPendingSwapCache();
231 } 226 }
232 227
233 void AppCacheHost::DoPendingSwapCache() { 228 void AppCacheHost::DoPendingSwapCache() {
234 DCHECK(pending_swap_cache_callback_); 229 DCHECK_EQ(false, pending_swap_cache_callback_.is_null());
235 230
236 // 6.9.8 Application cache API 231 // 6.9.8 Application cache API
237 bool success = false; 232 bool success = false;
238 if (associated_cache_ && associated_cache_->owning_group()) { 233 if (associated_cache_ && associated_cache_->owning_group()) {
239 if (associated_cache_->owning_group()->is_obsolete()) { 234 if (associated_cache_->owning_group()->is_obsolete()) {
240 success = true; 235 success = true;
241 AssociateCache(NULL); 236 AssociateCache(NULL);
242 } else if (swappable_cache_) { 237 } else if (swappable_cache_) {
243 DCHECK(swappable_cache_.get() == 238 DCHECK(swappable_cache_.get() ==
244 swappable_cache_->owning_group()->newest_complete_cache()); 239 swappable_cache_->owning_group()->newest_complete_cache());
245 success = true; 240 success = true;
246 AssociateCache(swappable_cache_); 241 AssociateCache(swappable_cache_);
247 } 242 }
248 } 243 }
249 244
250 pending_swap_cache_callback_->Run( 245 pending_swap_cache_callback_.Run(success, pending_callback_param_);
251 success, pending_callback_param_); 246 pending_swap_cache_callback_.Reset();
252
253 pending_swap_cache_callback_ = NULL;
254 pending_callback_param_ = NULL; 247 pending_callback_param_ = NULL;
255 } 248 }
256 249
257 void AppCacheHost::SetSpawningHostId( 250 void AppCacheHost::SetSpawningHostId(
258 int spawning_process_id, int spawning_host_id) { 251 int spawning_process_id, int spawning_host_id) {
259 spawning_process_id_ = spawning_process_id; 252 spawning_process_id_ = spawning_process_id;
260 spawning_host_id_ = spawning_host_id; 253 spawning_host_id_ = spawning_host_id;
261 } 254 }
262 255
263 const AppCacheHost* AppCacheHost::GetSpawningHost() const { 256 const AppCacheHost* AppCacheHost::GetSpawningHost() const {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 AssociateCache(NULL); // The UpdateJob may produce one for us later. 389 AssociateCache(NULL); // The UpdateJob may produce one for us later.
397 group->StartUpdateWithNewMasterEntry(this, new_master_entry_url_); 390 group->StartUpdateWithNewMasterEntry(this, new_master_entry_url_);
398 ObserveGroupBeingUpdated(group); 391 ObserveGroupBeingUpdated(group);
399 } else { 392 } else {
400 // Otherwise, the Document is not associated with any application cache. 393 // Otherwise, the Document is not associated with any application cache.
401 new_master_entry_url_ = GURL(); 394 new_master_entry_url_ = GURL();
402 AssociateCache(NULL); 395 AssociateCache(NULL);
403 } 396 }
404 397
405 // Respond to pending callbacks now that we have a selection. 398 // Respond to pending callbacks now that we have a selection.
406 if (pending_get_status_callback_) 399 if (!pending_get_status_callback_.is_null())
407 DoPendingGetStatus(); 400 DoPendingGetStatus();
408 else if (pending_start_update_callback_) 401 else if (!pending_start_update_callback_.is_null())
409 DoPendingStartUpdate(); 402 DoPendingStartUpdate();
410 else if (pending_swap_cache_callback_) 403 else if (!pending_swap_cache_callback_.is_null())
411 DoPendingSwapCache(); 404 DoPendingSwapCache();
412 405
413 FOR_EACH_OBSERVER(Observer, observers_, OnCacheSelectionComplete(this)); 406 FOR_EACH_OBSERVER(Observer, observers_, OnCacheSelectionComplete(this));
414 } 407 }
415 408
416 void AppCacheHost::ObserveGroupBeingUpdated(AppCacheGroup* group) { 409 void AppCacheHost::ObserveGroupBeingUpdated(AppCacheGroup* group) {
417 DCHECK(!group_being_updated_); 410 DCHECK(!group_being_updated_);
418 group_being_updated_ = group; 411 group_being_updated_ = group;
419 newest_cache_of_group_being_updated_ = group->newest_complete_cache(); 412 newest_cache_of_group_being_updated_ = group->newest_complete_cache();
420 group->AddUpdateObserver(this); 413 group->AddUpdateObserver(this);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 associated_cache_info_pending_ = cache && !cache->is_complete(); 474 associated_cache_info_pending_ = cache && !cache->is_complete();
482 AppCacheInfo info; 475 AppCacheInfo info;
483 if (cache) { 476 if (cache) {
484 cache->AssociateHost(this); 477 cache->AssociateHost(this);
485 FillCacheInfo(cache, GetStatus(), &info); 478 FillCacheInfo(cache, GetStatus(), &info);
486 } 479 }
487 frontend_->OnCacheSelected(host_id_, info); 480 frontend_->OnCacheSelected(host_id_, info);
488 } 481 }
489 482
490 } // namespace appcache 483 } // namespace appcache
OLDNEW
« no previous file with comments | « webkit/appcache/appcache_host.h ('k') | webkit/appcache/appcache_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698