diff options
author | cbentzel@chromium.org <cbentzel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-31 12:36:34 +0000 |
---|---|---|
committer | cbentzel@chromium.org <cbentzel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-31 12:36:34 +0000 |
commit | 503c1cfda23cf077b525ad9c21feb0d5032315f8 (patch) | |
tree | 332e59f2a68ad5cc6ab757fd75dc8d781aff274a | |
parent | 2f6bfef5c422903c0a252109fd9961a2c0ff77a8 (diff) | |
download | chromium_src-503c1cfda23cf077b525ad9c21feb0d5032315f8.zip chromium_src-503c1cfda23cf077b525ad9c21feb0d5032315f8.tar.gz chromium_src-503c1cfda23cf077b525ad9c21feb0d5032315f8.tar.bz2 |
Use the "DNS prefetch" button to control whether prerender is enabled/disabled.
This also removes prerender from about:flags.
BUG=77783
TEST=Force prerender on [via --prerender=enabled] and toggle the checkbox on/off to dynamically adjust prerender.
Review URL: http://codereview.chromium.org/6771018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79986 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/app/generated_resources.grd | 15 | ||||
-rw-r--r-- | chrome/browser/about_flags.cc | 15 | ||||
-rw-r--r-- | chrome/browser/net/net_pref_observer.cc | 10 | ||||
-rw-r--r-- | chrome/browser/net/net_pref_observer.h | 12 | ||||
-rw-r--r-- | chrome/browser/prerender/prerender_manager.cc | 13 | ||||
-rw-r--r-- | chrome/browser/prerender/prerender_manager.h | 17 | ||||
-rw-r--r-- | chrome/browser/prerender/prerender_resource_handler.cc | 2 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_impl.cc | 5 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_impl.h | 3 | ||||
-rw-r--r-- | chrome/test/testing_profile.cc | 2 |
10 files changed, 54 insertions, 40 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index 619fb0b2..895fa51 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -4131,21 +4131,6 @@ Keep your key file in a safe place. You will need it to create new versions of y <message name="IDS_FLAGS_DNS_SERVER_DESCRIPTION" desc=""> User specified DNS server, which Chrome will use for DNS resolutions rather than the system defaults. </message> - <message name="IDS_FLAGS_PAGE_PRERENDER_NAME" desc="Name of the 'Prerendering' lab."> - Web Page Prerendering. - </message> - <message name="IDS_FLAGS_PAGE_PRERENDER_DESCRIPTION" desc="Description of the 'Prerendering' lab."> - Speculatively prerenders complete webpages in the background for a faster browsing experience. The default setting of automatic can cause this feature to enable/disable randomly for testing purposes.\n - </message> - <message name="IDS_FLAGS_PAGE_PRERENDER_AUTOMATIC" desc="Option name for automatic selection in the 'Prerendering' lab"> - Automatic - </message> - <message name="IDS_FLAGS_PAGE_PRERENDER_ENABLED" desc="Option name for always enabling the 'Prerendering' lab"> - Always Enabled - </message> - <message name="IDS_FLAGS_PAGE_PRERENDER_DISABLED" desc="Option name for always disabling the 'Prerendering' lab"> - Always Disabled - </message> <message name="IDS_FLAGS_EXPERIMENTAL_EXTENSION_APIS_NAME" desc="Name of the 'Experimental Extension APIs' lab."> Experimental Extension APIs </message> diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc index d251cba..d48ae0c 100644 --- a/chrome/browser/about_flags.cc +++ b/chrome/browser/about_flags.cc @@ -41,14 +41,6 @@ const char kMediaPlayerExperimentName[] = "media-player"; const char kAdvancedFileSystemExperimentName[] = "advanced-file-system"; const char kVerticalTabsExperimentName[] = "vertical-tabs"; -const Experiment::Choice kPagePrerenderChoices[] = { - { IDS_FLAGS_PAGE_PRERENDER_AUTOMATIC, "", "" }, - { IDS_FLAGS_PAGE_PRERENDER_ENABLED, - switches::kPrerender, switches::kPrerenderSwitchValueEnabled }, - { IDS_FLAGS_PAGE_PRERENDER_DISABLED, - switches::kPrerender, switches::kPrerenderSwitchValueDisabled }, -}; - // RECORDING USER METRICS FOR FLAGS: // ----------------------------------------------------------------------------- // The first line of the experiment is the internal name. If you'd like to @@ -213,13 +205,6 @@ const Experiment kExperiments[] = { SINGLE_VALUE_TYPE(switches::kDnsServer) }, { - "page-prerender", // FLAGS:RECORD_UMA - IDS_FLAGS_PAGE_PRERENDER_NAME, - IDS_FLAGS_PAGE_PRERENDER_DESCRIPTION, - kOsAll, - MULTI_VALUE_TYPE(kPagePrerenderChoices) - }, - { "extension-apis", // FLAGS:RECORD_UMA IDS_FLAGS_EXPERIMENTAL_EXTENSION_APIS_NAME, IDS_FLAGS_EXPERIMENTAL_EXTENSION_APIS_DESCRIPTION, diff --git a/chrome/browser/net/net_pref_observer.cc b/chrome/browser/net/net_pref_observer.cc index 75dd11a..0a1a01c 100644 --- a/chrome/browser/net/net_pref_observer.cc +++ b/chrome/browser/net/net_pref_observer.cc @@ -7,6 +7,8 @@ #include "base/task.h" #include "chrome/browser/net/predictor_api.h" #include "chrome/browser/prefs/pref_service.h" +#include "chrome/browser/prerender/prerender_manager.h" +#include "chrome/browser/profiles/profile.h" #include "chrome/common/pref_names.h" #include "content/browser/browser_thread.h" #include "content/common/notification_type.h" @@ -25,9 +27,11 @@ void SetEnforceThrottlingOnThrottlerManager(bool enforce) { } -NetPrefObserver::NetPrefObserver(PrefService* prefs) { +NetPrefObserver::NetPrefObserver(PrefService* prefs, + prerender::PrerenderManager* prerender_manager) + : prerender_manager_(prerender_manager) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - + DCHECK(prefs); dns_prefetching_enabled_.Init(prefs::kDnsPrefetchingEnabled, prefs, this); spdy_disabled_.Init(prefs::kDisableSpdy, prefs, this); http_throttling_enabled_.Init(prefs::kHttpThrottlingEnabled, prefs, this); @@ -52,6 +56,8 @@ void NetPrefObserver::ApplySettings(const std::string* pref_name) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); chrome_browser_net::EnablePredictor(*dns_prefetching_enabled_); + if (prerender_manager_) + prerender_manager_->set_enabled(*dns_prefetching_enabled_); net::HttpStreamFactory::set_spdy_enabled(!*spdy_disabled_); if (!pref_name || *pref_name == prefs::kHttpThrottlingEnabled) { diff --git a/chrome/browser/net/net_pref_observer.h b/chrome/browser/net/net_pref_observer.h index a1fd2bd..3c33c16 100644 --- a/chrome/browser/net/net_pref_observer.h +++ b/chrome/browser/net/net_pref_observer.h @@ -12,12 +12,21 @@ #include "chrome/browser/prefs/pref_member.h" #include "content/common/notification_observer.h" +class Profile; + +namespace prerender { +class PrerenderManager; +} + // Monitors network-related preferences for changes and applies them. // The supplied PrefService must outlive this NetPrefObserver. // Must be used only on the UI thread. class NetPrefObserver : public NotificationObserver { public: - explicit NetPrefObserver(PrefService* prefs); + // |prefs| must outlive this NetPrefObserver. A reference is + // held to |prerender_manager| if it is non-NULL. + NetPrefObserver(PrefService* prefs, + prerender::PrerenderManager* prerender_manager); ~NetPrefObserver(); // NotificationObserver @@ -34,6 +43,7 @@ class NetPrefObserver : public NotificationObserver { BooleanPrefMember dns_prefetching_enabled_; BooleanPrefMember spdy_disabled_; BooleanPrefMember http_throttling_enabled_; + scoped_refptr<prerender::PrerenderManager> prerender_manager_; DISALLOW_COPY_AND_ASSIGN(NetPrefObserver); }; diff --git a/chrome/browser/prerender/prerender_manager.cc b/chrome/browser/prerender/prerender_manager.cc index aa2eb01..2a6ee7c 100644 --- a/chrome/browser/prerender/prerender_manager.cc +++ b/chrome/browser/prerender/prerender_manager.cc @@ -44,7 +44,7 @@ void PrerenderManager::SetMode(PrerenderManagerMode mode) { } // static -bool PrerenderManager::IsPrerenderingEnabled() { +bool PrerenderManager::IsPrerenderingPossible() { return GetMode() == PRERENDER_MODE_ENABLED || GetMode() == PRERENDER_MODE_EXPERIMENT_PRERENDER_GROUP || @@ -78,6 +78,7 @@ struct PrerenderManager::PendingContentsData { PrerenderManager::PrerenderManager(Profile* profile) : rate_limit_enabled_(true), + enabled_(true), profile_(profile), max_prerender_age_(base::TimeDelta::FromSeconds( kDefaultMaxPrerenderAgeSeconds)), @@ -382,6 +383,16 @@ void PrerenderManager::RecordTimeUntilUsed(base::TimeDelta time_until_used) { 50); } +bool PrerenderManager::is_enabled() const { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + return enabled_; +} + +void PrerenderManager::set_enabled(bool enabled) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + enabled_ = enabled; +} + PrerenderContents* PrerenderManager::FindEntry(const GURL& url) { for (std::list<PrerenderContentsData>::iterator it = prerender_list_.begin(); it != prerender_list_.end(); diff --git a/chrome/browser/prerender/prerender_manager.h b/chrome/browser/prerender/prerender_manager.h index 81e2ccd..74dd2d3 100644 --- a/chrome/browser/prerender/prerender_manager.h +++ b/chrome/browser/prerender/prerender_manager.h @@ -97,9 +97,19 @@ class PrerenderManager : public base::RefCounted<PrerenderManager> { unsigned int max_elements() const { return max_elements_; } void set_max_elements(unsigned int num) { max_elements_ = num; } + // Returns whether prerendering is currently enabled for this manager. + // Must be called on the UI thread. + bool is_enabled() const; + + // Set whether prerendering is currently enabled for this manager. + // Must be called on the UI thread. + // If |enabled| is false, existing prerendered pages will still persist until + // they time out, but new ones will not be generated. + void set_enabled(bool enabled); + static PrerenderManagerMode GetMode(); static void SetMode(PrerenderManagerMode mode); - static bool IsPrerenderingEnabled(); + static bool IsPrerenderingPossible(); static bool IsControlGroup(); // The following static method can be called from any thread, but will result @@ -166,6 +176,11 @@ class PrerenderManager : public base::RefCounted<PrerenderManager> { bool DoesRateLimitAllowPrerender() const; + // Specifies whether prerendering is currently enabled for this + // manager. The value can change dynamically during the lifetime + // of the PrerenderManager. + bool enabled_; + Profile* profile_; base::TimeDelta max_prerender_age_; diff --git a/chrome/browser/prerender/prerender_resource_handler.cc b/chrome/browser/prerender/prerender_resource_handler.cc index f5567c7..0a7b507 100644 --- a/chrome/browser/prerender/prerender_resource_handler.cc +++ b/chrome/browser/prerender/prerender_resource_handler.cc @@ -202,6 +202,8 @@ void PrerenderResourceHandler::StartPrerender( const GURL& referrer, bool make_pending) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + if (!prerender_manager_->is_enabled()) + return; if (make_pending) { prerender_manager_->AddPendingPreload(child_route_id_pair, url, alias_urls, referrer); diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc index 5b60dc8..ff46694 100644 --- a/chrome/browser/profiles/profile_impl.cc +++ b/chrome/browser/profiles/profile_impl.cc @@ -771,7 +771,8 @@ PrefService* ProfileImpl::GetPrefs() { GetExtensionPrefValueMap())); DCHECK(!net_pref_observer_.get()); - net_pref_observer_.reset(new NetPrefObserver(prefs_.get())); + net_pref_observer_.reset( + new NetPrefObserver(prefs_.get(), GetPrerenderManager())); } return prefs_.get(); @@ -1492,7 +1493,7 @@ PrefProxyConfigTracker* ProfileImpl::GetProxyConfigTracker() { } prerender::PrerenderManager* ProfileImpl::GetPrerenderManager() { - if (!prerender::PrerenderManager::IsPrerenderingEnabled()) + if (!prerender::PrerenderManager::IsPrerenderingPossible()) return NULL; if (!prerender_manager_) prerender_manager_ = new prerender::PrerenderManager(this); diff --git a/chrome/browser/profiles/profile_impl.h b/chrome/browser/profiles/profile_impl.h index 73f403b..ffc3fe8 100644 --- a/chrome/browser/profiles/profile_impl.h +++ b/chrome/browser/profiles/profile_impl.h @@ -208,6 +208,7 @@ class ProfileImpl : public Profile, scoped_refptr<TransportSecurityPersister> transport_security_persister_; scoped_ptr<policy::ProfilePolicyConnector> profile_policy_connector_; + scoped_refptr<prerender::PrerenderManager> prerender_manager_; scoped_ptr<NetPrefObserver> net_pref_observer_; scoped_ptr<TemplateURLFetcher> template_url_fetcher_; scoped_ptr<TemplateURLModel> template_url_model_; @@ -307,8 +308,6 @@ class ProfileImpl : public Profile, scoped_refptr<PrefProxyConfigTracker> pref_proxy_config_tracker_; - scoped_refptr<prerender::PrerenderManager> prerender_manager_; - scoped_ptr<ChromeURLDataManager> chrome_url_data_manager_; DISALLOW_COPY_AND_ASSIGN(ProfileImpl); diff --git a/chrome/test/testing_profile.cc b/chrome/test/testing_profile.cc index a2b9a0f..9d32203 100644 --- a/chrome/test/testing_profile.cc +++ b/chrome/test/testing_profile.cc @@ -770,7 +770,7 @@ ChromeURLDataManager* TestingProfile::GetChromeURLDataManager() { } prerender::PrerenderManager* TestingProfile::GetPrerenderManager() { - if (!prerender::PrerenderManager::IsPrerenderingEnabled()) + if (!prerender::PrerenderManager::IsPrerenderingPossible()) return NULL; if (!prerender_manager_) prerender_manager_ = new prerender::PrerenderManager(this); |