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

Unified Diff: trunk/src/chrome/browser/search/search.cc

Issue 135903002: Revert 244407 "InstantExtended: remove dead code related to the ..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « trunk/src/chrome/browser/search/search.h ('k') | trunk/src/chrome/browser/search/search_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: trunk/src/chrome/browser/search/search.cc
===================================================================
--- trunk/src/chrome/browser/search/search.cc (revision 244428)
+++ trunk/src/chrome/browser/search/search.cc (working copy)
@@ -7,6 +7,7 @@
#include "base/command_line.h"
#include "base/metrics/field_trial.h"
#include "base/prefs/pref_service.h"
+#include "base/rand_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/utf_string_conversions.h"
@@ -58,7 +59,13 @@
const uint64 kEmbeddedPageVersionDefault = 2;
#endif
+// The staleness timeout can be set (in seconds) via this config.
+const char kStalePageTimeoutFlagName[] = "stale";
+const int kStalePageTimeoutDefault = 3 * 3600; // 3 hours.
+
const char kHideVerbatimFlagName[] = "hide_verbatim";
+const char kShowNtpFlagName[] = "show_ntp";
+const char kUseCacheableNTP[] = "use_cacheable_ntp";
const char kPrefetchSearchResultsFlagName[] = "prefetch_results";
const char kPrefetchSearchResultsOnSRP[] = "prefetch_results_srp";
const char kDisplaySearchButtonFlagName[] = "display_search_button";
@@ -388,9 +395,14 @@
if (entry->GetURL() == GetLocalInstantURL(profile))
return true;
- GURL new_tab_url(GetNewTabPageURL(profile));
- return new_tab_url.is_valid() &&
- search::MatchesOriginAndPath(entry->GetURL(), new_tab_url);
+ if (ShouldUseCacheableNTP()) {
+ GURL new_tab_url(GetNewTabPageURL(profile));
+ return new_tab_url.is_valid() &&
+ search::MatchesOriginAndPath(entry->GetURL(), new_tab_url);
+ }
+
+ return IsInstantURL(entry->GetVirtualURL(), profile) &&
+ GetSearchTermsImpl(contents, entry).empty();
}
bool IsSuggestPrefEnabled(Profile* profile) {
@@ -446,6 +458,9 @@
}
GURL GetNewTabPageURL(Profile* profile) {
+ if (!ShouldUseCacheableNTP())
+ return GURL();
+
if (!profile || profile->IsOffTheRecord())
return GURL();
@@ -473,6 +488,9 @@
}
bool ShouldPrefetchSearchResults() {
+ if (!ShouldUseCacheableNTP())
+ return false;
+
FieldTrialFlags flags;
return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault(
kPrefetchSearchResultsFlagName, false, flags);
@@ -488,6 +506,23 @@
kHideVerbatimFlagName, false, flags);
}
+bool ShouldUseCacheableNTP() {
+ FieldTrialFlags flags;
+ return !GetFieldTrialInfo(&flags) || GetBoolValueForFlagWithDefault(
+ kUseCacheableNTP, true, flags);
+}
+
+bool ShouldShowInstantNTP() {
+ // If using the cacheable NTP, load the NTP directly instead of preloading its
+ // contents using InstantNTP.
+ if (ShouldUseCacheableNTP())
+ return false;
+
+ FieldTrialFlags flags;
+ return !GetFieldTrialInfo(&flags) ||
+ GetBoolValueForFlagWithDefault(kShowNtpFlagName, true, flags);
+}
+
DisplaySearchButtonConditions GetDisplaySearchButtonConditions() {
const CommandLine* cl = CommandLine::ForCurrentProcess();
if (cl->HasSwitch(switches::kDisableSearchButtonInOmnibox)) {
@@ -570,6 +605,43 @@
return effective_url;
}
+int GetInstantLoaderStalenessTimeoutSec() {
+ int timeout_sec = kStalePageTimeoutDefault;
+ FieldTrialFlags flags;
+ if (GetFieldTrialInfo(&flags)) {
+ timeout_sec = GetUInt64ValueForFlagWithDefault(kStalePageTimeoutFlagName,
+ kStalePageTimeoutDefault,
+ flags);
+ }
+
+ // Require a minimum 5 minute timeout.
+ if (timeout_sec < 0 || (timeout_sec > 0 && timeout_sec < 300))
+ timeout_sec = kStalePageTimeoutDefault;
+
+ // Randomize by upto 15% either side.
+ timeout_sec = base::RandInt(timeout_sec * 0.85, timeout_sec * 1.15);
+
+ return timeout_sec;
+}
+
+bool IsPreloadedInstantExtendedNTP(const content::WebContents* contents) {
+ if (!IsInstantExtendedAPIEnabled())
+ return false;
+
+ ProfileManager* profile_manager = g_browser_process->profile_manager();
+ if (!profile_manager)
+ return false; // The profile manager can be NULL while testing.
+
+ const std::vector<Profile*>& profiles = profile_manager->GetLoadedProfiles();
+ for (size_t i = 0; i < profiles.size(); ++i) {
+ const InstantService* instant_service =
+ InstantServiceFactory::GetForProfile(profiles[i]);
+ if (instant_service && instant_service->GetNTPContents() == contents)
+ return true;
+ }
+ return false;
+}
+
bool HandleNewTabURLRewrite(GURL* url,
content::BrowserContext* browser_context) {
if (!IsInstantExtendedAPIEnabled())
« no previous file with comments | « trunk/src/chrome/browser/search/search.h ('k') | trunk/src/chrome/browser/search/search_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698