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

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: 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 785 matching lines...) Expand 10 before | Expand all | Expand 10 after
1077 1083
1078 // Preload the Instant NTP. 1084 // Preload the Instant NTP.
1079 ntp_.reset(); 1085 ntp_.reset();
1080 if (extended_enabled() && preload_ntp_) 1086 if (extended_enabled() && preload_ntp_)
1081 ResetNTP(GetInstantURL()); 1087 ResetNTP(GetInstantURL());
1082 1088
1083 if (instant_tab_) 1089 if (instant_tab_)
1084 instant_tab_->SetDisplayInstantResults(instant_enabled_); 1090 instant_tab_->SetDisplayInstantResults(instant_enabled_);
1085 } 1091 }
1086 1092
1087 void InstantController::ThemeChanged(const ThemeBackgroundInfo& theme_info) { 1093 void InstantController::ThemeInfoChanged(
1094 const ThemeBackgroundInfo& theme_info) {
1088 if (!extended_enabled()) 1095 if (!extended_enabled())
1089 return; 1096 return;
1090 1097
1091 if (overlay_) 1098 if (overlay_)
1092 overlay_->SendThemeBackgroundInfo(theme_info); 1099 overlay_->SendThemeBackgroundInfo(theme_info);
1093 if (ntp_) 1100 if (ntp_)
1094 ntp_->SendThemeBackgroundInfo(theme_info); 1101 ntp_->SendThemeBackgroundInfo(theme_info);
1095 if (instant_tab_) 1102 if (instant_tab_)
1096 instant_tab_->SendThemeBackgroundInfo(theme_info); 1103 instant_tab_->SendThemeBackgroundInfo(theme_info);
1097 } 1104 }
(...skipping 19 matching lines...) Expand all
1117 // If the overlay is showing or the omnibox has focus, don't refresh the 1124 // If the overlay is showing or the omnibox has focus, don't refresh the
1118 // overlay. It will get refreshed the next time the overlay is hidden or the 1125 // overlay. It will get refreshed the next time the overlay is hidden or the
1119 // omnibox loses focus. 1126 // omnibox loses focus.
1120 if (omnibox_focus_state_ == OMNIBOX_FOCUS_NONE && model_.mode().is_default()) 1127 if (omnibox_focus_state_ == OMNIBOX_FOCUS_NONE && model_.mode().is_default())
1121 ResetOverlay(GetInstantURL()); 1128 ResetOverlay(GetInstantURL());
1122 } 1129 }
1123 1130
1124 void InstantController::OverlayLoadCompletedMainFrame() { 1131 void InstantController::OverlayLoadCompletedMainFrame() {
1125 if (overlay_->supports_instant()) 1132 if (overlay_->supports_instant())
1126 return; 1133 return;
1127 InstantService* instant_service = 1134 InstantService* instant_service = GetInstantService();
1128 InstantServiceFactory::GetForProfile(browser_->profile());
1129 content::WebContents* contents = overlay_->contents(); 1135 content::WebContents* contents = overlay_->contents();
1130 DCHECK(contents); 1136 DCHECK(contents);
1131 if (instant_service->IsInstantProcess( 1137 if (instant_service->IsInstantProcess(
1132 contents->GetRenderProcessHost()->GetID())) { 1138 contents->GetRenderProcessHost()->GetID())) {
1133 return; 1139 return;
1134 } 1140 }
1135 InstantSupportDetermined(contents, false); 1141 InstantSupportDetermined(contents, false);
1136 } 1142 }
1137 1143
1138 void InstantController::LogDebugEvent(const std::string& info) const { 1144 void InstantController::LogDebugEvent(const std::string& info) const {
1139 DVLOG(1) << info; 1145 DVLOG(1) << info;
1140 1146
1141 debug_events_.push_front(std::make_pair( 1147 debug_events_.push_front(std::make_pair(
1142 base::Time::Now().ToInternalValue(), info)); 1148 base::Time::Now().ToInternalValue(), info));
1143 static const size_t kMaxDebugEventSize = 2000; 1149 static const size_t kMaxDebugEventSize = 2000;
1144 if (debug_events_.size() > kMaxDebugEventSize) 1150 if (debug_events_.size() > kMaxDebugEventSize)
1145 debug_events_.pop_back(); 1151 debug_events_.pop_back();
1146 } 1152 }
1147 1153
1148 void InstantController::ClearDebugEvents() { 1154 void InstantController::ClearDebugEvents() {
1149 debug_events_.clear(); 1155 debug_events_.clear();
1150 } 1156 }
1151 1157
1152 void InstantController::UpdateMostVisitedItems() { 1158 void InstantController::UpdateMostVisitedItems() {
1153 InstantService* instant_service = 1159 InstantService* instant_service = GetInstantService();
1154 InstantServiceFactory::GetForProfile(profile());
1155 if (!instant_service) 1160 if (!instant_service)
1156 return; 1161 return;
1157 1162
1158 std::vector<InstantMostVisitedItem> items; 1163 std::vector<InstantMostVisitedItem> items;
1159 instant_service->GetCurrentMostVisitedItems(&items); 1164 instant_service->GetCurrentMostVisitedItems(&items);
1160 1165
1161 if (overlay_ && GetOverlayContents() && 1166 if (overlay_ && GetOverlayContents() &&
1162 SearchTabHelper::FromWebContents(overlay_->contents())-> 1167 SearchTabHelper::FromWebContents(overlay_->contents())->
1163 UpdateLastKnownMostVisitedItems(items)) { 1168 UpdateLastKnownMostVisitedItems(items)) {
1164 overlay_->SendMostVisitedItems(items); 1169 overlay_->SendMostVisitedItems(items);
(...skipping 12 matching lines...) Expand all
1177 } 1182 }
1178 1183
1179 content::NotificationService::current()->Notify( 1184 content::NotificationService::current()->Notify(
1180 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS, 1185 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS,
1181 content::Source<InstantController>(this), 1186 content::Source<InstantController>(this),
1182 content::NotificationService::NoDetails()); 1187 content::NotificationService::NoDetails());
1183 } 1188 }
1184 1189
1185 void InstantController::DeleteMostVisitedItem(const GURL& url) { 1190 void InstantController::DeleteMostVisitedItem(const GURL& url) {
1186 DCHECK(!url.is_empty()); 1191 DCHECK(!url.is_empty());
1187 InstantService* instant_service = 1192 InstantService* instant_service = GetInstantService();
1188 InstantServiceFactory::GetForProfile(profile());
1189 if (!instant_service) 1193 if (!instant_service)
1190 return; 1194 return;
1191 1195
1192 instant_service->DeleteMostVisitedItem(url); 1196 instant_service->DeleteMostVisitedItem(url);
1193 } 1197 }
1194 1198
1195 void InstantController::UndoMostVisitedDeletion(const GURL& url) { 1199 void InstantController::UndoMostVisitedDeletion(const GURL& url) {
1196 DCHECK(!url.is_empty()); 1200 DCHECK(!url.is_empty());
1197 InstantService* instant_service = 1201 InstantService* instant_service = GetInstantService();
1198 InstantServiceFactory::GetForProfile(profile());
1199 if (!instant_service) 1202 if (!instant_service)
1200 return; 1203 return;
1201 1204
1202 instant_service->UndoMostVisitedDeletion(url); 1205 instant_service->UndoMostVisitedDeletion(url);
1203 } 1206 }
1204 1207
1205 void InstantController::UndoAllMostVisitedDeletions() { 1208 void InstantController::UndoAllMostVisitedDeletions() {
1206 InstantService* instant_service = 1209 InstantService* instant_service = GetInstantService();
1207 InstantServiceFactory::GetForProfile(profile());
1208 if (!instant_service) 1210 if (!instant_service)
1209 return; 1211 return;
1210 1212
1211 instant_service->UndoAllMostVisitedDeletions(); 1213 instant_service->UndoAllMostVisitedDeletions();
1212 } 1214 }
1213 1215
1214 Profile* InstantController::profile() const { 1216 Profile* InstantController::profile() const {
1215 return browser_->profile(); 1217 return browser_->profile();
1216 } 1218 }
1217 1219
(...skipping 10 matching lines...) Expand all
1228 } 1230 }
1229 1231
1230 // TODO(shishir): We assume that the WebContent's current RenderViewHost is the 1232 // TODO(shishir): We assume that the WebContent's current RenderViewHost is the
1231 // RenderViewHost being created which is not always true. Fix this. 1233 // RenderViewHost being created which is not always true. Fix this.
1232 void InstantController::InstantPageRenderViewCreated( 1234 void InstantController::InstantPageRenderViewCreated(
1233 const content::WebContents* contents) { 1235 const content::WebContents* contents) {
1234 if (!extended_enabled()) 1236 if (!extended_enabled())
1235 return; 1237 return;
1236 1238
1237 // Update theme info so that the page picks it up. 1239 // Update theme info so that the page picks it up.
1238 browser_->UpdateThemeInfo(); 1240 InstantService* instant_service = GetInstantService();
1241 if (instant_service)
1242 instant_service->UpdateThemeInfo();
1239 1243
1240 // Ensure the searchbox API has the correct initial state. 1244 // Ensure the searchbox API has the correct initial state.
1241 if (IsContentsFrom(overlay(), contents)) { 1245 if (IsContentsFrom(overlay(), contents)) {
1242 overlay_->SetDisplayInstantResults(instant_enabled_); 1246 overlay_->SetDisplayInstantResults(instant_enabled_);
1243 overlay_->FocusChanged(omnibox_focus_state_, omnibox_focus_change_reason_); 1247 overlay_->FocusChanged(omnibox_focus_state_, omnibox_focus_change_reason_);
1244 overlay_->SetOmniboxBounds(omnibox_bounds_); 1248 overlay_->SetOmniboxBounds(omnibox_bounds_);
1245 overlay_->InitializeFonts(); 1249 overlay_->InitializeFonts();
1246 } else if (IsContentsFrom(ntp(), contents)) { 1250 } else if (IsContentsFrom(ntp(), contents)) {
1247 ntp_->SetDisplayInstantResults(instant_enabled_); 1251 ntp_->SetDisplayInstantResults(instant_enabled_);
1248 ntp_->SetOmniboxBounds(omnibox_bounds_); 1252 ntp_->SetOmniboxBounds(omnibox_bounds_);
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
1676 1680
1677 // Hide the |overlay_| since we are now using |instant_tab_| instead. 1681 // Hide the |overlay_| since we are now using |instant_tab_| instead.
1678 HideOverlay(); 1682 HideOverlay();
1679 } else { 1683 } else {
1680 instant_tab_.reset(); 1684 instant_tab_.reset();
1681 } 1685 }
1682 } 1686 }
1683 1687
1684 void InstantController::UpdateInfoForInstantTab() { 1688 void InstantController::UpdateInfoForInstantTab() {
1685 if (instant_tab_) { 1689 if (instant_tab_) {
1686 browser_->UpdateThemeInfo(); 1690 // Update theme details.
1691 InstantService* instant_service = GetInstantService();
1692 if (instant_service)
1693 instant_service->UpdateThemeInfo();
1694
1687 instant_tab_->SetDisplayInstantResults(instant_enabled_); 1695 instant_tab_->SetDisplayInstantResults(instant_enabled_);
1688 instant_tab_->SetOmniboxBounds(omnibox_bounds_); 1696 instant_tab_->SetOmniboxBounds(omnibox_bounds_);
1689 instant_tab_->InitializeFonts(); 1697 instant_tab_->InitializeFonts();
1690 UpdateMostVisitedItems(); 1698 UpdateMostVisitedItems();
1691 instant_tab_->FocusChanged(omnibox_focus_state_, 1699 instant_tab_->FocusChanged(omnibox_focus_state_,
1692 omnibox_focus_change_reason_); 1700 omnibox_focus_change_reason_);
1693 instant_tab_->SetInputInProgress(IsInputInProgress()); 1701 instant_tab_->SetInputInProgress(IsInputInProgress());
1694 } 1702 }
1695 } 1703 }
1696 1704
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1911 bool js_webkit_enabled = profile()->GetPrefs()->GetBoolean( 1919 bool js_webkit_enabled = profile()->GetPrefs()->GetBoolean(
1912 prefs::kWebKitJavascriptEnabled); 1920 prefs::kWebKitJavascriptEnabled);
1913 return js_content_enabled && js_webkit_enabled; 1921 return js_content_enabled && js_webkit_enabled;
1914 } 1922 }
1915 1923
1916 bool InstantController::InStartup() const { 1924 bool InstantController::InStartup() const {
1917 // TODO(shishir): This is not completely reliable. Find a better way to detect 1925 // TODO(shishir): This is not completely reliable. Find a better way to detect
1918 // startup time. 1926 // startup time.
1919 return !browser_->GetActiveWebContents(); 1927 return !browser_->GetActiveWebContents();
1920 } 1928 }
1929
1930 InstantService* InstantController::GetInstantService() const {
1931 return InstantServiceFactory::GetForProfile(profile());
1932 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698