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

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

Issue 7374008: Move download stuff from download helper back to TabContents. This is basically a revert of r8576... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync Created 9 years, 5 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) 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 "chrome/browser/prerender/prerender_contents.h" 5 #include "chrome/browser/prerender/prerender_contents.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/process_util.h" 10 #include "base/process_util.h"
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 const RenderViewHost* source_render_view_host) { 143 const RenderViewHost* source_render_view_host) {
144 DCHECK(profile_ != NULL); 144 DCHECK(profile_ != NULL);
145 DCHECK(!prerendering_has_started_); 145 DCHECK(!prerendering_has_started_);
146 DCHECK(prerender_contents_.get() == NULL); 146 DCHECK(prerender_contents_.get() == NULL);
147 147
148 prerendering_has_started_ = true; 148 prerendering_has_started_ = true;
149 TabContents* new_contents = new TabContents(profile_, NULL, MSG_ROUTING_NONE, 149 TabContents* new_contents = new TabContents(profile_, NULL, MSG_ROUTING_NONE,
150 NULL, NULL); 150 NULL, NULL);
151 prerender_contents_.reset(new TabContentsWrapper(new_contents)); 151 prerender_contents_.reset(new TabContentsWrapper(new_contents));
152 TabContentsObserver::Observe(new_contents); 152 TabContentsObserver::Observe(new_contents);
153 prerender_contents_->download_tab_helper()->set_delegate(this);
154 153
155 gfx::Rect tab_bounds; 154 gfx::Rect tab_bounds;
156 if (source_render_view_host) { 155 if (source_render_view_host) {
157 DCHECK(source_render_view_host->view() != NULL); 156 DCHECK(source_render_view_host->view() != NULL);
158 TabContents* source_tc = 157 TabContents* source_tc =
159 source_render_view_host->delegate()->GetAsTabContents(); 158 source_render_view_host->delegate()->GetAsTabContents();
160 if (source_tc) { 159 if (source_tc) {
161 // So that history merging will work, get the max page ID 160 // So that history merging will work, get the max page ID
162 // of the old page as a starting id. 161 // of the old page as a starting id.
163 starting_page_id_ = source_tc->GetMaxPageID(); 162 starting_page_id_ = source_tc->GetMaxPageID();
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 } 509 }
511 set_final_status(final_status); 510 set_final_status(final_status);
512 511
513 // We may destroy the PrerenderContents before we have initialized the 512 // We may destroy the PrerenderContents before we have initialized the
514 // RenderViewHost. Otherwise set the Observer's PrerenderContents to NULL to 513 // RenderViewHost. Otherwise set the Observer's PrerenderContents to NULL to
515 // avoid any more messages being sent. 514 // avoid any more messages being sent.
516 if (render_view_host_observer_.get()) 515 if (render_view_host_observer_.get())
517 render_view_host_observer_->set_prerender_contents(NULL); 516 render_view_host_observer_->set_prerender_contents(NULL);
518 } 517 }
519 518
520 bool PrerenderContents::CanDownload(int request_id) {
521 Destroy(FINAL_STATUS_DOWNLOAD);
522 // Cancel the download.
523 return false;
524 }
525
526 void PrerenderContents::OnStartDownload(DownloadItem* download,
527 TabContentsWrapper* tab) {
528 // Prerendered pages should never be able to download files.
529 NOTREACHED();
530 }
531
532 base::ProcessMetrics* PrerenderContents::MaybeGetProcessMetrics() { 519 base::ProcessMetrics* PrerenderContents::MaybeGetProcessMetrics() {
533 if (process_metrics_.get() == NULL) { 520 if (process_metrics_.get() == NULL) {
534 // If a PrenderContents hasn't started prerending, don't be fully formed. 521 // If a PrenderContents hasn't started prerending, don't be fully formed.
535 if (!render_view_host() || !render_view_host()->process()) 522 if (!render_view_host() || !render_view_host()->process())
536 return NULL; 523 return NULL;
537 base::ProcessHandle handle = render_view_host()->process()->GetHandle(); 524 base::ProcessHandle handle = render_view_host()->process()->GetHandle();
538 if (handle == base::kNullProcessHandle) 525 if (handle == base::kNullProcessHandle)
539 return NULL; 526 return NULL;
540 #if !defined(OS_MACOSX) 527 #if !defined(OS_MACOSX)
541 process_metrics_.reset(base::ProcessMetrics::CreateProcessMetrics(handle)); 528 process_metrics_.reset(base::ProcessMetrics::CreateProcessMetrics(handle));
(...skipping 15 matching lines...) Expand all
557 size_t private_bytes, shared_bytes; 544 size_t private_bytes, shared_bytes;
558 if (metrics->GetMemoryBytes(&private_bytes, &shared_bytes) && 545 if (metrics->GetMemoryBytes(&private_bytes, &shared_bytes) &&
559 private_bytes > prerender_manager_->config().max_bytes) { 546 private_bytes > prerender_manager_->config().max_bytes) {
560 Destroy(FINAL_STATUS_MEMORY_LIMIT_EXCEEDED); 547 Destroy(FINAL_STATUS_MEMORY_LIMIT_EXCEEDED);
561 } 548 }
562 } 549 }
563 550
564 TabContentsWrapper* PrerenderContents::ReleasePrerenderContents() { 551 TabContentsWrapper* PrerenderContents::ReleasePrerenderContents() {
565 prerender_contents_->tab_contents()->set_delegate(NULL); 552 prerender_contents_->tab_contents()->set_delegate(NULL);
566 render_view_host_observer_.reset(); 553 render_view_host_observer_.reset();
567 prerender_contents_->download_tab_helper()->set_delegate(NULL);
568 TabContentsObserver::Observe(NULL); 554 TabContentsObserver::Observe(NULL);
569 return prerender_contents_.release(); 555 return prerender_contents_.release();
570 } 556 }
571 557
572 RenderViewHostDelegate* PrerenderContents::GetRenderViewHostDelegate() { 558 RenderViewHostDelegate* PrerenderContents::GetRenderViewHostDelegate() {
573 if (!prerender_contents_.get()) 559 if (!prerender_contents_.get())
574 return NULL; 560 return NULL;
575 return prerender_contents_->tab_contents(); 561 return prerender_contents_->tab_contents();
576 } 562 }
577 563
(...skipping 17 matching lines...) Expand all
595 return NULL; 581 return NULL;
596 DictionaryValue* dict_value = new DictionaryValue(); 582 DictionaryValue* dict_value = new DictionaryValue();
597 dict_value->SetString("url", prerender_url_.spec()); 583 dict_value->SetString("url", prerender_url_.spec());
598 base::TimeTicks current_time = base::TimeTicks::Now(); 584 base::TimeTicks current_time = base::TimeTicks::Now();
599 base::TimeDelta duration = current_time - load_start_time_; 585 base::TimeDelta duration = current_time - load_start_time_;
600 dict_value->SetInteger("duration", duration.InSeconds()); 586 dict_value->SetInteger("duration", duration.InSeconds());
601 return dict_value; 587 return dict_value;
602 } 588 }
603 589
604 } // namespace prerender 590 } // namespace prerender
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698