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

Side by Side Diff: chrome/browser/ui/search/instant_controller.cc

Issue 14608004: Move instant support to SearchTabHelper. Fix InstantTab reset. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Guard instant-extended-only bits. Created 7 years, 7 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
« no previous file with comments | « no previous file | chrome/browser/ui/search/instant_page.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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/ui/search/instant_controller.h" 5 #include "chrome/browser/ui/search/instant_controller.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 1434 matching lines...) Expand 10 before | Expand all | Expand 10 after
1445 1445
1446 void InstantController::ResetInstantTab() { 1446 void InstantController::ResetInstantTab() {
1447 // Do not wire up the InstantTab in Incognito, to prevent it from sending data 1447 // Do not wire up the InstantTab in Incognito, to prevent it from sending data
1448 // to the page. 1448 // to the page.
1449 if (!search_mode_.is_origin_default() && 1449 if (!search_mode_.is_origin_default() &&
1450 !browser_->profile()->IsOffTheRecord()) { 1450 !browser_->profile()->IsOffTheRecord()) {
1451 content::WebContents* active_tab = browser_->GetActiveWebContents(); 1451 content::WebContents* active_tab = browser_->GetActiveWebContents();
1452 if (!instant_tab_ || active_tab != instant_tab_->contents()) { 1452 if (!instant_tab_ || active_tab != instant_tab_->contents()) {
1453 instant_tab_.reset(new InstantTab(this)); 1453 instant_tab_.reset(new InstantTab(this));
1454 instant_tab_->Init(active_tab); 1454 instant_tab_->Init(active_tab);
1455 // Update theme info for this tab. 1455 // Note that |instant_tab_| may have gotten reset in Init() if it's
1456 browser_->UpdateThemeInfo(); 1456 // already known to not support instant.
1457 instant_tab_->SetDisplayInstantResults(instant_enabled_); 1457 if (instant_tab_) {
1458 instant_tab_->SetOmniboxBounds(omnibox_bounds_); 1458 // Update theme info for this tab.
1459 instant_tab_->InitializeFonts(); 1459 browser_->UpdateThemeInfo();
1460 StartListeningToMostVisitedChanges(); 1460 instant_tab_->SetDisplayInstantResults(instant_enabled_);
1461 instant_tab_->KeyCaptureChanged( 1461 instant_tab_->SetOmniboxBounds(omnibox_bounds_);
1462 omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE); 1462 instant_tab_->InitializeFonts();
1463 StartListeningToMostVisitedChanges();
1464 instant_tab_->KeyCaptureChanged(
1465 omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE);
1466 }
1463 } 1467 }
1464 1468
1465 // Hide the |overlay_| since we are now using |instant_tab_| instead. 1469 // Hide the |overlay_| since we are now using |instant_tab_| instead.
1466 HideOverlay(); 1470 if (instant_tab_)
1471 HideOverlay();
1467 } else { 1472 } else {
1468 instant_tab_.reset(); 1473 instant_tab_.reset();
1469 } 1474 }
1470 } 1475 }
1471 1476
1472 void InstantController::HideOverlay() { 1477 void InstantController::HideOverlay() {
1473 HideInternal(); 1478 HideInternal();
1474 ReloadOverlayIfStale(); 1479 ReloadOverlayIfStale();
1475 } 1480 }
1476 1481
1477 void InstantController::HideInternal() { 1482 void InstantController::HideInternal() {
1478 LOG_INSTANT_DEBUG_EVENT(this, "Hide"); 1483 LOG_INSTANT_DEBUG_EVENT(this, "Hide");
1479 1484
1480 // If GetOverlayContents() returns NULL, either we're already in the desired 1485 // If GetOverlayContents() returns NULL, either we're already in the desired
1481 // MODE_DEFAULT state, or we're in the commit path. For the latter, don't 1486 // MODE_DEFAULT state, or we're in the commit path. For the latter, don't
1482 // change the state just yet; else we may hide the overlay unnecessarily. 1487 // change the state just yet; else we may hide the overlay unnecessarily.
1483 // Instead, the state will be set correctly after the commit is done. 1488 // Instead, the state will be set correctly after the commit is done.
1484 if (GetOverlayContents()) { 1489 if (GetOverlayContents()) {
1485 model_.SetOverlayState(SearchMode(), 0, INSTANT_SIZE_PERCENT); 1490 model_.SetOverlayState(SearchMode(), 0, INSTANT_SIZE_PERCENT);
1486 allow_overlay_to_show_search_suggestions_ = false; 1491 allow_overlay_to_show_search_suggestions_ = false;
1487 1492
1488 // Send a message asking the overlay to clear out old results. 1493 // Send a message asking the overlay to clear out old results.
1489 overlay_->Update(string16(), 0, 0, true); 1494 overlay_->Update(string16(), 0, 0, true);
1490 } 1495 }
1491 1496
1497 // Now that the overlay is hidden, try |instant_tab_| again.
1498 if (!instant_tab_)
1499 ResetInstantTab();
1500
1492 // Clear the first interaction timestamp for later use. 1501 // Clear the first interaction timestamp for later use.
1493 first_interaction_time_ = base::Time(); 1502 first_interaction_time_ = base::Time();
1494 } 1503 }
1495 1504
1496 void InstantController::ShowOverlay(int height, InstantSizeUnits units) { 1505 void InstantController::ShowOverlay(int height, InstantSizeUnits units) {
1497 // If we are on a committed search results page, the |overlay_| is not in use. 1506 // If we are on a committed search results page, the |overlay_| is not in use.
1498 if (instant_tab_) 1507 if (instant_tab_)
1499 return; 1508 return;
1500 1509
1501 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( 1510 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf(
1502 "Show: height=%d units=%d", height, units)); 1511 "Show: height=%d units=%d", height, units));
1503 1512
1504 // Must have updated omnibox after the last HideOverlay() to show suggestions. 1513 // Must have updated omnibox after the last HideOverlay() to show suggestions.
1505 if (!allow_overlay_to_show_search_suggestions_) 1514 if (!allow_overlay_to_show_search_suggestions_)
1506 return; 1515 return;
1507 1516
1508 // The page is trying to hide itself. Hide explicitly (i.e., don't use 1517 // The page is trying to hide itself. Hide explicitly (i.e., don't use
1509 // HideOverlay()) so that it can change its mind. 1518 // HideOverlay()) so that it can change its mind.
1510 if (height == 0) { 1519 if (height == 0) {
1511 model_.SetOverlayState(SearchMode(), 0, INSTANT_SIZE_PERCENT); 1520 model_.SetOverlayState(SearchMode(), 0, INSTANT_SIZE_PERCENT);
1521
1522 // Now that the overlay is hidden, try |instant_tab_| again.
1523 if (!instant_tab_)
1524 ResetInstantTab();
1525
1512 return; 1526 return;
1513 } 1527 }
1514 1528
1515 // If the overlay is being shown for the first time since the user started 1529 // If the overlay is being shown for the first time since the user started
1516 // typing, record a histogram value. 1530 // typing, record a histogram value.
1517 if (!first_interaction_time_.is_null() && model_.mode().is_default()) { 1531 if (!first_interaction_time_.is_null() && model_.mode().is_default()) {
1518 base::TimeDelta delta = base::Time::Now() - first_interaction_time_; 1532 base::TimeDelta delta = base::Time::Now() - first_interaction_time_;
1519 UMA_HISTOGRAM_TIMES("Instant.TimeToFirstShow", delta); 1533 UMA_HISTOGRAM_TIMES("Instant.TimeToFirstShow", delta);
1520 } 1534 }
1521 1535
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
1685 } 1699 }
1686 } 1700 }
1687 1701
1688 return false; 1702 return false;
1689 } 1703 }
1690 1704
1691 bool InstantController::UsingLocalPage() const { 1705 bool InstantController::UsingLocalPage() const {
1692 return (instant_tab_ && instant_tab_->IsLocal()) || 1706 return (instant_tab_ && instant_tab_->IsLocal()) ||
1693 (!instant_tab_ && overlay_ && overlay_->IsLocal()); 1707 (!instant_tab_ && overlay_ && overlay_->IsLocal());
1694 } 1708 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/search/instant_page.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698