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

Unified Diff: components/domain_reliability/monitor.h

Issue 491753003: Domain Reliability: Don't upload when metrics reporting is off. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix pref handling Created 6 years, 4 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: components/domain_reliability/monitor.h
diff --git a/components/domain_reliability/monitor.h b/components/domain_reliability/monitor.h
index 7886f89e8721c55b3e59414b102198981fc3c21c..9c81bedb26f1af80ff4edcc8bc5fdec503b73b1d 100644
--- a/components/domain_reliability/monitor.h
+++ b/components/domain_reliability/monitor.h
@@ -10,6 +10,7 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
+#include "base/prefs/pref_member.h"
#include "base/time/time.h"
#include "components/domain_reliability/beacon.h"
#include "components/domain_reliability/clear_mode.h"
@@ -24,6 +25,8 @@
#include "net/http/http_response_info.h"
#include "net/url_request/url_request_status.h"
+class PrefService;
+
namespace base {
class SingleThreadTaskRunner;
class ThreadChecker;
@@ -42,20 +45,43 @@ namespace domain_reliability {
// to the proper |DomainReliabilityContext|.
class DOMAIN_RELIABILITY_EXPORT DomainReliabilityMonitor {
public:
- explicit DomainReliabilityMonitor(const std::string& upload_reporter_string);
+ // Creates a Monitor. |InitReportingPref| and |InitURLRequestContext| must be
+ // called (in that order) before any other methods are called. (See those
+ // methods for further threading details.)
+ DomainReliabilityMonitor(const std::string& upload_reporter_string);
DomainReliabilityMonitor(const std::string& upload_reporter_string,
scoped_ptr<MockableTime> time);
~DomainReliabilityMonitor();
- // Initializes the Monitor.
- void Init(
+ // Begins monitoring |reporting_pref_name| in |local_state_pref_service| to
+ // let the user control whether Domain Reliability uploads are sent. (When the
+ // pref is true, they are sent; when it is false, they are discarded.)
+ //
+ // Must be called before |InitURLRequestContext|, on the thread that owns
+ // |local_state_pref_service|. |network_task_runner| must be a task runner
+ // for the thread on which the URLRequestContext passed later lives.
+ void InitReportingPref(
+ PrefService* local_state_pref_service,
+ const char* reporting_pref_name,
+ const scoped_refptr<base::SingleThreadTaskRunner>&
+ network_task_runner);
+
+ // Initializes the Monitor's URLRequestContextGetter.
+ //
+ // Must be called after |InitReportingPref|, on the thread that owns
+ // |url_request_context|. |task_runner| must be a task runner on that
+ // (current) thread.
+ void InitURLRequestContext(
net::URLRequestContext* url_request_context,
const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);
// Same, but for unittests where the Getter is readily available.
- void Init(
+ void InitURLRequestContext(
scoped_refptr<net::URLRequestContextGetter> url_request_context_getter);
+ // Must be called from the same thread as |InitReportingPref|.
+ void DestroyReportingPref();
+
// Populates the monitor with contexts that were configured at compile time.
void AddBakedInConfigs();
@@ -112,6 +138,8 @@ class DOMAIN_RELIABILITY_EXPORT DomainReliabilityMonitor {
void ClearContexts();
void OnRequestLegComplete(const RequestInfo& info);
+ void OnReportingPrefChanged();
+
DomainReliabilityContext* GetContextForHost(const std::string& host) const;
base::WeakPtr<DomainReliabilityMonitor> MakeWeakPtr();
@@ -124,6 +152,9 @@ class DOMAIN_RELIABILITY_EXPORT DomainReliabilityMonitor {
scoped_ptr<DomainReliabilityUploader> uploader_;
ContextMap contexts_;
+ BooleanPrefMember reporting_pref_;
+ bool reporting_pref_initialized_;
+
base::WeakPtrFactory<DomainReliabilityMonitor> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(DomainReliabilityMonitor);

Powered by Google App Engine
This is Rietveld 408576698