OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "webkit/appcache/appcache.h" | 8 #include "webkit/appcache/appcache.h" |
9 #include "webkit/appcache/appcache_request_handler.h" | 9 #include "webkit/appcache/appcache_request_handler.h" |
10 | 10 |
11 namespace appcache { | 11 namespace appcache { |
12 | 12 |
13 AppCacheHost::AppCacheHost(int host_id, AppCacheFrontend* frontend, | 13 AppCacheHost::AppCacheHost(int host_id, AppCacheFrontend* frontend, |
14 AppCacheService* service) | 14 AppCacheService* service) |
15 : host_id_(host_id), pending_main_resource_cache_id_(kNoCacheId), | 15 : host_id_(host_id), pending_main_resource_cache_id_(kNoCacheId), |
16 pending_selected_cache_id_(kNoCacheId), | 16 pending_selected_cache_id_(kNoCacheId), |
17 frontend_(frontend), service_(service), | 17 frontend_(frontend), service_(service), |
18 pending_get_status_callback_(NULL), pending_start_update_callback_(NULL), | 18 pending_get_status_callback_(NULL), pending_start_update_callback_(NULL), |
19 pending_swap_cache_callback_(NULL), pending_callback_param_(NULL) { | 19 pending_swap_cache_callback_(NULL), pending_callback_param_(NULL), |
| 20 content_blocked_(false) { |
20 } | 21 } |
21 | 22 |
22 AppCacheHost::~AppCacheHost() { | 23 AppCacheHost::~AppCacheHost() { |
23 FOR_EACH_OBSERVER(Observer, observers_, OnDestructionImminent(this)); | 24 FOR_EACH_OBSERVER(Observer, observers_, OnDestructionImminent(this)); |
24 if (associated_cache_.get()) | 25 if (associated_cache_.get()) |
25 associated_cache_->UnassociateHost(this); | 26 associated_cache_->UnassociateHost(this); |
26 if (group_being_updated_.get()) | 27 if (group_being_updated_.get()) |
27 group_being_updated_->RemoveUpdateObserver(this); | 28 group_being_updated_->RemoveUpdateObserver(this); |
28 service_->storage()->CancelDelegateCallbacks(this); | 29 service_->storage()->CancelDelegateCallbacks(this); |
29 } | 30 } |
30 | 31 |
31 void AppCacheHost::AddObserver(Observer* observer) { | 32 void AppCacheHost::AddObserver(Observer* observer) { |
32 observers_.AddObserver(observer); | 33 observers_.AddObserver(observer); |
33 } | 34 } |
34 | 35 |
35 void AppCacheHost::RemoveObserver(Observer* observer) { | 36 void AppCacheHost::RemoveObserver(Observer* observer) { |
36 observers_.RemoveObserver(observer); | 37 observers_.RemoveObserver(observer); |
37 } | 38 } |
38 | 39 |
39 void AppCacheHost::SelectCache(const GURL& document_url, | 40 void AppCacheHost::SelectCache(const GURL& document_url, |
40 const int64 cache_document_was_loaded_from, | 41 const int64 cache_document_was_loaded_from, |
41 const GURL& manifest_url) { | 42 const GURL& manifest_url) { |
42 DCHECK(!pending_start_update_callback_ && | 43 DCHECK(!pending_start_update_callback_ && |
43 !pending_swap_cache_callback_ && | 44 !pending_swap_cache_callback_ && |
44 !pending_get_status_callback_); | 45 !pending_get_status_callback_); |
45 | 46 |
| 47 if (content_blocked_) |
| 48 frontend_->OnContentBlocked(host_id_); |
| 49 |
46 // First we handle an unusual case of SelectCache being called a second | 50 // First we handle an unusual case of SelectCache being called a second |
47 // time. Generally this shouldn't happen, but with bad content I think | 51 // time. Generally this shouldn't happen, but with bad content I think |
48 // this can occur... <html manifest=foo> <html manifest=bar></html></html> | 52 // this can occur... <html manifest=foo> <html manifest=bar></html></html> |
49 // We handle this by killing whatever loading we have initiated, and by | 53 // We handle this by killing whatever loading we have initiated, and by |
50 // unassociating any hosts we currently have associated... and starting | 54 // unassociating any hosts we currently have associated... and starting |
51 // anew with the inputs to this SelectCache call. | 55 // anew with the inputs to this SelectCache call. |
52 // TODO(michaeln): at some point determine what behavior the algorithms | 56 // TODO(michaeln): at some point determine what behavior the algorithms |
53 // described in the HTML5 draft produce and have our impl produce those | 57 // described in the HTML5 draft produce and have our impl produce those |
54 // results (or suggest changes to the algorihtms described in the spec | 58 // results (or suggest changes to the algorihtms described in the spec |
55 // if the resulting behavior is just too insane). | 59 // if the resulting behavior is just too insane). |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 DCHECK_EQ(group, group_being_updated_); | 318 DCHECK_EQ(group, group_being_updated_); |
315 group->RemoveUpdateObserver(this); | 319 group->RemoveUpdateObserver(this); |
316 | 320 |
317 // Add a reference to the newest complete cache. | 321 // Add a reference to the newest complete cache. |
318 SetSwappableCache(group); | 322 SetSwappableCache(group); |
319 | 323 |
320 group_being_updated_ = NULL; | 324 group_being_updated_ = NULL; |
321 newest_cache_of_group_being_updated_ = NULL; | 325 newest_cache_of_group_being_updated_ = NULL; |
322 } | 326 } |
323 | 327 |
| 328 void AppCacheHost::OnContentBlocked(AppCacheGroup* group) { |
| 329 frontend_->OnContentBlocked(host_id_); |
| 330 } |
| 331 |
324 void AppCacheHost::SetSwappableCache(AppCacheGroup* group) { | 332 void AppCacheHost::SetSwappableCache(AppCacheGroup* group) { |
325 if (!group) { | 333 if (!group) { |
326 swappable_cache_ = NULL; | 334 swappable_cache_ = NULL; |
327 } else { | 335 } else { |
328 AppCache* new_cache = group->newest_complete_cache(); | 336 AppCache* new_cache = group->newest_complete_cache(); |
329 if (new_cache != associated_cache_) | 337 if (new_cache != associated_cache_) |
330 swappable_cache_ = new_cache; | 338 swappable_cache_ = new_cache; |
331 else | 339 else |
332 swappable_cache_ = NULL; | 340 swappable_cache_ = NULL; |
333 } | 341 } |
334 } | 342 } |
335 | 343 |
336 void AppCacheHost::LoadMainResourceCache(int64 cache_id) { | 344 void AppCacheHost::LoadMainResourceCache(int64 cache_id) { |
337 DCHECK(cache_id != kNoCacheId); | 345 DCHECK(cache_id != kNoCacheId); |
338 if (pending_main_resource_cache_id_ == cache_id || | 346 if (pending_main_resource_cache_id_ == cache_id || |
339 (main_resource_cache_ && main_resource_cache_->cache_id() == cache_id)) { | 347 (main_resource_cache_ && main_resource_cache_->cache_id() == cache_id)) { |
340 return; | 348 return; |
341 } | 349 } |
342 pending_main_resource_cache_id_ = cache_id; | 350 pending_main_resource_cache_id_ = cache_id; |
343 service_->storage()->LoadCache(cache_id, this); | 351 service_->storage()->LoadCache(cache_id, this); |
344 } | 352 } |
345 | 353 |
| 354 void AppCacheHost::NotifyContentBlocked() { |
| 355 content_blocked_ = true; |
| 356 } |
| 357 |
346 void AppCacheHost::AssociateCache(AppCache* cache) { | 358 void AppCacheHost::AssociateCache(AppCache* cache) { |
347 if (associated_cache_.get()) { | 359 if (associated_cache_.get()) { |
348 associated_cache_->UnassociateHost(this); | 360 associated_cache_->UnassociateHost(this); |
349 } | 361 } |
350 | 362 |
351 associated_cache_ = cache; | 363 associated_cache_ = cache; |
352 SetSwappableCache(cache ? cache->owning_group() : NULL); | 364 SetSwappableCache(cache ? cache->owning_group() : NULL); |
353 | 365 |
354 if (cache) { | 366 if (cache) { |
355 cache->AssociateHost(this); | 367 cache->AssociateHost(this); |
356 frontend_->OnCacheSelected(host_id_, cache->cache_id(), GetStatus()); | 368 frontend_->OnCacheSelected(host_id_, cache->cache_id(), GetStatus()); |
357 } else { | 369 } else { |
358 frontend_->OnCacheSelected(host_id_, kNoCacheId, UNCACHED); | 370 frontend_->OnCacheSelected(host_id_, kNoCacheId, UNCACHED); |
359 } | 371 } |
360 } | 372 } |
361 | 373 |
362 } // namespace appcache | 374 } // namespace appcache |
OLD | NEW |