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

Unified Diff: net/dns/mock_host_resolver.h

Issue 2837813004: Sync the browser test host resolver with the network process before a test runs. (Closed)
Patch Set: review comments Created 3 years, 8 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
Index: net/dns/mock_host_resolver.h
diff --git a/net/dns/mock_host_resolver.h b/net/dns/mock_host_resolver.h
index cca300acbc69c90e93bfa0772f27646533f0670f..4cbe57c12c50d0e99930e1475544f48dad18f300 100644
--- a/net/dns/mock_host_resolver.h
+++ b/net/dns/mock_host_resolver.h
@@ -9,6 +9,7 @@
#include <list>
#include <map>
+#include <string>
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
@@ -212,6 +213,11 @@ class RuleBasedHostResolverProc : public HostResolverProc {
// Deletes all the rules that have been added.
void ClearRules();
+ // Asserts if any changes are made to the rules after this call.
+ // TODO: once this class isn't used by tests that use an out of process
mmenke 2017/04/25 17:29:47 I believe TODO(name) is the preferred style here?
jam 2017/04/25 18:19:37 Done.
+ // network service, remove this method and make Rule private.
+ void DisableModifications();
+
// HostResolverProc methods:
int Resolve(const std::string& host,
AddressFamily address_family,
@@ -219,10 +225,36 @@ class RuleBasedHostResolverProc : public HostResolverProc {
AddressList* addrlist,
int* os_error) override;
- private:
- struct Rule;
+ struct Rule {
+ enum ResolverType {
+ kResolverTypeFail,
+ kResolverTypeSystem,
+ kResolverTypeIPLiteral,
+ };
+
+ Rule(ResolverType resolver_type,
+ const std::string& host_pattern,
+ AddressFamily address_family,
+ HostResolverFlags host_resolver_flags,
+ const std::string& replacement,
+ const std::string& canonical_name,
+ int latency_ms);
+ Rule(const Rule& other);
+
+ ResolverType resolver_type;
+ std::string host_pattern;
+ AddressFamily address_family;
+ HostResolverFlags host_resolver_flags;
+ std::string replacement;
+ std::string canonical_name;
+ int latency_ms; // In milliseconds.
+ };
+
typedef std::list<Rule> RuleList;
+ RuleList GetRules();
+
+ private:
~RuleBasedHostResolverProc() override;
void AddRuleInternal(const Rule& rule);
@@ -231,6 +263,9 @@ class RuleBasedHostResolverProc : public HostResolverProc {
// Must be obtained before writing to or reading from |rules_|.
base::Lock rule_lock_;
+
+ // Whether changes are allowed.
+ bool modifications_allowed_;
};
// Create rules that map all requests to localhost.

Powered by Google App Engine
This is Rietveld 408576698