summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoreroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-11 19:13:08 +0000
committereroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-11 19:13:08 +0000
commit8d53d50afb7ed6df2a39c175bfdb2485a3a25d9d (patch)
treeeab27a8ece609f3bd6fad7081cbf5fd36ec0922f
parent762d2db5d5e1b0d7852ddb2efef982b00e897322 (diff)
downloadchromium_src-8d53d50afb7ed6df2a39c175bfdb2485a3a25d9d.zip
chromium_src-8d53d50afb7ed6df2a39c175bfdb2485a3a25d9d.tar.gz
chromium_src-8d53d50afb7ed6df2a39c175bfdb2485a3a25d9d.tar.bz2
Clear the host cache when closing the last incognito window.
This avoids retaining navigation history relating to the incognito window. I piggy-back off of the dns prefetcher's OffTheRecordObserver to do this. In the future I hope to have a separate host resolver for off the record mode, so this won't be necessary. BUG=24629 Review URL: http://codereview.chromium.org/523076 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35923 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/browser_main.cc5
-rw-r--r--chrome/browser/net/dns_global.cc52
-rw-r--r--chrome/browser/net/dns_global.h12
-rw-r--r--chrome/browser/net/dns_master_unittest.cc31
-rw-r--r--net/base/host_cache.h5
-rw-r--r--net/base/host_cache_unittest.cc20
6 files changed, 84 insertions, 41 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc
index 521513f..0c57f3a 100644
--- a/chrome/browser/browser_main.cc
+++ b/chrome/browser/browser_main.cc
@@ -762,8 +762,9 @@ int BrowserMain(const MainFunctionParams& parameters) {
// testing against a bunch of special cases that are taken care early on.
PrepareRestartOnCrashEnviroment(parsed_command_line);
- // Initialize and maintain DNS prefetcher module.
- chrome_browser_net::DnsPrefetcherInit dns_prefetch(user_prefs, local_state);
+ // Initialize and maintain DNS prefetcher module. Also registers an observer
+ // to clear the host cache when closing incognito mode.
+ chrome_browser_net::DnsGlobalInit dns_prefetch(user_prefs, local_state);
scoped_refptr<FieldTrial> socket_late_binding_trial =
new FieldTrial("SocketLateBinding", 100);
diff --git a/chrome/browser/net/dns_global.cc b/chrome/browser/net/dns_global.cc
index bb2abad..916f307 100644
--- a/chrome/browser/net/dns_global.cc
+++ b/chrome/browser/net/dns_global.cc
@@ -34,7 +34,7 @@ using base::TimeDelta;
namespace chrome_browser_net {
-static void DiscardAllPrefetchState();
+static void ChangedToOnTheRecord();
static void DnsMotivatedPrefetch(const std::string& hostname,
DnsHostInfo::ResolutionMotivation motivation);
static void DnsPrefetchMotivatedList(
@@ -42,10 +42,10 @@ static void DnsPrefetchMotivatedList(
DnsHostInfo::ResolutionMotivation motivation);
// static
-const size_t DnsPrefetcherInit::kMaxConcurrentLookups = 8;
+const size_t DnsGlobalInit::kMaxPrefetchConcurrentLookups = 8;
// static
-const int DnsPrefetcherInit::kMaxQueueingDelayMs = 1000;
+const int DnsGlobalInit::kMaxPrefetchQueueingDelayMs = 1000;
// Host resolver shared by DNS prefetcher, and the main URLRequestContext.
static net::HostResolver* global_host_resolver = NULL;
@@ -72,8 +72,12 @@ void OnTheRecord(bool enable) {
if (on_the_record_switch == enable)
return;
on_the_record_switch = enable;
- if (on_the_record_switch)
- DiscardAllPrefetchState(); // Destroy all evidence of our OTR session.
+ if (on_the_record_switch) {
+ ChromeThread::PostTask(
+ ChromeThread::IO,
+ FROM_HERE,
+ NewRunnableFunction(ChangedToOnTheRecord));
+ }
}
void RegisterPrefs(PrefService* local_state) {
@@ -409,9 +413,6 @@ void InitDnsPrefetch(TimeDelta max_queue_delay, size_t max_concurrent,
dns_master = new DnsMaster(GetGlobalHostResolver(),
max_queue_delay, max_concurrent);
dns_master->AddRef();
- // We did the initialization, so we should prime the pump, and set up
- // the DNS resolution system to run.
- Singleton<OffTheRecordObserver>::get()->Register();
if (user_prefs) {
bool enabled = user_prefs->GetBoolean(prefs::kDnsPrefetchingEnabled);
@@ -457,16 +458,19 @@ void FreeDnsPrefetchResources() {
dns_master = NULL;
}
-static void DiscardAllPrefetchState() {
- DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
- if (!dns_master)
- return;
+static void ChangedToOnTheRecord() {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
- ChromeThread::PostTask(
- ChromeThread::IO,
- FROM_HERE,
- NewRunnableMethod(dns_master,
- &DnsMaster::DiscardAllResults));
+ if (dns_master) {
+ // Destroy all evidence of our OTR session.
+ dns_master->DnsMaster::DiscardAllResults();
+ }
+
+ // Clear the host cache to avoid showing entries from the OTR session
+ // in about:net-internals.
+ net::HostCache* host_cache = GetGlobalHostResolver()->GetHostCache();
+ if (host_cache)
+ host_cache->clear();
}
//------------------------------------------------------------------------------
@@ -610,8 +614,8 @@ static void RestoreSubresourceReferrers(PrefService* local_state) {
// Methods for the helper class that is used to startup and teardown the whole
// DNS prefetch system.
-DnsPrefetcherInit::DnsPrefetcherInit(PrefService* user_prefs,
- PrefService* local_state) {
+DnsGlobalInit::DnsGlobalInit(PrefService* user_prefs,
+ PrefService* local_state) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
// Set up a field trial to see what disabling DNS pre-resolution does to
// latency of page loads.
@@ -639,12 +643,16 @@ DnsPrefetcherInit::DnsPrefetcherInit(PrefService* user_prefs,
trial_->AppendGroup("_default_enabled_prefetch",
FieldTrial::kAllRemainingProbability);
+ // We will register the incognito observer regardless of whether prefetching
+ // is enabled, as it is also used to clear the host cache.
+ Singleton<OffTheRecordObserver>::get()->Register();
+
if (trial_->group() != disabled_prefetch) {
// Initialize the DNS prefetch system.
- size_t max_concurrent = kMaxConcurrentLookups;
+ size_t max_concurrent = kMaxPrefetchConcurrentLookups;
- int max_queueing_delay_ms = kMaxQueueingDelayMs;
+ int max_queueing_delay_ms = kMaxPrefetchQueueingDelayMs;
if (trial_->group() == max_250ms_prefetch)
max_queueing_delay_ms = 250;
@@ -666,7 +674,7 @@ DnsPrefetcherInit::DnsPrefetcherInit(PrefService* user_prefs,
}
}
-DnsPrefetcherInit::~DnsPrefetcherInit() {
+DnsGlobalInit::~DnsGlobalInit() {
if (dns_master)
FreeDnsPrefetchResources();
}
diff --git a/chrome/browser/net/dns_global.h b/chrome/browser/net/dns_global.h
index 965e152..48d7a56 100644
--- a/chrome/browser/net/dns_global.h
+++ b/chrome/browser/net/dns_global.h
@@ -57,26 +57,26 @@ void DnsPrefetchGetHtmlInfo(std::string* output);
//------------------------------------------------------------------------------
void SaveDnsPrefetchStateForNextStartupAndTrim(PrefService* prefs);
// Helper class to handle global init and shutdown.
-class DnsPrefetcherInit {
+class DnsGlobalInit {
public:
// Too many concurrent lookups negate benefits of prefetching by trashing
// the OS cache before all resource loading is complete.
// This is the default.
- static const size_t kMaxConcurrentLookups;
+ static const size_t kMaxPrefetchConcurrentLookups;
// When prefetch requests are queued beyond some period of time, then the
// system is congested, and we need to clear all queued requests to get out
// of that state. The following is the suggested default time limit.
- static const int kMaxQueueingDelayMs;
+ static const int kMaxPrefetchQueueingDelayMs;
- DnsPrefetcherInit(PrefService* user_prefs, PrefService* local_state);
- ~DnsPrefetcherInit();
+ DnsGlobalInit(PrefService* user_prefs, PrefService* local_state);
+ ~DnsGlobalInit();
private:
// Maintain a field trial instance when we do A/B testing.
scoped_refptr<FieldTrial> trial_;
- DISALLOW_COPY_AND_ASSIGN(DnsPrefetcherInit);
+ DISALLOW_COPY_AND_ASSIGN(DnsGlobalInit);
};
} // namespace chrome_browser_net
diff --git a/chrome/browser/net/dns_master_unittest.cc b/chrome/browser/net/dns_master_unittest.cc
index 249956d..2f83d30 100644
--- a/chrome/browser/net/dns_master_unittest.cc
+++ b/chrome/browser/net/dns_master_unittest.cc
@@ -63,7 +63,7 @@ class DnsMasterTest : public testing::Test {
: io_thread_(ChromeThread::IO, &loop_),
host_resolver_(new net::MockCachingHostResolver()),
default_max_queueing_delay_(TimeDelta::FromMilliseconds(
- DnsPrefetcherInit::kMaxQueueingDelayMs)) {
+ DnsGlobalInit::kMaxPrefetchQueueingDelayMs)) {
}
protected:
@@ -99,7 +99,7 @@ class DnsMasterTest : public testing::Test {
protected:
scoped_refptr<net::MockCachingHostResolver> host_resolver_;
- // Shorthand to access TimeDelta of DnsPrefetcherInit::kMaxQueueingDelayMs.
+ // Shorthand to access TimeDelta of DnsGlobalInit::kMaxQueueingDelayMs.
// (It would be a static constant... except style rules preclude that :-/ ).
const TimeDelta default_max_queueing_delay_;
};
@@ -108,13 +108,15 @@ class DnsMasterTest : public testing::Test {
TEST_F(DnsMasterTest, StartupShutdownTest) {
scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_,
- default_max_queueing_delay_, DnsPrefetcherInit::kMaxConcurrentLookups);
+ default_max_queueing_delay_,
+ DnsGlobalInit::kMaxPrefetchConcurrentLookups);
testing_master->Shutdown();
}
TEST_F(DnsMasterTest, BenefitLookupTest) {
scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_,
- default_max_queueing_delay_, DnsPrefetcherInit::kMaxConcurrentLookups);
+ default_max_queueing_delay_,
+ DnsGlobalInit::kMaxPrefetchConcurrentLookups);
std::string goog("www.google.com"),
goog2("gmail.google.com.com"),
@@ -178,7 +180,8 @@ TEST_F(DnsMasterTest, ShutdownWhenResolutionIsPendingTest) {
host_resolver_->Reset(resolver_proc);
scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_,
- default_max_queueing_delay_, DnsPrefetcherInit::kMaxConcurrentLookups);
+ default_max_queueing_delay_,
+ DnsGlobalInit::kMaxPrefetchConcurrentLookups);
std::string localhost("127.0.0.1");
NameList names;
@@ -201,7 +204,8 @@ TEST_F(DnsMasterTest, ShutdownWhenResolutionIsPendingTest) {
TEST_F(DnsMasterTest, SingleLookupTest) {
scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_,
- default_max_queueing_delay_, DnsPrefetcherInit::kMaxConcurrentLookups);
+ default_max_queueing_delay_,
+ DnsGlobalInit::kMaxPrefetchConcurrentLookups);
std::string goog("www.google.com");
@@ -230,7 +234,8 @@ TEST_F(DnsMasterTest, ConcurrentLookupTest) {
host_resolver_->rules()->AddSimulatedFailure("*.notfound");
scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_,
- default_max_queueing_delay_, DnsPrefetcherInit::kMaxConcurrentLookups);
+ default_max_queueing_delay_,
+ DnsGlobalInit::kMaxPrefetchConcurrentLookups);
std::string goog("www.google.com"),
goog2("gmail.google.com.com"),
@@ -278,7 +283,8 @@ TEST_F(DnsMasterTest, MassiveConcurrentLookupTest) {
host_resolver_->rules()->AddSimulatedFailure("*.notfound");
scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_,
- default_max_queueing_delay_, DnsPrefetcherInit::kMaxConcurrentLookups);
+ default_max_queueing_delay_,
+ DnsGlobalInit::kMaxPrefetchConcurrentLookups);
NameList names;
for (int i = 0; i < 100; i++)
@@ -382,7 +388,8 @@ int GetLatencyFromSerialization(const std::string& motivation,
// Make sure nil referral lists really have no entries, and no latency listed.
TEST_F(DnsMasterTest, ReferrerSerializationNilTest) {
scoped_refptr<DnsMaster> master = new DnsMaster(host_resolver_,
- default_max_queueing_delay_, DnsPrefetcherInit::kMaxConcurrentLookups);
+ default_max_queueing_delay_,
+ DnsGlobalInit::kMaxPrefetchConcurrentLookups);
ListValue referral_list;
master->SerializeReferrers(&referral_list);
EXPECT_EQ(0U, referral_list.GetSize());
@@ -397,7 +404,8 @@ TEST_F(DnsMasterTest, ReferrerSerializationNilTest) {
// serialization without being changed.
TEST_F(DnsMasterTest, ReferrerSerializationSingleReferrerTest) {
scoped_refptr<DnsMaster> master = new DnsMaster(host_resolver_,
- default_max_queueing_delay_, DnsPrefetcherInit::kMaxConcurrentLookups);
+ default_max_queueing_delay_,
+ DnsGlobalInit::kMaxPrefetchConcurrentLookups);
std::string motivation_hostname = "www.google.com";
std::string subresource_hostname = "icons.google.com";
const int kLatency = 3;
@@ -421,7 +429,8 @@ TEST_F(DnsMasterTest, ReferrerSerializationSingleReferrerTest) {
// Make sure the Trim() functionality works as expected.
TEST_F(DnsMasterTest, ReferrerSerializationTrimTest) {
scoped_refptr<DnsMaster> master = new DnsMaster(host_resolver_,
- default_max_queueing_delay_, DnsPrefetcherInit::kMaxConcurrentLookups);
+ default_max_queueing_delay_,
+ DnsGlobalInit::kMaxPrefetchConcurrentLookups);
std::string motivation_hostname = "www.google.com";
std::string icon_subresource_hostname = "icons.google.com";
std::string img_subresource_hostname = "img.google.com";
diff --git a/net/base/host_cache.h b/net/base/host_cache.h
index 4eb5853..c13c6a0 100644
--- a/net/base/host_cache.h
+++ b/net/base/host_cache.h
@@ -79,6 +79,11 @@ class HostCache {
const AddressList addrlist,
base::TimeTicks now);
+ // Empties the cache.
+ void clear() {
+ entries_.clear();
+ }
+
// Returns true if this HostCache can contain no entries.
bool caching_is_disabled() const {
return max_entries_ == 0;
diff --git a/net/base/host_cache_unittest.cc b/net/base/host_cache_unittest.cc
index 5f4e21b..141cfde 100644
--- a/net/base/host_cache_unittest.cc
+++ b/net/base/host_cache_unittest.cc
@@ -319,6 +319,26 @@ TEST(HostCacheTest, NoCache) {
EXPECT_EQ(0U, cache.size());
}
+TEST(HostCacheTest, Clear) {
+ HostCache cache(kMaxCacheEntries, kSuccessEntryTTL, kFailureEntryTTL);
+
+ // Set t=0.
+ base::TimeTicks now;
+
+ EXPECT_EQ(0u, cache.size());
+
+ // Add three entries.
+ cache.Set(Key("foobar1.com"), OK, AddressList(), now);
+ cache.Set(Key("foobar2.com"), OK, AddressList(), now);
+ cache.Set(Key("foobar3.com"), OK, AddressList(), now);
+
+ EXPECT_EQ(3u, cache.size());
+
+ cache.clear();
+
+ EXPECT_EQ(0u, cache.size());
+}
+
// Tests the less than and equal operators for HostCache::Key work.
TEST(HostCacheTest, KeyComparators) {
struct {