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( | 523 show_timer_.Start(FROM_HERE, |
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(base::TimeDelta::FromMilliseconds(kUpdateDelayMS), | 672 update_timer_.Start(FROM_HERE, |
| 673 base::TimeDelta::FromMilliseconds(kUpdateDelayMS), |
673 this, &InstantController::ProcessScheduledUpdate); | 674 this, &InstantController::ProcessScheduledUpdate); |
674 } | 675 } |
675 | 676 |
676 void InstantController::ProcessScheduledUpdate() { | 677 void InstantController::ProcessScheduledUpdate() { |
677 DCHECK(loader_manager_.get()); | 678 DCHECK(loader_manager_.get()); |
678 | 679 |
679 // We only delay loading of sites that don't support instant, so we can ignore | 680 // We only delay loading of sites that don't support instant, so we can ignore |
680 // suggested_text here. | 681 // suggested_text here. |
681 string16 suggested_text; | 682 string16 suggested_text; |
682 UpdateLoader(NULL, scheduled_url_, last_transition_type_, string16(), false, | 683 UpdateLoader(NULL, scheduled_url_, last_transition_type_, string16(), false, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 scoped_ptr<InstantLoader> owned_loader; | 718 scoped_ptr<InstantLoader> owned_loader; |
718 TemplateURLID template_url_id = template_url ? template_url->id() : 0; | 719 TemplateURLID template_url_id = template_url ? template_url->id() : 0; |
719 InstantLoader* new_loader = | 720 InstantLoader* new_loader = |
720 loader_manager_->UpdateLoader(template_url_id, &owned_loader); | 721 loader_manager_->UpdateLoader(template_url_id, &owned_loader); |
721 | 722 |
722 new_loader->SetOmniboxBounds(omnibox_bounds_); | 723 new_loader->SetOmniboxBounds(omnibox_bounds_); |
723 if (new_loader->Update(tab_contents_, template_url, url, transition_type, | 724 if (new_loader->Update(tab_contents_, template_url, url, transition_type, |
724 user_text, verbatim, suggested_text)) { | 725 user_text, verbatim, suggested_text)) { |
725 show_timer_.Stop(); | 726 show_timer_.Stop(); |
726 if (!new_loader->http_status_ok()) { | 727 if (!new_loader->http_status_ok()) { |
727 show_timer_.Start( | 728 show_timer_.Start(FROM_HERE, |
728 base::TimeDelta::FromMilliseconds(kShowDelayMS), | 729 base::TimeDelta::FromMilliseconds(kShowDelayMS), |
729 this, &InstantController::ShowTimerFired); | 730 this, &InstantController::ShowTimerFired); |
730 } | 731 } |
731 } | 732 } |
732 UpdateDisplayableLoader(); | 733 UpdateDisplayableLoader(); |
733 } | 734 } |
734 | 735 |
735 InstantController::PreviewCondition InstantController::GetPreviewConditionFor( | 736 InstantController::PreviewCondition InstantController::GetPreviewConditionFor( |
736 const AutocompleteMatch& match, const TemplateURL** template_url) { | 737 const AutocompleteMatch& match, const TemplateURL** template_url) { |
737 const TemplateURL* t_url = match.template_url; | 738 const TemplateURL* t_url = match.template_url; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 if (destroy_factory_.empty()) { | 793 if (destroy_factory_.empty()) { |
793 MessageLoop::current()->PostTask( | 794 MessageLoop::current()->PostTask( |
794 FROM_HERE, destroy_factory_.NewRunnableMethod( | 795 FROM_HERE, destroy_factory_.NewRunnableMethod( |
795 &InstantController::DestroyLoaders)); | 796 &InstantController::DestroyLoaders)); |
796 } | 797 } |
797 } | 798 } |
798 | 799 |
799 void InstantController::DestroyLoaders() { | 800 void InstantController::DestroyLoaders() { |
800 loaders_to_destroy_.reset(); | 801 loaders_to_destroy_.reset(); |
801 } | 802 } |
OLD | NEW |