Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <iterator> | 7 #include <iterator> |
| 8 | 8 |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 953 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 964 return; | 964 return; |
| 965 | 965 |
| 966 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( | 966 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( |
| 967 "SearchModeChanged: [origin:mode] %d:%d to %d:%d", old_mode.origin, | 967 "SearchModeChanged: [origin:mode] %d:%d to %d:%d", old_mode.origin, |
| 968 old_mode.mode, new_mode.origin, new_mode.mode)); | 968 old_mode.mode, new_mode.origin, new_mode.mode)); |
| 969 | 969 |
| 970 search_mode_ = new_mode; | 970 search_mode_ = new_mode; |
| 971 if (!new_mode.is_search_suggestions()) | 971 if (!new_mode.is_search_suggestions()) |
| 972 HideOverlay(); | 972 HideOverlay(); |
| 973 | 973 |
| 974 ResetInstantTab(); | 974 // Now that the overlay is hidden, try |instant_tab_| again. |
|
samarth
2013/05/08 02:38:48
Let's take out all the instant tab resetting logic
kmadhusu
2013/05/09 02:40:40
Done.
| |
| 975 if (!instant_tab_) | |
| 976 ResetInstantTab(); | |
| 975 } | 977 } |
| 976 | 978 |
| 977 void InstantController::ActiveTabChanged() { | 979 void InstantController::ActiveTabChanged() { |
| 978 if (!extended_enabled_ && !instant_enabled_) | 980 if (!extended_enabled_ && !instant_enabled_) |
| 979 return; | 981 return; |
| 980 | 982 |
| 981 LOG_INSTANT_DEBUG_EVENT(this, "ActiveTabChanged"); | 983 LOG_INSTANT_DEBUG_EVENT(this, "ActiveTabChanged"); |
| 982 | 984 |
| 983 // When switching tabs, always hide the overlay. | 985 // When switching tabs, always hide the overlay. |
| 984 HideOverlay(); | 986 HideOverlay(); |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1516 | 1518 |
| 1517 void InstantController::ResetInstantTab() { | 1519 void InstantController::ResetInstantTab() { |
| 1518 // Do not wire up the InstantTab in Incognito, to prevent it from sending data | 1520 // Do not wire up the InstantTab in Incognito, to prevent it from sending data |
| 1519 // to the page. | 1521 // to the page. |
| 1520 if (!search_mode_.is_origin_default() && | 1522 if (!search_mode_.is_origin_default() && |
| 1521 !browser_->profile()->IsOffTheRecord()) { | 1523 !browser_->profile()->IsOffTheRecord()) { |
| 1522 content::WebContents* active_tab = browser_->GetActiveWebContents(); | 1524 content::WebContents* active_tab = browser_->GetActiveWebContents(); |
| 1523 if (!instant_tab_ || active_tab != instant_tab_->contents()) { | 1525 if (!instant_tab_ || active_tab != instant_tab_->contents()) { |
| 1524 instant_tab_.reset(new InstantTab(this)); | 1526 instant_tab_.reset(new InstantTab(this)); |
| 1525 instant_tab_->Init(active_tab); | 1527 instant_tab_->Init(active_tab); |
| 1526 UpdateInfoForInstantTab(); | 1528 // Note that |instant_tab_| may have gotten reset in Init() if it's |
| 1527 use_tab_for_suggestions_ = true; | 1529 // already known to not support instant. |
| 1530 if (instant_tab_) { | |
| 1531 UpdateInfoForInstantTab(); | |
| 1532 use_tab_for_suggestions_ = true; | |
| 1533 } else { | |
| 1534 use_tab_for_suggestions_ = false; | |
| 1535 } | |
| 1528 } | 1536 } |
| 1529 | 1537 |
| 1530 // Hide the |overlay_| since we are now using |instant_tab_| instead. | 1538 if (instant_tab_) { |
| 1531 HideOverlay(); | 1539 // Hide the |overlay_| since we are now using |instant_tab_| instead. |
| 1540 HideOverlay(); | |
| 1541 } | |
| 1532 } else { | 1542 } else { |
| 1533 instant_tab_.reset(); | 1543 instant_tab_.reset(); |
| 1534 } | 1544 } |
| 1535 } | 1545 } |
| 1536 | 1546 |
| 1537 void InstantController::UpdateInfoForInstantTab() { | 1547 void InstantController::UpdateInfoForInstantTab() { |
| 1538 if (instant_tab_) { | 1548 if (instant_tab_) { |
| 1539 browser_->UpdateThemeInfo(); | 1549 browser_->UpdateThemeInfo(); |
| 1540 instant_tab_->SetDisplayInstantResults(instant_enabled_); | 1550 instant_tab_->SetDisplayInstantResults(instant_enabled_); |
| 1541 instant_tab_->SetOmniboxBounds(omnibox_bounds_); | 1551 instant_tab_->SetOmniboxBounds(omnibox_bounds_); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1582 "Show: height=%d units=%d", height, units)); | 1592 "Show: height=%d units=%d", height, units)); |
| 1583 | 1593 |
| 1584 // Must have updated omnibox after the last HideOverlay() to show suggestions. | 1594 // Must have updated omnibox after the last HideOverlay() to show suggestions. |
| 1585 if (!allow_overlay_to_show_search_suggestions_) | 1595 if (!allow_overlay_to_show_search_suggestions_) |
| 1586 return; | 1596 return; |
| 1587 | 1597 |
| 1588 // The page is trying to hide itself. Hide explicitly (i.e., don't use | 1598 // The page is trying to hide itself. Hide explicitly (i.e., don't use |
| 1589 // HideOverlay()) so that it can change its mind. | 1599 // HideOverlay()) so that it can change its mind. |
| 1590 if (height == 0) { | 1600 if (height == 0) { |
| 1591 model_.SetOverlayState(SearchMode(), 0, INSTANT_SIZE_PERCENT); | 1601 model_.SetOverlayState(SearchMode(), 0, INSTANT_SIZE_PERCENT); |
| 1592 if (instant_tab_) | 1602 if (instant_tab_) { |
| 1593 use_tab_for_suggestions_ = true; | 1603 use_tab_for_suggestions_ = true; |
| 1604 } else { | |
| 1605 // Now that the overlay is hidden, try |instant_tab_| again. | |
| 1606 ResetInstantTab(); | |
| 1607 } | |
| 1594 return; | 1608 return; |
| 1595 } | 1609 } |
| 1596 | 1610 |
| 1597 // If the overlay is being shown for the first time since the user started | 1611 // If the overlay is being shown for the first time since the user started |
| 1598 // typing, record a histogram value. | 1612 // typing, record a histogram value. |
| 1599 if (!first_interaction_time_.is_null() && model_.mode().is_default()) { | 1613 if (!first_interaction_time_.is_null() && model_.mode().is_default()) { |
| 1600 base::TimeDelta delta = base::Time::Now() - first_interaction_time_; | 1614 base::TimeDelta delta = base::Time::Now() - first_interaction_time_; |
| 1601 UMA_HISTOGRAM_TIMES("Instant.TimeToFirstShow", delta); | 1615 UMA_HISTOGRAM_TIMES("Instant.TimeToFirstShow", delta); |
| 1602 } | 1616 } |
| 1603 | 1617 |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1806 | 1820 |
| 1807 result->transition = match.transition; | 1821 result->transition = match.transition; |
| 1808 result->relevance = match.relevance; | 1822 result->relevance = match.relevance; |
| 1809 result->autocomplete_match_index = autocomplete_match_index; | 1823 result->autocomplete_match_index = autocomplete_match_index; |
| 1810 | 1824 |
| 1811 DVLOG(1) << " " << result->relevance << " " << result->type << " " | 1825 DVLOG(1) << " " << result->relevance << " " << result->type << " " |
| 1812 << result->provider << " " << result->destination_url << " '" | 1826 << result->provider << " " << result->destination_url << " '" |
| 1813 << result->description << "' '" << result->search_query << "' " | 1827 << result->description << "' '" << result->search_query << "' " |
| 1814 << result->transition << " " << result->autocomplete_match_index; | 1828 << result->transition << " " << result->autocomplete_match_index; |
| 1815 } | 1829 } |
| OLD | NEW |