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

Side by Side Diff: chrome/browser/prerender/prerender_contents.cc

Issue 141163002: Make PrerenderTracker's resource_throttle_io_thread_map_ use RenderFrame IDs instead of RenderView … (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: simplify code Created 6 years, 11 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/prerender/prerender_contents.h" 5 #include "chrome/browser/prerender/prerender_contents.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h"
11 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/chrome_notification_types.h" 13 #include "chrome/browser/chrome_notification_types.h"
13 #include "chrome/browser/favicon/favicon_tab_helper.h" 14 #include "chrome/browser/favicon/favicon_tab_helper.h"
14 #include "chrome/browser/history/history_tab_helper.h" 15 #include "chrome/browser/history/history_tab_helper.h"
15 #include "chrome/browser/history/history_types.h" 16 #include "chrome/browser/history/history_types.h"
16 #include "chrome/browser/prerender/prerender_field_trial.h" 17 #include "chrome/browser/prerender/prerender_field_trial.h"
17 #include "chrome/browser/prerender/prerender_final_status.h" 18 #include "chrome/browser/prerender/prerender_final_status.h"
18 #include "chrome/browser/prerender/prerender_handle.h" 19 #include "chrome/browser/prerender/prerender_handle.h"
19 #include "chrome/browser/prerender/prerender_manager.h" 20 #include "chrome/browser/prerender/prerender_manager.h"
20 #include "chrome/browser/prerender/prerender_manager_factory.h" 21 #include "chrome/browser/prerender/prerender_manager_factory.h"
22 #include "chrome/browser/prerender/prerender_resource_throttle.h"
21 #include "chrome/browser/prerender/prerender_tracker.h" 23 #include "chrome/browser/prerender/prerender_tracker.h"
22 #include "chrome/browser/profiles/profile.h" 24 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/ui/browser.h" 25 #include "chrome/browser/ui/browser.h"
24 #include "chrome/browser/ui/browser_tab_contents.h" 26 #include "chrome/browser/ui/browser_tab_contents.h"
25 #include "chrome/common/prerender_messages.h" 27 #include "chrome/common/prerender_messages.h"
26 #include "chrome/common/render_messages.h" 28 #include "chrome/common/render_messages.h"
27 #include "chrome/common/url_constants.h" 29 #include "chrome/common/url_constants.h"
28 #include "content/public/browser/browser_child_process_host.h" 30 #include "content/public/browser/browser_child_process_host.h"
31 #include "content/public/browser/browser_thread.h"
29 #include "content/public/browser/notification_service.h" 32 #include "content/public/browser/notification_service.h"
30 #include "content/public/browser/render_frame_host.h" 33 #include "content/public/browser/render_frame_host.h"
31 #include "content/public/browser/render_process_host.h" 34 #include "content/public/browser/render_process_host.h"
32 #include "content/public/browser/render_view_host.h" 35 #include "content/public/browser/render_view_host.h"
33 #include "content/public/browser/resource_request_details.h" 36 #include "content/public/browser/resource_request_details.h"
34 #include "content/public/browser/session_storage_namespace.h" 37 #include "content/public/browser/session_storage_namespace.h"
35 #include "content/public/browser/web_contents.h" 38 #include "content/public/browser/web_contents.h"
36 #include "content/public/browser/web_contents_delegate.h" 39 #include "content/public/browser/web_contents_delegate.h"
37 #include "content/public/browser/web_contents_view.h" 40 #include "content/public/browser/web_contents_view.h"
38 #include "content/public/common/favicon_url.h" 41 #include "content/public/common/favicon_url.h"
(...skipping 16 matching lines...) Expand all
55 // existing cookies that existed before the prerender started, or when a cookie 58 // existing cookies that existed before the prerender started, or when a cookie
56 // is changed, we record these events for histogramming purposes. 59 // is changed, we record these events for histogramming purposes.
57 enum InternalCookieEvent { 60 enum InternalCookieEvent {
58 INTERNAL_COOKIE_EVENT_MAIN_FRAME_SEND = 0, 61 INTERNAL_COOKIE_EVENT_MAIN_FRAME_SEND = 0,
59 INTERNAL_COOKIE_EVENT_MAIN_FRAME_CHANGE = 1, 62 INTERNAL_COOKIE_EVENT_MAIN_FRAME_CHANGE = 1,
60 INTERNAL_COOKIE_EVENT_OTHER_SEND = 2, 63 INTERNAL_COOKIE_EVENT_OTHER_SEND = 2,
61 INTERNAL_COOKIE_EVENT_OTHER_CHANGE = 3, 64 INTERNAL_COOKIE_EVENT_OTHER_CHANGE = 3,
62 INTERNAL_COOKIE_EVENT_MAX 65 INTERNAL_COOKIE_EVENT_MAX
63 }; 66 };
64 67
68 void ResumeThrottles(
69 std::vector<base::WeakPtr<PrerenderResourceThrottle> > throttles) {
70 for (size_t i = 0; i < throttles.size(); i++) {
71 if (throttles[i])
72 throttles[i]->Resume();
73 }
74 }
75
65 } // namespace 76 } // namespace
66 77
67 // static 78 // static
68 const int PrerenderContents::kNumCookieStatuses = 79 const int PrerenderContents::kNumCookieStatuses =
69 (1 << INTERNAL_COOKIE_EVENT_MAX); 80 (1 << INTERNAL_COOKIE_EVENT_MAX);
70 81
71 class PrerenderContentsFactoryImpl : public PrerenderContents::Factory { 82 class PrerenderContentsFactoryImpl : public PrerenderContents::Factory {
72 public: 83 public:
73 virtual PrerenderContents* CreatePrerenderContents( 84 virtual PrerenderContents* CreatePrerenderContents(
74 PrerenderManager* prerender_manager, Profile* profile, 85 PrerenderManager* prerender_manager, Profile* profile,
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 219
209 SessionStorageNamespace* session_storage_namespace = NULL; 220 SessionStorageNamespace* session_storage_namespace = NULL;
210 if (prerender_contents_) { 221 if (prerender_contents_) {
211 // TODO(ajwong): This does not correctly handle storage for isolated apps. 222 // TODO(ajwong): This does not correctly handle storage for isolated apps.
212 session_storage_namespace = prerender_contents_-> 223 session_storage_namespace = prerender_contents_->
213 GetController().GetDefaultSessionStorageNamespace(); 224 GetController().GetDefaultSessionStorageNamespace();
214 } 225 }
215 prerender_manager_->StartPendingPrerenders( 226 prerender_manager_->StartPendingPrerenders(
216 child_id_, &pending_prerenders_, session_storage_namespace); 227 child_id_, &pending_prerenders_, session_storage_namespace);
217 pending_prerenders_.clear(); 228 pending_prerenders_.clear();
229
230 content::BrowserThread::PostTask(
231 content::BrowserThread::IO,
232 FROM_HERE,
233 base::Bind(&ResumeThrottles, resource_throttles_));
234 resource_throttles_.clear();
218 } 235 }
219 236
220 PrerenderContents::PrerenderContents( 237 PrerenderContents::PrerenderContents(
221 PrerenderManager* prerender_manager, 238 PrerenderManager* prerender_manager,
222 Profile* profile, 239 Profile* profile,
223 const GURL& url, 240 const GURL& url,
224 const content::Referrer& referrer, 241 const content::Referrer& referrer,
225 Origin origin, 242 Origin origin,
226 uint8 experiment_id) 243 uint8 experiment_id)
227 : prerendering_has_started_(false), 244 : prerendering_has_started_(false),
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 // Set the size of the prerender WebContents. 353 // Set the size of the prerender WebContents.
337 prerender_contents_->GetView()->SizeContents(size_); 354 prerender_contents_->GetView()->SizeContents(size_);
338 355
339 child_id_ = GetRenderViewHost()->GetProcess()->GetID(); 356 child_id_ = GetRenderViewHost()->GetProcess()->GetID();
340 route_id_ = GetRenderViewHost()->GetRoutingID(); 357 route_id_ = GetRenderViewHost()->GetRoutingID();
341 358
342 // Log transactions to see if we could merge session storage namespaces in 359 // Log transactions to see if we could merge session storage namespaces in
343 // the event of a mismatch. 360 // the event of a mismatch.
344 alias_session_storage_namespace->AddTransactionLogProcessId(child_id_); 361 alias_session_storage_namespace->AddTransactionLogProcessId(child_id_);
345 362
346 // Register this with the ResourceDispatcherHost as a prerender
347 // RenderViewHost. This must be done before the Navigate message to catch all
348 // resource requests, but as it is on the same thread as the Navigate message
349 // (IO) there is no race condition.
350 AddObserver(prerender_manager()->prerender_tracker());
351 NotifyPrerenderStart(); 363 NotifyPrerenderStart();
352 364
353 // Close ourselves when the application is shutting down. 365 // Close ourselves when the application is shutting down.
354 notification_registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, 366 notification_registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING,
355 content::NotificationService::AllSources()); 367 content::NotificationService::AllSources());
356 368
357 // Register for our parent profile to shutdown, so we can shut ourselves down 369 // Register for our parent profile to shutdown, so we can shut ourselves down
358 // as well (should only be called for OTR profiles, as we should receive 370 // as well (should only be called for OTR profiles, as we should receive
359 // APP_TERMINATING before non-OTR profiles are destroyed). 371 // APP_TERMINATING before non-OTR profiles are destroyed).
360 // TODO(tburkard): figure out if this is needed. 372 // TODO(tburkard): figure out if this is needed.
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 838
827 DCHECK_GE(internal_event, 0); 839 DCHECK_GE(internal_event, 0);
828 DCHECK_LT(internal_event, INTERNAL_COOKIE_EVENT_MAX); 840 DCHECK_LT(internal_event, INTERNAL_COOKIE_EVENT_MAX);
829 841
830 cookie_status_ |= (1 << internal_event); 842 cookie_status_ |= (1 << internal_event);
831 843
832 DCHECK_GE(cookie_status_, 0); 844 DCHECK_GE(cookie_status_, 0);
833 DCHECK_LT(cookie_status_, kNumCookieStatuses); 845 DCHECK_LT(cookie_status_, kNumCookieStatuses);
834 } 846 }
835 847
848 void PrerenderContents::AddResourceThrottle(
849 const base::WeakPtr<PrerenderResourceThrottle>& throttle) {
850 resource_throttles_.push_back(throttle);
851 }
852
836 } // namespace prerender 853 } // namespace prerender
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698