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

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

Issue 1910693002: Avoid the long merge session throttle interstitial page for NTP on Chrome OS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « chrome/browser/chromeos/login/signin/merge_session_throttling_utils.cc ('k') | no next file » | 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/search/search.h" 5 #include "chrome/browser/search/search.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_split.h" 13 #include "base/strings/string_split.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/chromeos/login/signin/merge_session_throttling_utils.h"
Marc Treib 2016/04/21 08:32:12 This should go into an #if defined(OS_CHROMEOS) bl
afakhry 2016/04/21 17:04:09 Done.
16 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/profiles/profile_manager.h" 18 #include "chrome/browser/profiles/profile_manager.h"
18 #include "chrome/browser/search/instant_service.h" 19 #include "chrome/browser/search/instant_service.h"
19 #include "chrome/browser/search/instant_service_factory.h" 20 #include "chrome/browser/search/instant_service_factory.h"
20 #include "chrome/browser/search_engines/template_url_service_factory.h" 21 #include "chrome/browser/search_engines/template_url_service_factory.h"
21 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" 22 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h"
22 #include "chrome/browser/ui/browser.h" 23 #include "chrome/browser/ui/browser.h"
23 #include "chrome/browser/ui/browser_instant_controller.h" 24 #include "chrome/browser/ui/browser_instant_controller.h"
24 #include "chrome/browser/ui/search/instant_search_prerenderer.h" 25 #include "chrome/browser/ui/search/instant_search_prerenderer.h"
25 #include "chrome/common/chrome_switches.h" 26 #include "chrome/common/chrome_switches.h"
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 return NEW_TAB_URL_INCOGNITO; 233 return NEW_TAB_URL_INCOGNITO;
233 if (!new_tab_url.is_valid()) 234 if (!new_tab_url.is_valid())
234 return NEW_TAB_URL_NOT_SET; 235 return NEW_TAB_URL_NOT_SET;
235 if (!new_tab_url.SchemeIsCryptographic()) 236 if (!new_tab_url.SchemeIsCryptographic())
236 return NEW_TAB_URL_INSECURE; 237 return NEW_TAB_URL_INSECURE;
237 if (!IsURLAllowedForSupervisedUser(new_tab_url, profile)) 238 if (!IsURLAllowedForSupervisedUser(new_tab_url, profile))
238 return NEW_TAB_URL_BLOCKED; 239 return NEW_TAB_URL_BLOCKED;
239 return NEW_TAB_URL_VALID; 240 return NEW_TAB_URL_VALID;
240 } 241 }
241 242
243 #if defined(OS_CHROMEOS)
244
245 // On Chrome OS, if the session hasn't merged yet, we need to avoid loading the
246 // remote NTP because that will trigger showing the merge session throttle
247 // interstitial page, which can show for 5+ seconds. crbug.com/591530.
248 bool ShouldShowLocalNtpWhileMergeSessionInProgress(const GURL& url,
249 Profile* profile) {
250 if (!merge_session_throttling_utils::ShouldDelayUrl(url) ||
Marc Treib 2016/04/21 08:32:12 I'd move the "#if defined(OS_CHROMEOS)" here so th
afakhry 2016/04/21 17:04:09 Done.
251 !merge_session_throttling_utils::ShouldDelayRequest(profile)) {
252 return false;
253 }
254
255 return true;
256 }
257
258 #endif // defined(OS_CHROMEOS)
259
242 // Used to look up the URL to use for the New Tab page. Also tracks how we 260 // Used to look up the URL to use for the New Tab page. Also tracks how we
243 // arrived at that URL so it can be logged with UMA. 261 // arrived at that URL so it can be logged with UMA.
244 struct NewTabURLDetails { 262 struct NewTabURLDetails {
245 NewTabURLDetails(const GURL& url, NewTabURLState state) 263 NewTabURLDetails(const GURL& url, NewTabURLState state)
246 : url(url), state(state) {} 264 : url(url), state(state) {}
247 265
248 static NewTabURLDetails ForProfile(Profile* profile) { 266 static NewTabURLDetails ForProfile(Profile* profile) {
249 const GURL local_url(chrome::kChromeSearchLocalNtpUrl); 267 const GURL local_url(chrome::kChromeSearchLocalNtpUrl);
250 268
251 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 269 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
252 if (command_line->HasSwitch(switches::kForceLocalNtp)) 270 if (command_line->HasSwitch(switches::kForceLocalNtp))
253 return NewTabURLDetails(local_url, NEW_TAB_URL_VALID); 271 return NewTabURLDetails(local_url, NEW_TAB_URL_VALID);
254 272
255 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); 273 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile);
256 if (!profile || !template_url) 274 if (!profile || !template_url)
257 return NewTabURLDetails(local_url, NEW_TAB_URL_BAD); 275 return NewTabURLDetails(local_url, NEW_TAB_URL_BAD);
258 276
259 GURL search_provider_url = TemplateURLRefToGURL( 277 GURL search_provider_url = TemplateURLRefToGURL(
260 template_url->new_tab_url_ref(), UIThreadSearchTermsData(profile), 278 template_url->new_tab_url_ref(), UIThreadSearchTermsData(profile),
261 false, false); 279 false, false);
280
281 #if defined(OS_CHROMEOS)
282 if (ShouldShowLocalNtpWhileMergeSessionInProgress(search_provider_url,
283 profile)) {
284 // Force load the local NTP if the merge session is not complete.
285 return NewTabURLDetails(local_url, NEW_TAB_URL_VALID);
286 }
287 #endif // defined(OS_CHROMEOS)
288
262 NewTabURLState state = IsValidNewTabURL(profile, search_provider_url); 289 NewTabURLState state = IsValidNewTabURL(profile, search_provider_url);
263 switch (state) { 290 switch (state) {
264 case NEW_TAB_URL_VALID: 291 case NEW_TAB_URL_VALID:
265 // We can use the search provider's page. 292 // We can use the search provider's page.
266 return NewTabURLDetails(search_provider_url, state); 293 return NewTabURLDetails(search_provider_url, state);
267 case NEW_TAB_URL_INCOGNITO: 294 case NEW_TAB_URL_INCOGNITO:
268 // Incognito has its own New Tab. 295 // Incognito has its own New Tab.
269 return NewTabURLDetails(GURL(), state); 296 return NewTabURLDetails(GURL(), state);
270 default: 297 default:
271 // Use the local New Tab otherwise. 298 // Use the local New Tab otherwise.
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 kUseAltInstantURL, false, flags); 611 kUseAltInstantURL, false, flags);
585 } 612 }
586 613
587 bool ShouldUseSearchPathForInstant() { 614 bool ShouldUseSearchPathForInstant() {
588 FieldTrialFlags flags; 615 FieldTrialFlags flags;
589 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( 616 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault(
590 kUseSearchPathForInstant, false, flags); 617 kUseSearchPathForInstant, false, flags);
591 } 618 }
592 619
593 } // namespace search 620 } // namespace search
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/signin/merge_session_throttling_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698