| OLD | NEW |
| 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/instant/instant_controller.h" | 5 #include "chrome/browser/instant/instant_controller.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 GURL InstantController::GetCurrentURL() { | 513 GURL InstantController::GetCurrentURL() { |
| 514 return loader_manager_.get() && loader_manager_->active_loader() ? | 514 return loader_manager_.get() && loader_manager_->active_loader() ? |
| 515 loader_manager_->active_loader()->url() : GURL(); | 515 loader_manager_->active_loader()->url() : GURL(); |
| 516 } | 516 } |
| 517 | 517 |
| 518 void InstantController::InstantStatusChanged(InstantLoader* loader) { | 518 void InstantController::InstantStatusChanged(InstantLoader* loader) { |
| 519 if (!loader->http_status_ok()) { | 519 if (!loader->http_status_ok()) { |
| 520 // Status isn't ok, start a timer that when fires shows the result. This | 520 // Status isn't ok, start a timer that when fires shows the result. This |
| 521 // delays showing 403 pages and the like. | 521 // delays showing 403 pages and the like. |
| 522 show_timer_.Stop(); | 522 show_timer_.Stop(); |
| 523 show_timer_.Start(FROM_HERE, | 523 show_timer_.Start( |
| 524 base::TimeDelta::FromMilliseconds(kShowDelayMS), | 524 base::TimeDelta::FromMilliseconds(kShowDelayMS), |
| 525 this, &InstantController::ShowTimerFired); | 525 this, &InstantController::ShowTimerFired); |
| 526 UpdateDisplayableLoader(); | 526 UpdateDisplayableLoader(); |
| 527 return; | 527 return; |
| 528 } | 528 } |
| 529 | 529 |
| 530 ProcessInstantStatusChanged(loader); | 530 ProcessInstantStatusChanged(loader); |
| 531 } | 531 } |
| 532 | 532 |
| 533 void InstantController::SetSuggestedTextFor( | 533 void InstantController::SetSuggestedTextFor( |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 // Immediately update if the url is the same (which should result in nothing | 662 // Immediately update if the url is the same (which should result in nothing |
| 663 // happening) or the hosts differ, otherwise we'll delay the update. | 663 // happening) or the hosts differ, otherwise we'll delay the update. |
| 664 return (active_loader->url() == url) || | 664 return (active_loader->url() == url) || |
| 665 (active_loader->url().host() != url.host()); | 665 (active_loader->url().host() != url.host()); |
| 666 } | 666 } |
| 667 | 667 |
| 668 void InstantController::ScheduleUpdate(const GURL& url) { | 668 void InstantController::ScheduleUpdate(const GURL& url) { |
| 669 scheduled_url_ = url; | 669 scheduled_url_ = url; |
| 670 | 670 |
| 671 update_timer_.Stop(); | 671 update_timer_.Stop(); |
| 672 update_timer_.Start(FROM_HERE, | 672 update_timer_.Start(base::TimeDelta::FromMilliseconds(kUpdateDelayMS), |
| 673 base::TimeDelta::FromMilliseconds(kUpdateDelayMS), | |
| 674 this, &InstantController::ProcessScheduledUpdate); | 673 this, &InstantController::ProcessScheduledUpdate); |
| 675 } | 674 } |
| 676 | 675 |
| 677 void InstantController::ProcessScheduledUpdate() { | 676 void InstantController::ProcessScheduledUpdate() { |
| 678 DCHECK(loader_manager_.get()); | 677 DCHECK(loader_manager_.get()); |
| 679 | 678 |
| 680 // We only delay loading of sites that don't support instant, so we can ignore | 679 // We only delay loading of sites that don't support instant, so we can ignore |
| 681 // suggested_text here. | 680 // suggested_text here. |
| 682 string16 suggested_text; | 681 string16 suggested_text; |
| 683 UpdateLoader(NULL, scheduled_url_, last_transition_type_, string16(), false, | 682 UpdateLoader(NULL, scheduled_url_, last_transition_type_, string16(), false, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 scoped_ptr<InstantLoader> owned_loader; | 717 scoped_ptr<InstantLoader> owned_loader; |
| 719 TemplateURLID template_url_id = template_url ? template_url->id() : 0; | 718 TemplateURLID template_url_id = template_url ? template_url->id() : 0; |
| 720 InstantLoader* new_loader = | 719 InstantLoader* new_loader = |
| 721 loader_manager_->UpdateLoader(template_url_id, &owned_loader); | 720 loader_manager_->UpdateLoader(template_url_id, &owned_loader); |
| 722 | 721 |
| 723 new_loader->SetOmniboxBounds(omnibox_bounds_); | 722 new_loader->SetOmniboxBounds(omnibox_bounds_); |
| 724 if (new_loader->Update(tab_contents_, template_url, url, transition_type, | 723 if (new_loader->Update(tab_contents_, template_url, url, transition_type, |
| 725 user_text, verbatim, suggested_text)) { | 724 user_text, verbatim, suggested_text)) { |
| 726 show_timer_.Stop(); | 725 show_timer_.Stop(); |
| 727 if (!new_loader->http_status_ok()) { | 726 if (!new_loader->http_status_ok()) { |
| 728 show_timer_.Start(FROM_HERE, | 727 show_timer_.Start( |
| 729 base::TimeDelta::FromMilliseconds(kShowDelayMS), | 728 base::TimeDelta::FromMilliseconds(kShowDelayMS), |
| 730 this, &InstantController::ShowTimerFired); | 729 this, &InstantController::ShowTimerFired); |
| 731 } | 730 } |
| 732 } | 731 } |
| 733 UpdateDisplayableLoader(); | 732 UpdateDisplayableLoader(); |
| 734 } | 733 } |
| 735 | 734 |
| 736 InstantController::PreviewCondition InstantController::GetPreviewConditionFor( | 735 InstantController::PreviewCondition InstantController::GetPreviewConditionFor( |
| 737 const AutocompleteMatch& match, const TemplateURL** template_url) { | 736 const AutocompleteMatch& match, const TemplateURL** template_url) { |
| 738 const TemplateURL* t_url = match.template_url; | 737 const TemplateURL* t_url = match.template_url; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 793 if (destroy_factory_.empty()) { | 792 if (destroy_factory_.empty()) { |
| 794 MessageLoop::current()->PostTask( | 793 MessageLoop::current()->PostTask( |
| 795 FROM_HERE, destroy_factory_.NewRunnableMethod( | 794 FROM_HERE, destroy_factory_.NewRunnableMethod( |
| 796 &InstantController::DestroyLoaders)); | 795 &InstantController::DestroyLoaders)); |
| 797 } | 796 } |
| 798 } | 797 } |
| 799 | 798 |
| 800 void InstantController::DestroyLoaders() { | 799 void InstantController::DestroyLoaders() { |
| 801 loaders_to_destroy_.reset(); | 800 loaders_to_destroy_.reset(); |
| 802 } | 801 } |
| OLD | NEW |