| Index: chrome/browser/instant/instant_preloader.cc
 | 
| diff --git a/chrome/browser/instant/instant_preloader.cc b/chrome/browser/instant/instant_preloader.cc
 | 
| new file mode 100644
 | 
| index 0000000000000000000000000000000000000000..af96cd9e2d818c5bd34d79a6c557f2f8bea3dca6
 | 
| --- /dev/null
 | 
| +++ b/chrome/browser/instant/instant_preloader.cc
 | 
| @@ -0,0 +1,154 @@
 | 
| +// Copyright 2012 The Chromium Authors. All rights reserved.
 | 
| +// Use of this source code is governed by a BSD-style license that can be
 | 
| +// found in the LICENSE file.
 | 
| +
 | 
| +#include "chrome/browser/instant/instant_preloader.h"
 | 
| +
 | 
| +#include "base/stringprintf.h"
 | 
| +#include "chrome/browser/instant/instant_service.h"
 | 
| +#include "chrome/browser/instant/search.h"
 | 
| +#include "chrome/browser/profiles/profile.h"
 | 
| +#include "content/public/browser/site_instance.h"
 | 
| +#include "content/public/browser/web_contents.h"
 | 
| +
 | 
| +namespace {
 | 
| +
 | 
| +const int kStalePageTimeoutMS = 3 * 3600 * 1000;  // 3 hours
 | 
| +
 | 
| +// This HTTP header and value are set on loads that originate from Instant.
 | 
| +const char kInstantHeader[] = "X-Purpose: Instant";
 | 
| +
 | 
| +}  // namespace
 | 
| +
 | 
| +InstantPreloader::InstantPreloader(InstantService* service)
 | 
| +    : InstantWebContentsContainer(
 | 
| +          ALLOW_THIS_IN_INITIALIZER_LIST(this), service),
 | 
| +      service_(service) {
 | 
| +  service_->AddObserver(this);
 | 
| +}
 | 
| +
 | 
| +InstantPreloader::~InstantPreloader() {
 | 
| +  service_->RemoveObserver(this);
 | 
| +}
 | 
| +
 | 
| +void InstantPreloader::InitContents() {
 | 
| +  if (contents_ && (supports_instant() || contents_->IsLoading()))
 | 
| +    return;
 | 
| +
 | 
| +  GURL instant_url = chrome::search::GetInstantURL(service_->profile());
 | 
| +  if (!instant_url.is_valid())
 | 
| +    return;
 | 
| +
 | 
| +  content::WebContents::CreateParams create_params(service_->profile(),
 | 
| +      content::SiteInstance::CreateForURL(service_->profile(), instant_url));
 | 
| +  contents_.reset(content::WebContents::Create(create_params));
 | 
| +
 | 
| +  SetUpContents();
 | 
| +
 | 
| +  service_->LogDebugEvent(base::StringPrintf("%p LoadURL '%s'",
 | 
| +                                             this,
 | 
| +                                             instant_url.spec().c_str()));
 | 
| +
 | 
| +  contents_->GetController().LoadURL(instant_url, content::Referrer(),
 | 
| +      content::PAGE_TRANSITION_GENERATED, kInstantHeader);
 | 
| +  contents_->WasHidden();
 | 
| +
 | 
| +  stale_page_timer_.Start(FROM_HERE,
 | 
| +      base::TimeDelta::FromMilliseconds(kStalePageTimeoutMS),
 | 
| +      this, &InstantPreloader::ReloadContents);
 | 
| +}
 | 
| +
 | 
| +scoped_ptr<content::WebContents> InstantPreloader::ReleaseContents() {
 | 
| +  TearDownContents();
 | 
| +  scoped_ptr<content::WebContents> old_contents(contents_.Pass());
 | 
| +  InitContents();
 | 
| +  return old_contents.Pass();
 | 
| +}
 | 
| +
 | 
