| 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/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/feature_list.h" | 10 #include "base/feature_list.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 #endif | 45 #endif |
| 46 | 46 |
| 47 #if defined(OS_CHROMEOS) | 47 #if defined(OS_CHROMEOS) |
| 48 #include "chrome/browser/chromeos/login/signin/merge_session_throttling_utils.h" | 48 #include "chrome/browser/chromeos/login/signin/merge_session_throttling_utils.h" |
| 49 #endif // defined(OS_CHROMEOS) | 49 #endif // defined(OS_CHROMEOS) |
| 50 | 50 |
| 51 namespace search { | 51 namespace search { |
| 52 | 52 |
| 53 namespace { | 53 namespace { |
| 54 | 54 |
| 55 // Controls whether to use the alternate Instant search base URL. This allows | |
| 56 // experimentation of Instant search. | |
| 57 const char kUseAltInstantURL[] = "use_alternate_instant_url"; | |
| 58 const char kUseSearchPathForInstant[] = "use_search_path_for_instant"; | |
| 59 const char kAltInstantURLPath[] = "search"; | |
| 60 const char kAltInstantURLQueryParams[] = "&qbp=1"; | |
| 61 | |
| 62 // Status of the New Tab URL for the default Search provider. NOTE: Used in a | 55 // Status of the New Tab URL for the default Search provider. NOTE: Used in a |
| 63 // UMA histogram so values should only be added at the end and not reordered. | 56 // UMA histogram so values should only be added at the end and not reordered. |
| 64 enum NewTabURLState { | 57 enum NewTabURLState { |
| 65 // Valid URL that should be used. | 58 // Valid URL that should be used. |
| 66 NEW_TAB_URL_VALID = 0, | 59 NEW_TAB_URL_VALID = 0, |
| 67 | 60 |
| 68 // Corrupt state (e.g. no profile or template url). | 61 // Corrupt state (e.g. no profile or template url). |
| 69 NEW_TAB_URL_BAD = 1, | 62 NEW_TAB_URL_BAD = 1, |
| 70 | 63 |
| 71 // URL should not be used because in incognito window. | 64 // URL should not be used because in incognito window. |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 if (!instant_url.SchemeIsCryptographic() && | 465 if (!instant_url.SchemeIsCryptographic() && |
| 473 !google_util::StartsWithCommandLineGoogleBaseURL(instant_url)) { | 466 !google_util::StartsWithCommandLineGoogleBaseURL(instant_url)) { |
| 474 GURL::Replacements replacements; | 467 GURL::Replacements replacements; |
| 475 replacements.SetSchemeStr(url::kHttpsScheme); | 468 replacements.SetSchemeStr(url::kHttpsScheme); |
| 476 instant_url = instant_url.ReplaceComponents(replacements); | 469 instant_url = instant_url.ReplaceComponents(replacements); |
| 477 } | 470 } |
| 478 | 471 |
| 479 if (!IsURLAllowedForSupervisedUser(instant_url, profile)) | 472 if (!IsURLAllowedForSupervisedUser(instant_url, profile)) |
| 480 return GURL(); | 473 return GURL(); |
| 481 | 474 |
| 482 if (ShouldUseAltInstantURL()) { | |
| 483 GURL::Replacements replacements; | |
| 484 const std::string path( | |
| 485 ShouldUseSearchPathForInstant() ? kAltInstantURLPath : std::string()); | |
| 486 if (!path.empty()) | |
| 487 replacements.SetPathStr(path); | |
| 488 const std::string query( | |
| 489 instant_url.query() + std::string(kAltInstantURLQueryParams)); | |
| 490 replacements.SetQueryStr(query); | |
| 491 instant_url = instant_url.ReplaceComponents(replacements); | |
| 492 } | |
| 493 return instant_url; | 475 return instant_url; |
| 494 } | 476 } |
| 495 | 477 |
| 496 // Returns URLs associated with the default search engine for |profile|. | 478 // Returns URLs associated with the default search engine for |profile|. |
| 497 std::vector<GURL> GetSearchURLs(Profile* profile) { | 479 std::vector<GURL> GetSearchURLs(Profile* profile) { |
| 498 std::vector<GURL> result; | 480 std::vector<GURL> result; |
| 499 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); | 481 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); |
| 500 if (!template_url) | 482 if (!template_url) |
| 501 return result; | 483 return result; |
| 502 for (const TemplateURLRef& ref : template_url->url_refs()) { | 484 for (const TemplateURLRef& ref : template_url->url_refs()) { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 | 573 |
| 592 InstantSupportState GetInstantSupportStateFromNavigationEntry( | 574 InstantSupportState GetInstantSupportStateFromNavigationEntry( |
| 593 const content::NavigationEntry& entry) { | 575 const content::NavigationEntry& entry) { |
| 594 base::string16 value; | 576 base::string16 value; |
| 595 if (!entry.GetExtraData(kInstantSupportStateKey, &value)) | 577 if (!entry.GetExtraData(kInstantSupportStateKey, &value)) |
| 596 return INSTANT_SUPPORT_UNKNOWN; | 578 return INSTANT_SUPPORT_UNKNOWN; |
| 597 | 579 |
| 598 return StringToInstantSupportState(value); | 580 return StringToInstantSupportState(value); |
| 599 } | 581 } |
| 600 | 582 |
| 601 bool ShouldUseAltInstantURL() { | |
| 602 FieldTrialFlags flags; | |
| 603 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( | |
| 604 kUseAltInstantURL, false, flags); | |
| 605 } | |
| 606 | |
| 607 bool ShouldUseSearchPathForInstant() { | |
| 608 FieldTrialFlags flags; | |
| 609 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( | |
| 610 kUseSearchPathForInstant, false, flags); | |
| 611 } | |
| 612 | |
| 613 } // namespace search | 583 } // namespace search |
| OLD | NEW |