summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorttuttle@chromium.org <ttuttle@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-09 00:25:16 +0000
committerttuttle@chromium.org <ttuttle@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-09 00:25:16 +0000
commitcd0810e0ab781e5a5401d0c28c0afe594cd1a2d1 (patch)
treedf429ee222851fd49cd858339a0fdc7213380c59
parent0e2bbf25d90af1e7a8194b610b8a178cb9b9fe3f (diff)
downloadchromium_src-cd0810e0ab781e5a5401d0c28c0afe594cd1a2d1.zip
chromium_src-cd0810e0ab781e5a5401d0c28c0afe594cd1a2d1.tar.gz
chromium_src-cd0810e0ab781e5a5401d0c28c0afe594cd1a2d1.tar.bz2
Move DnsProbeService::Result to chrome/common
I'm going to be writing the renderer-side code to interface with the NetErrorTabHelper, and it will need to understand DNS probe results, so move that enum to common. BUG=156415 Review URL: https://chromiumcodereview.appspot.com/11776031 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175628 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/net/dns_probe_service.cc38
-rw-r--r--chrome/browser/net/dns_probe_service.h15
-rw-r--r--chrome/browser/net/dns_probe_service_unittest.cc22
-rw-r--r--chrome/browser/net/net_error_tab_helper.cc7
-rw-r--r--chrome/browser/net/net_error_tab_helper.h3
-rw-r--r--chrome/browser/net/net_error_tab_helper_unittest.cc10
-rw-r--r--chrome/common/net/net_error_info.h20
7 files changed, 71 insertions, 44 deletions
diff --git a/chrome/browser/net/dns_probe_service.cc b/chrome/browser/net/dns_probe_service.cc
index 5609247..7b12d72 100644
--- a/chrome/browser/net/dns_probe_service.cc
+++ b/chrome/browser/net/dns_probe_service.cc
@@ -8,6 +8,7 @@
#include "base/metrics/histogram.h"
#include "base/string_number_conversions.h"
#include "chrome/browser/net/dns_probe_job.h"
+#include "chrome/common/net/net_error_info.h"
#include "net/base/ip_endpoint.h"
#include "net/base/net_util.h"
#include "net/dns/dns_client.h"
@@ -16,6 +17,7 @@
using base::FieldTrialList;
using base::StringToInt;
+using chrome_common_net::DnsProbeResult;
using net::DnsClient;
using net::DnsConfig;
using net::IPAddressNumber;
@@ -74,7 +76,7 @@ DnsProbeService::DnsProbeService()
: system_result_(DnsProbeJob::SERVERS_UNKNOWN),
public_result_(DnsProbeJob::SERVERS_UNKNOWN),
state_(STATE_NO_RESULTS),
- result_(PROBE_UNKNOWN),
+ result_(chrome_common_net::DNS_PROBE_UNKNOWN),
dns_attempts_(GetAttemptsFromFieldTrial()) {
NetworkChangeNotifier::AddIPAddressObserver(this);
}
@@ -125,7 +127,7 @@ void DnsProbeService::ExpireResults() {
DCHECK_EQ(STATE_RESULTS_CACHED, state_);
state_ = STATE_NO_RESULTS;
- result_ = PROBE_UNKNOWN;
+ result_ = chrome_common_net::DNS_PROBE_UNKNOWN;
}
void DnsProbeService::StartProbes() {
@@ -152,7 +154,7 @@ void DnsProbeService::StartProbes() {
state_ = STATE_RESULTS_CACHED;
// TODO(ttuttle): Should this be BAD_CONFIG? Currently I think it only
// happens when the system DnsConfig has no servers.
- result_ = PROBE_UNKNOWN;
+ result_ = chrome_common_net::DNS_PROBE_UNKNOWN;
CallCallbacks();
return;
}
@@ -173,34 +175,36 @@ void DnsProbeService::OnProbesComplete() {
}
void DnsProbeService::HistogramProbes() const {
+ const DnsProbeResult kMaxResult = chrome_common_net::DNS_PROBE_MAX;
+
DCHECK_EQ(STATE_RESULTS_CACHED, state_);
- DCHECK_NE(MAX_RESULT, result_);
+ DCHECK_NE(kMaxResult, result_);
base::TimeDelta elapsed = base::Time::Now() - probe_start_time_;
- UMA_HISTOGRAM_ENUMERATION("DnsProbe.Probe.Result", result_, MAX_RESULT);
+ UMA_HISTOGRAM_ENUMERATION("DnsProbe.Probe.Result", result_, kMaxResult);
UMA_HISTOGRAM_MEDIUM_TIMES("DnsProbe.Probe.Elapsed", elapsed);
if (NetworkChangeNotifier::IsOffline()) {
UMA_HISTOGRAM_ENUMERATION("DnsProbe.Probe.NcnOffline.Result",
- result_, MAX_RESULT);
+ result_, kMaxResult);
UMA_HISTOGRAM_MEDIUM_TIMES("DnsProbe.Probe.NcnOffline.Elapsed", elapsed);
} else {
UMA_HISTOGRAM_ENUMERATION("DnsProbe.Probe.NcnOnline.Result",
- result_, MAX_RESULT);
+ result_, kMaxResult);
UMA_HISTOGRAM_MEDIUM_TIMES("DnsProbe.Probe.NcnOnline.Elapsed", elapsed);
}
switch (result_) {
- case PROBE_UNKNOWN:
+ case chrome_common_net::DNS_PROBE_UNKNOWN:
UMA_HISTOGRAM_MEDIUM_TIMES("DnsProbe.Probe.ResultUnknown.Elapsed",
elapsed);
break;
- case PROBE_NO_INTERNET:
+ case chrome_common_net::DNS_PROBE_NO_INTERNET:
UMA_HISTOGRAM_MEDIUM_TIMES("DnsProbe.Probe.ResultNoInternet.Elapsed",
elapsed);
break;
- case PROBE_BAD_CONFIG:
+ case chrome_common_net::DNS_PROBE_BAD_CONFIG:
UMA_HISTOGRAM_MEDIUM_TIMES("DnsProbe.Probe.ResultBadConfig.Elapsed",
elapsed);
@@ -217,41 +221,41 @@ void DnsProbeService::HistogramProbes() const {
"DnsProbe.Probe.ResultBadConfig.SystemIsLocalhost",
system_is_localhost_);
break;
- case PROBE_NXDOMAIN:
+ case chrome_common_net::DNS_PROBE_NXDOMAIN:
UMA_HISTOGRAM_MEDIUM_TIMES("DnsProbe.Probe.ResultNxdomain.Elapsed",
elapsed);
break;
- case MAX_RESULT:
+ case chrome_common_net::DNS_PROBE_MAX:
NOTREACHED();
break;
}
}
-DnsProbeService::Result DnsProbeService::EvaluateResults() const {
+DnsProbeResult DnsProbeService::EvaluateResults() const {
DCHECK_NE(DnsProbeJob::SERVERS_UNKNOWN, system_result_);
DCHECK_NE(DnsProbeJob::SERVERS_UNKNOWN, public_result_);
// If the system DNS is working, assume the domain doesn't exist.
if (system_result_ == DnsProbeJob::SERVERS_CORRECT)
- return PROBE_NXDOMAIN;
+ return chrome_common_net::DNS_PROBE_NXDOMAIN;
// If the system DNS is not working but another public server is, assume the
// DNS config is bad (or perhaps the DNS servers are down or broken).
if (public_result_ == DnsProbeJob::SERVERS_CORRECT)
- return PROBE_BAD_CONFIG;
+ return chrome_common_net::DNS_PROBE_BAD_CONFIG;
// If the system DNS is not working and another public server is unreachable,
// assume the internet connection is down (note that system DNS may be a
// router on the LAN, so it may be reachable but returning errors.)
if (public_result_ == DnsProbeJob::SERVERS_UNREACHABLE)
- return PROBE_NO_INTERNET;
+ return chrome_common_net::DNS_PROBE_NO_INTERNET;
// Otherwise: the system DNS is not working and another public server is
// responding but with errors or incorrect results. This is an awkward case;
// an invasive captive portal or a restrictive firewall may be intercepting
// or rewriting DNS traffic, or the public server may itself be failing or
// down.
- return PROBE_UNKNOWN;
+ return chrome_common_net::DNS_PROBE_UNKNOWN;
}
void DnsProbeService::CallCallbacks() {
diff --git a/chrome/browser/net/dns_probe_service.h b/chrome/browser/net/dns_probe_service.h
index 692b85f..c40967a 100644
--- a/chrome/browser/net/dns_probe_service.h
+++ b/chrome/browser/net/dns_probe_service.h
@@ -11,6 +11,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/time.h"
#include "chrome/browser/net/dns_probe_job.h"
+#include "chrome/common/net/net_error_info.h"
#include "net/base/network_change_notifier.h"
namespace net {
@@ -21,14 +22,8 @@ namespace chrome_browser_net {
class DnsProbeService : public net::NetworkChangeNotifier::IPAddressObserver {
public:
- enum Result {
- PROBE_UNKNOWN,
- PROBE_NO_INTERNET,
- PROBE_BAD_CONFIG,
- PROBE_NXDOMAIN,
- MAX_RESULT
- };
- typedef base::Callback<void(Result result)> CallbackType;
+ typedef base::Callback<void(chrome_common_net::DnsProbeResult result)>
+ CallbackType;
DnsProbeService();
virtual ~DnsProbeService();
@@ -54,7 +49,7 @@ class DnsProbeService : public net::NetworkChangeNotifier::IPAddressObserver {
void CallCallbacks();
void OnProbeJobComplete(DnsProbeJob* job, DnsProbeJob::Result result);
- Result EvaluateResults() const;
+ chrome_common_net::DnsProbeResult EvaluateResults() const;
void HistogramProbes() const;
// These are expected to be overridden by tests to return mock jobs.
@@ -76,7 +71,7 @@ class DnsProbeService : public net::NetworkChangeNotifier::IPAddressObserver {
DnsProbeJob::Result public_result_;
std::vector<CallbackType> callbacks_;
State state_;
- Result result_;
+ chrome_common_net::DnsProbeResult result_;
base::Time probe_start_time_;
// How many DNS request attempts the probe jobs will make before giving up
// (Overrides the attempts field in the system DnsConfig.)
diff --git a/chrome/browser/net/dns_probe_service_unittest.cc b/chrome/browser/net/dns_probe_service_unittest.cc
index 62e886e..a687df4 100644
--- a/chrome/browser/net/dns_probe_service_unittest.cc
+++ b/chrome/browser/net/dns_probe_service_unittest.cc
@@ -10,15 +10,19 @@
#include "base/message_loop.h"
#include "base/run_loop.h"
#include "chrome/browser/net/dns_probe_job.h"
+#include "chrome/common/net/net_error_info.h"
#include "testing/gtest/include/gtest/gtest.h"
+using chrome_common_net::DnsProbeResult;
+
namespace chrome_browser_net {
namespace {
class MockDnsProbeJob : public DnsProbeJob {
public:
- MockDnsProbeJob(const CallbackType& callback, Result result)
+ MockDnsProbeJob(const CallbackType& callback,
+ DnsProbeJob::Result result)
: ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
MessageLoop::current()->PostTask(
FROM_HERE,
@@ -109,7 +113,7 @@ class DnsProbeServiceTest : public testing::Test {
public:
DnsProbeServiceTest()
: callback_called_(false),
- callback_result_(DnsProbeService::PROBE_UNKNOWN) {
+ callback_result_(chrome_common_net::DNS_PROBE_UNKNOWN) {
}
void Probe() {
@@ -130,10 +134,10 @@ class DnsProbeServiceTest : public testing::Test {
MessageLoopForIO message_loop_;
TestDnsProbeService service_;
bool callback_called_;
- DnsProbeService::Result callback_result_;
+ DnsProbeResult callback_result_;
private:
- void ProbeCallback(DnsProbeService::Result result) {
+ void ProbeCallback(DnsProbeResult result) {
callback_called_ = true;
callback_result_ = result;
}
@@ -152,7 +156,7 @@ TEST_F(DnsProbeServiceTest, Probe) {
RunUntilIdle();
EXPECT_TRUE(callback_called_);
- EXPECT_EQ(DnsProbeService::PROBE_NXDOMAIN, callback_result_);
+ EXPECT_EQ(chrome_common_net::DNS_PROBE_NXDOMAIN, callback_result_);
}
TEST_F(DnsProbeServiceTest, Cache) {
@@ -170,7 +174,7 @@ TEST_F(DnsProbeServiceTest, Cache) {
RunUntilIdle();
EXPECT_TRUE(callback_called_);
- EXPECT_EQ(DnsProbeService::PROBE_NXDOMAIN, callback_result_);
+ EXPECT_EQ(chrome_common_net::DNS_PROBE_NXDOMAIN, callback_result_);
}
TEST_F(DnsProbeServiceTest, Expired) {
@@ -182,7 +186,7 @@ TEST_F(DnsProbeServiceTest, Expired) {
RunUntilIdle();
EXPECT_TRUE(callback_called_);
- EXPECT_EQ(DnsProbeService::PROBE_NXDOMAIN, callback_result_);
+ EXPECT_EQ(chrome_common_net::DNS_PROBE_NXDOMAIN, callback_result_);
Reset();
@@ -193,7 +197,7 @@ TEST_F(DnsProbeServiceTest, Expired) {
RunUntilIdle();
EXPECT_TRUE(callback_called_);
- EXPECT_EQ(DnsProbeService::PROBE_NXDOMAIN, callback_result_);
+ EXPECT_EQ(chrome_common_net::DNS_PROBE_NXDOMAIN, callback_result_);
}
TEST_F(DnsProbeServiceTest, SystemFail) {
@@ -203,7 +207,7 @@ TEST_F(DnsProbeServiceTest, SystemFail) {
Probe();
EXPECT_TRUE(callback_called_);
- EXPECT_EQ(DnsProbeService::PROBE_UNKNOWN, callback_result_);
+ EXPECT_EQ(chrome_common_net::DNS_PROBE_UNKNOWN, callback_result_);
Reset();
diff --git a/chrome/browser/net/net_error_tab_helper.cc b/chrome/browser/net/net_error_tab_helper.cc
index 9e95a46..c38141f 100644
--- a/chrome/browser/net/net_error_tab_helper.cc
+++ b/chrome/browser/net/net_error_tab_helper.cc
@@ -11,11 +11,13 @@
#include "chrome/browser/net/dns_probe_service.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/net/net_error_info.h"
#include "chrome/common/pref_names.h"
#include "content/public/browser/browser_thread.h"
#include "net/base/net_errors.h"
using base::FieldTrialList;
+using chrome_common_net::DnsProbeResult;
using content::BrowserContext;
using content::BrowserThread;
using content::RenderViewHost;
@@ -48,7 +50,7 @@ bool GetEnabledByTrial() {
void DnsProbeCallback(
base::WeakPtr<NetErrorTabHelper> tab_helper,
- DnsProbeService::Result result) {
+ DnsProbeResult result) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
BrowserThread::PostTask(
@@ -126,8 +128,7 @@ void NetErrorTabHelper::OnMainFrameDnsError() {
set_dns_probe_running(true);
}
-void NetErrorTabHelper::OnDnsProbeFinished(
- DnsProbeService::Result result) {
+void NetErrorTabHelper::OnDnsProbeFinished(DnsProbeResult result) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(dns_probe_running_);
diff --git a/chrome/browser/net/net_error_tab_helper.h b/chrome/browser/net/net_error_tab_helper.h
index 9eb8a2b..9083e32 100644
--- a/chrome/browser/net/net_error_tab_helper.h
+++ b/chrome/browser/net/net_error_tab_helper.h
@@ -10,6 +10,7 @@
#include "base/memory/weak_ptr.h"
#include "base/prefs/public/pref_member.h"
#include "chrome/browser/net/dns_probe_service.h"
+#include "chrome/common/net/net_error_info.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"
@@ -39,7 +40,7 @@ class NetErrorTabHelper
const string16& error_description,
content::RenderViewHost* render_view_host) OVERRIDE;
- void OnDnsProbeFinished(DnsProbeService::Result result);
+ void OnDnsProbeFinished(chrome_common_net::DnsProbeResult result);
static void set_state_for_testing(TestingState testing_state);
diff --git a/chrome/browser/net/net_error_tab_helper_unittest.cc b/chrome/browser/net/net_error_tab_helper_unittest.cc
index ab1d0ca5..bcb3f5aa 100644
--- a/chrome/browser/net/net_error_tab_helper_unittest.cc
+++ b/chrome/browser/net/net_error_tab_helper_unittest.cc
@@ -7,12 +7,14 @@
#include "base/message_loop.h"
#include "base/run_loop.h"
#include "chrome/browser/net/dns_probe_service.h"
+#include "chrome/common/net/net_error_info.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/test/test_browser_thread.h"
#include "googleurl/src/gurl.h"
#include "net/base/net_errors.h"
#include "testing/gtest/include/gtest/gtest.h"
+using chrome_common_net::DnsProbeResult;
using content::BrowserThread;
using content::TestBrowserThread;
@@ -44,7 +46,7 @@ class TestNetErrorTabHelper : public NetErrorTabHelper {
probes_allowed_ = probes_allowed;
}
- void SimulateProbeResult(DnsProbeService::Result result) {
+ void SimulateProbeResult(DnsProbeResult result) {
OnDnsProbeFinished(result);
}
@@ -130,21 +132,21 @@ TEST_F(NetErrorTabHelperTest, HandleProbeResponse) {
SimulateFailure(true, net::ERR_NAME_NOT_RESOLVED);
// Make sure we handle probe response.
- tab_helper_.SimulateProbeResult(DnsProbeService::PROBE_UNKNOWN);
+ tab_helper_.SimulateProbeResult(chrome_common_net::DNS_PROBE_UNKNOWN);
EXPECT_FALSE(tab_helper_.dns_probe_running());
EXPECT_EQ(1, tab_helper_.probe_start_count());
}
TEST_F(NetErrorTabHelperTest, MultipleProbes) {
SimulateFailure(true, net::ERR_NAME_NOT_RESOLVED);
- tab_helper_.SimulateProbeResult(DnsProbeService::PROBE_UNKNOWN);
+ tab_helper_.SimulateProbeResult(chrome_common_net::DNS_PROBE_UNKNOWN);
// Make sure we can run a new probe after the previous one returned.
SimulateFailure(true, net::ERR_NAME_NOT_RESOLVED);
EXPECT_TRUE(tab_helper_.dns_probe_running());
EXPECT_EQ(2, tab_helper_.probe_start_count());
- tab_helper_.SimulateProbeResult(DnsProbeService::PROBE_UNKNOWN);
+ tab_helper_.SimulateProbeResult(chrome_common_net::DNS_PROBE_UNKNOWN);
EXPECT_FALSE(tab_helper_.dns_probe_running());
EXPECT_EQ(2, tab_helper_.probe_start_count());
}
diff --git a/chrome/common/net/net_error_info.h b/chrome/common/net/net_error_info.h
new file mode 100644
index 0000000..9f8d08a
--- /dev/null
+++ b/chrome/common/net/net_error_info.h
@@ -0,0 +1,20 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_COMMON_NET_NET_ERROR_INFO_H_
+#define CHROME_COMMON_NET_NET_ERROR_INFO_H_
+
+namespace chrome_common_net {
+
+enum DnsProbeResult {
+ DNS_PROBE_UNKNOWN,
+ DNS_PROBE_NO_INTERNET,
+ DNS_PROBE_BAD_CONFIG,
+ DNS_PROBE_NXDOMAIN,
+ DNS_PROBE_MAX
+};
+
+} // namespace chrome_common_net
+
+#endif // CHROME_COMMON_NET_NET_ERROR_INFO_H_