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

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

Issue 16413002: Moved theme related state from BrowserInstantController to InstantService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 6 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
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 <iterator> 7 #include <iterator>
8 8
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 last_match_was_search_(false), 267 last_match_was_search_(false),
268 omnibox_focus_state_(OMNIBOX_FOCUS_NONE), 268 omnibox_focus_state_(OMNIBOX_FOCUS_NONE),
269 omnibox_focus_change_reason_(OMNIBOX_FOCUS_CHANGE_EXPLICIT), 269 omnibox_focus_change_reason_(OMNIBOX_FOCUS_CHANGE_EXPLICIT),
270 omnibox_bounds_(-1, -1, 0, 0), 270 omnibox_bounds_(-1, -1, 0, 0),
271 allow_overlay_to_show_search_suggestions_(false) { 271 allow_overlay_to_show_search_suggestions_(false) {
272 272
273 // When the InstantController lives, the InstantService should live. 273 // When the InstantController lives, the InstantService should live.
274 // InstantService sets up profile-level facilities such as the ThemeSource for 274 // InstantService sets up profile-level facilities such as the ThemeSource for
275 // the NTP. 275 // the NTP.
276 // However, in some tests, browser_ may be null. 276 // However, in some tests, browser_ may be null.
277 if (browser_) 277 if (browser_) {
278 InstantServiceFactory::GetForProfile(browser_->profile()); 278 InstantService* instant_service = GetInstantService();
279 instant_service->AddObserver(this);
280 }
279 } 281 }
280 282
281 InstantController::~InstantController() { 283 InstantController::~InstantController() {
284 if (browser_) {
285 InstantService* instant_service = GetInstantService();
286 instant_service->RemoveObserver(this);
287 }
282 } 288 }
283 289
284 void InstantController::OnAutocompleteStart() { 290 void InstantController::OnAutocompleteStart() {
285 if (UseTabForSuggestions() && instant_tab_->supports_instant()) { 291 if (UseTabForSuggestions() && instant_tab_->supports_instant()) {
286 LOG_INSTANT_DEBUG_EVENT( 292 LOG_INSTANT_DEBUG_EVENT(
287 this, "OnAutocompleteStart: using InstantTab"); 293 this, "OnAutocompleteStart: using InstantTab");
288 return; 294 return;
289 } 295 }
290 296
291 // Not using |instant_tab_|. Check if overlay is OK to use. 297 // Not using |instant_tab_|. Check if overlay is OK to use.
(...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 1089
1084 // Preload the Instant NTP. 1090 // Preload the Instant NTP.
1085 ntp_.reset(); 1091 ntp_.reset();
1086 if (extended_enabled() && preload_ntp_) 1092 if (extended_enabled() && preload_ntp_)
1087 ResetNTP(GetInstantURL()); 1093 ResetNTP(GetInstantURL());
1088 1094
1089 if (instant_tab_) 1095 if (instant_tab_)
1090 instant_tab_->sender()->SetDisplayInstantResults(instant_enabled_); 1096 instant_tab_->sender()->SetDisplayInstantResults(instant_enabled_);
1091 } 1097 }
1092 1098
1093 void InstantController::ThemeChanged(const ThemeBackgroundInfo& theme_info) { 1099 void InstantController::ThemeInfoChanged(
1100 const ThemeBackgroundInfo& theme_info) {
1094 if (!extended_enabled()) 1101 if (!extended_enabled())
1095 return; 1102 return;
1096 1103
1097 if (overlay_) 1104 if (overlay_)
1098 overlay_->sender()->SendThemeBackgroundInfo(theme_info); 1105 overlay_->sender()->SendThemeBackgroundInfo(theme_info);
1099 if (ntp_) 1106 if (ntp_)
1100 ntp_->sender()->SendThemeBackgroundInfo(theme_info); 1107 ntp_->sender()->SendThemeBackgroundInfo(theme_info);
1101 if (instant_tab_) 1108 if (instant_tab_)
1102 instant_tab_->sender()->SendThemeBackgroundInfo(theme_info); 1109 instant_tab_->sender()->SendThemeBackgroundInfo(theme_info);
1103 } 1110 }
(...skipping 19 matching lines...) Expand all
1123 // If the overlay is showing or the omnibox has focus, don't refresh the 1130 // If the overlay is showing or the omnibox has focus, don't refresh the
1124 // overlay. It will get refreshed the next time the overlay is hidden or the 1131 // overlay. It will get refreshed the next time the overlay is hidden or the
1125 // omnibox loses focus. 1132 // omnibox loses focus.
1126 if (omnibox_focus_state_ == OMNIBOX_FOCUS_NONE && model_.mode().is_default()) 1133 if (omnibox_focus_state_ == OMNIBOX_FOCUS_NONE && model_.mode().is_default())
1127 ResetOverlay(GetInstantURL()); 1134 ResetOverlay(GetInstantURL());
1128 } 1135 }
1129 1136
1130 void InstantController::OverlayLoadCompletedMainFrame() { 1137 void InstantController::OverlayLoadCompletedMainFrame() {
1131 if (!overlay_ || overlay_->supports_instant()) 1138 if (!overlay_ || overlay_->supports_instant())
1132 return; 1139 return;
1133 InstantService* instant_service = 1140 InstantService* instant_service = GetInstantService();
1134 InstantServiceFactory::GetForProfile(browser_->profile());
1135 content::WebContents* contents = overlay_->contents(); 1141 content::WebContents* contents = overlay_->contents();
1136 DCHECK(contents); 1142 DCHECK(contents);
1137 if (instant_service->IsInstantProcess( 1143 if (instant_service->IsInstantProcess(
1138 contents->GetRenderProcessHost()->GetID())) { 1144 contents->GetRenderProcessHost()->GetID())) {
1139 return; 1145 return;
1140 } 1146 }
1141 InstantSupportDetermined(contents, false); 1147 InstantSupportDetermined(contents, false);
1142 } 1148 }
1143 1149
1144 void InstantController::LogDebugEvent(const std::string& info) const { 1150 void InstantController::LogDebugEvent(const std::string& info) const {
1145 DVLOG(1) << info; 1151 DVLOG(1) << info;
1146 1152
1147 debug_events_.push_front(std::make_pair( 1153 debug_events_.push_front(std::make_pair(
1148 base::Time::Now().ToInternalValue(), info)); 1154 base::Time::Now().ToInternalValue(), info));
1149 static const size_t kMaxDebugEventSize = 2000; 1155 static const size_t kMaxDebugEventSize = 2000;
1150 if (debug_events_.size() > kMaxDebugEventSize) 1156 if (debug_events_.size() > kMaxDebugEventSize)
1151 debug_events_.pop_back(); 1157 debug_events_.pop_back();
1152 } 1158 }
1153 1159
1154 void InstantController::ClearDebugEvents() { 1160 void InstantController::ClearDebugEvents() {
1155 debug_events_.clear(); 1161 debug_events_.clear();
1156 } 1162 }
1157 1163
1158 void InstantController::UpdateMostVisitedItems() { 1164 void InstantController::UpdateMostVisitedItems() {
1159 InstantService* instant_service = 1165 InstantService* instant_service = GetInstantService();
1160 InstantServiceFactory::GetForProfile(profile());
1161 if (!instant_service) 1166 if (!instant_service)
1162 return; 1167 return;
1163 1168
1164 std::vector<InstantMostVisitedItem> items; 1169 std::vector<InstantMostVisitedItem> items;
1165 instant_service->GetCurrentMostVisitedItems(&items); 1170 instant_service->GetCurrentMostVisitedItems(&items);
1166 1171
1167 if (overlay_ && GetOverlayContents() && 1172 if (overlay_ && GetOverlayContents() &&
1168 SearchTabHelper::FromWebContents(overlay_->contents())-> 1173 SearchTabHelper::FromWebContents(overlay_->contents())->
1169 UpdateLastKnownMostVisitedItems(items)) { 1174 UpdateLastKnownMostVisitedItems(items)) {
1170 overlay_->sender()->SendMostVisitedItems(items); 1175 overlay_->sender()->SendMostVisitedItems(items);
(...skipping 12 matching lines...) Expand all
1183 } 1188 }
1184 1189
1185 content::NotificationService::current()->Notify( 1190 content::NotificationService::current()->Notify(
1186 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS, 1191 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS,
1187 content::Source<InstantController>(this), 1192 content::Source<InstantController>(this),
1188 content::NotificationService::NoDetails()); 1193 content::NotificationService::NoDetails());
1189 } 1194 }
1190 1195
1191 void InstantController::DeleteMostVisitedItem(const GURL& url) { 1196 void InstantController::DeleteMostVisitedItem(const GURL& url) {
1192 DCHECK(!url.is_empty()); 1197 DCHECK(!url.is_empty());
1193 InstantService* instant_service = 1198 InstantService* instant_service = GetInstantService();
1194 InstantServiceFactory::GetForProfile(profile());
1195 if (!instant_service) 1199 if (!instant_service)
1196 return; 1200 return;
1197 1201
1198 instant_service->DeleteMostVisitedItem(url); 1202 instant_service->DeleteMostVisitedItem(url);
1199 } 1203 }
1200 1204
1201 void InstantController::UndoMostVisitedDeletion(const GURL& url) { 1205 void InstantController::UndoMostVisitedDeletion(const GURL& url) {
1202 DCHECK(!url.is_empty()); 1206 DCHECK(!url.is_empty());
1203 InstantService* instant_service = 1207 InstantService* instant_service = GetInstantService();
1204 InstantServiceFactory::GetForProfile(profile());
1205 if (!instant_service) 1208 if (!instant_service)
1206 return; 1209 return;
1207 1210
1208 instant_service->UndoMostVisitedDeletion(url); 1211 instant_service->UndoMostVisitedDeletion(url);
1209 } 1212 }
1210 1213
1211 void InstantController::UndoAllMostVisitedDeletions() { 1214 void InstantController::UndoAllMostVisitedDeletions() {
1212 InstantService* instant_service = 1215 InstantService* instant_service = GetInstantService();
1213 InstantServiceFactory::GetForProfile(profile());
1214 if (!instant_service) 1216 if (!instant_service)
1215 return; 1217 return;
1216 1218
1217 instant_service->UndoAllMostVisitedDeletions(); 1219 instant_service->UndoAllMostVisitedDeletions();
1218 } 1220 }
1219 1221
1220 Profile* InstantController::profile() const { 1222 Profile* InstantController::profile() const {
1221 return browser_->profile(); 1223 return browser_->profile();
1222 } 1224 }
1223 1225
(...skipping 10 matching lines...) Expand all
1234 } 1236 }
1235 1237
1236 // TODO(shishir): We assume that the WebContent's current RenderViewHost is the 1238 // TODO(shishir): We assume that the WebContent's current RenderViewHost is the
1237 // RenderViewHost being created which is not always true. Fix this. 1239 // RenderViewHost being created which is not always true. Fix this.
1238 void InstantController::InstantPageRenderViewCreated( 1240 void InstantController::InstantPageRenderViewCreated(
1239 const content::WebContents* contents) { 1241 const content::WebContents* contents) {
1240 if (!extended_enabled()) 1242 if (!extended_enabled())
1241 return; 1243 return;
1242 1244
1243 // Update theme info so that the page picks it up. 1245 // Update theme info so that the page picks it up.
1244 browser_->UpdateThemeInfo(); 1246 InstantService* instant_service = GetInstantService();
1247 if (instant_service)
1248 instant_service->UpdateThemeInfo();
1245 1249
1246 // Ensure the searchbox API has the correct initial state. 1250 // Ensure the searchbox API has the correct initial state.
1247 if (IsContentsFrom(overlay(), contents)) { 1251 if (IsContentsFrom(overlay(), contents)) {
1248 overlay_->sender()->SetDisplayInstantResults(instant_enabled_); 1252 overlay_->sender()->SetDisplayInstantResults(instant_enabled_);
1249 overlay_->sender()->FocusChanged(omnibox_focus_state_, 1253 overlay_->sender()->FocusChanged(omnibox_focus_state_,
1250 omnibox_focus_change_reason_); 1254 omnibox_focus_change_reason_);
1251 overlay_->sender()->SetOmniboxBounds(omnibox_bounds_); 1255 overlay_->sender()->SetOmniboxBounds(omnibox_bounds_);
1252 overlay_->InitializeFonts(); 1256 overlay_->InitializeFonts();
1253 } else if (IsContentsFrom(ntp(), contents)) { 1257 } else if (IsContentsFrom(ntp(), contents)) {
1254 ntp_->sender()->SetDisplayInstantResults(instant_enabled_); 1258 ntp_->sender()->SetDisplayInstantResults(instant_enabled_);
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
1677 1681
1678 // Hide the |overlay_| since we are now using |instant_tab_| instead. 1682 // Hide the |overlay_| since we are now using |instant_tab_| instead.
1679 HideOverlay(); 1683 HideOverlay();
1680 } else { 1684 } else {
1681 instant_tab_.reset(); 1685 instant_tab_.reset();
1682 } 1686 }
1683 } 1687 }
1684 1688
1685 void InstantController::UpdateInfoForInstantTab() { 1689 void InstantController::UpdateInfoForInstantTab() {
1686 if (instant_tab_) { 1690 if (instant_tab_) {
1687 browser_->UpdateThemeInfo();
1688 instant_tab_->sender()->SetDisplayInstantResults(instant_enabled_); 1691 instant_tab_->sender()->SetDisplayInstantResults(instant_enabled_);
1689 instant_tab_->sender()->SetOmniboxBounds(omnibox_bounds_); 1692 instant_tab_->sender()->SetOmniboxBounds(omnibox_bounds_);
1693
1694 // Update theme details.
1695 InstantService* instant_service = GetInstantService();
1696 if (instant_service)
1697 instant_service->UpdateThemeInfo();
1698
1690 instant_tab_->InitializeFonts(); 1699 instant_tab_->InitializeFonts();
1691 UpdateMostVisitedItems(); 1700 UpdateMostVisitedItems();
1692 instant_tab_->sender()->FocusChanged(omnibox_focus_state_, 1701 instant_tab_->sender()->FocusChanged(omnibox_focus_state_,
1693 omnibox_focus_change_reason_); 1702 omnibox_focus_change_reason_);
1694 instant_tab_->sender()->SetInputInProgress(IsInputInProgress()); 1703 instant_tab_->sender()->SetInputInProgress(IsInputInProgress());
1695 } 1704 }
1696 } 1705 }
1697 1706
1698 bool InstantController::IsInputInProgress() const { 1707 bool InstantController::IsInputInProgress() const {
1699 return !search_mode_.is_ntp() && 1708 return !search_mode_.is_ntp() &&
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
1916 bool js_webkit_enabled = profile()->GetPrefs()->GetBoolean( 1925 bool js_webkit_enabled = profile()->GetPrefs()->GetBoolean(
1917 prefs::kWebKitJavascriptEnabled); 1926 prefs::kWebKitJavascriptEnabled);
1918 return js_content_enabled && js_webkit_enabled; 1927 return js_content_enabled && js_webkit_enabled;
1919 } 1928 }
1920 1929
1921 bool InstantController::InStartup() const { 1930 bool InstantController::InStartup() const {
1922 // TODO(shishir): This is not completely reliable. Find a better way to detect 1931 // TODO(shishir): This is not completely reliable. Find a better way to detect
1923 // startup time. 1932 // startup time.
1924 return !browser_->GetActiveWebContents(); 1933 return !browser_->GetActiveWebContents();
1925 } 1934 }
1935
1936 InstantService* InstantController::GetInstantService() const {
1937 return InstantServiceFactory::GetForProfile(profile());
1938 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/instant_controller.h ('k') | chrome/browser/ui/search/instant_extended_interactive_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698