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

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

Issue 6546004: Defend against selectCache() being called multiple times.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 10 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/web_application_cache_host_impl.h » ('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) 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 "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 16 matching lines...) Expand all
27 info->creation_time = cache->owning_group()->creation_time(); 27 info->creation_time = cache->owning_group()->creation_time();
28 info->size = cache->cache_size(); 28 info->size = cache->cache_size();
29 } 29 }
30 } 30 }
31 31
32 } // Anonymous namespace 32 } // Anonymous namespace
33 33
34 AppCacheHost::AppCacheHost(int host_id, AppCacheFrontend* frontend, 34 AppCacheHost::AppCacheHost(int host_id, AppCacheFrontend* frontend,
35 AppCacheService* service) 35 AppCacheService* service)
36 : host_id_(host_id), parent_host_id_(kNoHostId), parent_process_id_(0), 36 : host_id_(host_id), parent_host_id_(kNoHostId), parent_process_id_(0),
37 was_select_cache_called_(false),
37 pending_main_resource_cache_id_(kNoCacheId), 38 pending_main_resource_cache_id_(kNoCacheId),
38 pending_selected_cache_id_(kNoCacheId), 39 pending_selected_cache_id_(kNoCacheId),
39 frontend_(frontend), service_(service), 40 frontend_(frontend), service_(service),
40 pending_get_status_callback_(NULL), pending_start_update_callback_(NULL), 41 pending_get_status_callback_(NULL), pending_start_update_callback_(NULL),
41 pending_swap_cache_callback_(NULL), pending_callback_param_(NULL), 42 pending_swap_cache_callback_(NULL), pending_callback_param_(NULL),
42 main_resource_was_fallback_(false), main_resource_blocked_(false), 43 main_resource_was_fallback_(false), main_resource_blocked_(false),
43 associated_cache_info_pending_(false) { 44 associated_cache_info_pending_(false) {
44 } 45 }
45 46
46 AppCacheHost::~AppCacheHost() { 47 AppCacheHost::~AppCacheHost() {
(...skipping 12 matching lines...) Expand all
59 void AppCacheHost::RemoveObserver(Observer* observer) { 60 void AppCacheHost::RemoveObserver(Observer* observer) {
60 observers_.RemoveObserver(observer); 61 observers_.RemoveObserver(observer);
61 } 62 }
62 63
63 void AppCacheHost::SelectCache(const GURL& document_url, 64 void AppCacheHost::SelectCache(const GURL& document_url,
64 const int64 cache_document_was_loaded_from, 65 const int64 cache_document_was_loaded_from,
65 const GURL& manifest_url) { 66 const GURL& manifest_url) {
66 DCHECK(!pending_start_update_callback_ && 67 DCHECK(!pending_start_update_callback_ &&
67 !pending_swap_cache_callback_ && 68 !pending_swap_cache_callback_ &&
68 !pending_get_status_callback_); 69 !pending_get_status_callback_);
69 70
ericu 2011/02/18 01:27:34 Given that this condition is now prevented in the
michaeln 2011/02/18 01:41:46 Right, I'm being overly paranoid after seeing a CR
71 // This should not be called more than once per instance, but if a renderer
72 // some how does get confused and calls us twice, we ignore all but the
73 // first call.
74 if (was_select_cache_called_)
75 return;
76 was_select_cache_called_ = true;
77
70 if (main_resource_blocked_) 78 if (main_resource_blocked_)
71 frontend_->OnContentBlocked(host_id_, 79 frontend_->OnContentBlocked(host_id_,
72 blocked_manifest_url_); 80 blocked_manifest_url_);
73 81
74 // First we handle an unusual case of SelectCache being called a second
75 // time. Generally this shouldn't happen, but with bad content I think
76 // this can occur... <html manifest=foo> <html manifest=bar></html></html>
77 // We handle this by killing whatever loading we have initiated, and by
78 // unassociating any hosts we currently have associated... and starting
79 // anew with the inputs to this SelectCache call.
80 // TODO(michaeln): at some point determine what behavior the algorithms
81 // described in the HTML5 draft produce and have our impl produce those
82 // results (or suggest changes to the algorihtms described in the spec
83 // if the resulting behavior is just too insane).
84 if (is_selection_pending()) {
85 service_->storage()->CancelDelegateCallbacks(this);
86 pending_selected_manifest_url_ = GURL();
87 pending_selected_cache_id_ = kNoCacheId;
88 } else if (associated_cache()) {
89 AssociateCache(NULL);
90 }
91 new_master_entry_url_ = GURL();
92
93 // 6.9.6 The application cache selection algorithm. 82 // 6.9.6 The application cache selection algorithm.
94 // The algorithm is started here and continues in FinishCacheSelection, 83 // The algorithm is started here and continues in FinishCacheSelection,
95 // after cache or group loading is complete. 84 // after cache or group loading is complete.
96 // Note: Foreign entries are detected on the client side and 85 // Note: Foreign entries are detected on the client side and
97 // MarkAsForeignEntry is called in that case, so that detection 86 // MarkAsForeignEntry is called in that case, so that detection
98 // step is skipped here. See WebApplicationCacheHostImpl.cc 87 // step is skipped here. See WebApplicationCacheHostImpl.cc
99 88
100 if (cache_document_was_loaded_from != kNoCacheId) { 89 if (cache_document_was_loaded_from != kNoCacheId) {
101 LoadSelectedCache(cache_document_was_loaded_from); 90 LoadSelectedCache(cache_document_was_loaded_from);
102 return; 91 return;
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 associated_cache_info_pending_ = cache && !cache->is_complete(); 464 associated_cache_info_pending_ = cache && !cache->is_complete();
476 AppCacheInfo info; 465 AppCacheInfo info;
477 if (cache) { 466 if (cache) {
478 cache->AssociateHost(this); 467 cache->AssociateHost(this);
479 FillCacheInfo(cache, GetStatus(), &info); 468 FillCacheInfo(cache, GetStatus(), &info);
480 } 469 }
481 frontend_->OnCacheSelected(host_id_, info); 470 frontend_->OnCacheSelected(host_id_, info);
482 } 471 }
483 472
484 } // namespace appcache 473 } // namespace appcache
OLDNEW
« no previous file with comments | « webkit/appcache/appcache_host.h ('k') | webkit/appcache/web_application_cache_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698