| +void InstantPreloader::RenderViewGone(
 | 
| +    const content::WebContents* /* contents */) {
 | 
| +  DeleteContents();
 | 
| +}
 | 
| +
 | 
| +void InstantPreloader::InitSearchBox(
 | 
| +    const content::WebContents* /* contents */) {
 | 
| +  page_.DisplayInstantResults(
 | 
| +      chrome::search::IsInstantPrefEnabled(service_->profile()));
 | 
| +  page_.ThemeChanged(service_->theme_info());
 | 
| +  page_.FontChanged(service_->omnibox_font_name(),
 | 
| +                    service_->omnibox_font_size());
 | 
| +  page_.MostVisitedItems(service_->most_visited_items());
 | 
| +}
 | 
| +
 | 
| +void InstantPreloader::InstantSupportDetermined(
 | 
| +    const content::WebContents* /* contents */) {
 | 
| +  if (!supports_instant())
 | 
| +    DeleteContents();
 | 
| +  service_->InstantSupportDetermined();
 | 
| +}
 | 
| +
 | 
| +void InstantPreloader::SetSuggestion(
 | 
| +    const content::WebContents* /* contents */,
 | 
| +    const InstantSuggestion& /* suggestion */) {
 | 
| +}
 | 
| +
 | 
| +void InstantPreloader::NavigateToURL(const content::WebContents* /* contents */,
 | 
| +                                     const GURL& /* url */,
 | 
| +                                     content::PageTransition /* transition */,
 | 
| +                                     WindowOpenDisposition /* disposition */) {
 | 
| +}
 | 
| +
 | 
| +void InstantPreloader::ShowOverlay(const content::WebContents* /* contents */,
 | 
| +                                   int /* height */,
 | 
| +                                   InstantSizeUnits /* height_units */) {
 | 
| +}
 | 
| +
 | 
| +void InstantPreloader::SetFocusState(const content::WebContents* /* contents */,
 | 
| +                                     OmniboxFocusState /* focus_state */) {
 | 
| +}
 | 
| +
 | 
| +void InstantPreloader::DeleteMostVisitedItem(
 | 
| +    const content::WebContents* /* contents */,
 | 
| +    const GURL& /* url */) {
 | 
| +}
 | 
| +
 | 
| +void InstantPreloader::UndoMostVisitedItemDeletion(
 | 
| +    const content::WebContents* /* contents */,
 | 
| +    const GURL& /* url */) {
 | 
| +}
 | 
| +
 | 
| +void InstantPreloader::UndoAllMostVisitedItemDeletions(
 | 
| +    const content::WebContents* /* contents */) {
 | 
| +}
 | 
| +
 | 
| +void InstantPreloader::InstantStatusChanged() {
 | 
| +  if (contents_)
 | 
| +    ReloadContents();
 | 
| +}
 | 
| +
 | 
| +void InstantPreloader::ThemeInfoChanged() {
 | 
| +  page_.ThemeChanged(service_->theme_info());
 | 
| +}
 | 
| +
 | 
| +void InstantPreloader::MostVisitedItemsChanged() {
 | 
| +  page_.MostVisitedItems(service_->most_visited_items());
 | 
| +}
 | 
| +
 | 
| +void InstantPreloader::CloseContents(content::WebContents* /* source */) {
 | 
| +  DeleteContents();
 | 
| +}
 | 
| +
 | 
| +void InstantPreloader::TearDownContents() {
 | 
| +  InstantWebContentsContainer::TearDownContents();
 | 
| +  stale_page_timer_.Stop();
 | 
| +}
 | 
| +
 | 
| +void InstantPreloader::DeleteContents() {
 | 
| +  TearDownContents();
 | 
| +  contents_.reset();
 | 
| +}
 | 
| +
 | 
| +void InstantPreloader::ReloadContents() {
 | 
| +  DeleteContents();
 | 
| +  InitContents();
 | 
| +}
 | 
| 
 |