blob: 1e58694a632a6038236940ad98285e4b7f632396 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
// Copyright 2014 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 COMPONENTS_DOMAIN_RELIABILITY_MONITOR_H_
#define COMPONENTS_DOMAIN_RELIABILITY_MONITOR_H_
#include <map>
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "components/domain_reliability/beacon.h"
#include "components/domain_reliability/clear_mode.h"
#include "components/domain_reliability/config.h"
#include "components/domain_reliability/context.h"
#include "components/domain_reliability/dispatcher.h"
#include "components/domain_reliability/domain_reliability_export.h"
#include "components/domain_reliability/scheduler.h"
#include "components/domain_reliability/uploader.h"
#include "components/domain_reliability/util.h"
#include "net/base/load_timing_info.h"
#include "net/http/http_response_info.h"
#include "net/url_request/url_request_status.h"
namespace base {
class SingleThreadTaskRunner;
class ThreadChecker;
class Value;
} // namespace base
namespace net {
class URLRequest;
class URLRequestContext;
class URLRequestContextGetter;
} // namespace net
namespace domain_reliability {
// The top-level object that measures requests and hands off the measurements
// to the proper |DomainReliabilityContext|.
class DOMAIN_RELIABILITY_EXPORT DomainReliabilityMonitor {
public:
explicit DomainReliabilityMonitor(const std::string& upload_reporter_string);
DomainReliabilityMonitor(const std::string& upload_reporter_string,
scoped_ptr<MockableTime> time);
~DomainReliabilityMonitor();
// Initializes the Monitor.
void Init(
net::URLRequestContext* url_request_context,
const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);
// Same, but for unittests where the Getter is readily available.
void Init(
scoped_refptr<net::URLRequestContextGetter> url_request_context_getter);
// Populates the monitor with contexts that were configured at compile time.
void AddBakedInConfigs();
// Should be called when |request| is about to follow a redirect. Will
// examine and possibly log the redirect request.
void OnBeforeRedirect(net::URLRequest* request);
// Should be called when |request| is complete. Will examine and possibly
// log the (final) request. (|started| should be true if the request was
// actually started before it was terminated.)
void OnCompleted(net::URLRequest* request, bool started);
// Called to remove browsing data. With CLEAR_BEACONS, leaves contexts in
// place but clears beacons (which betray browsing history); with
// CLEAR_CONTEXTS, removes all contexts (which can behave as cookies).
void ClearBrowsingData(DomainReliabilityClearMode mode);
// Gets a Value containing data that can be formatted into a web page for
// debugging purposes.
scoped_ptr<base::Value> GetWebUIData() const;
DomainReliabilityContext* AddContextForTesting(
scoped_ptr<const DomainReliabilityConfig> config);
size_t contexts_size_for_testing() const { return contexts_.size(); }
private:
friend class DomainReliabilityMonitorTest;
// Allow the Service to call |MakeWeakPtr|.
friend class DomainReliabilityServiceImpl;
typedef std::map<std::string, DomainReliabilityContext*> ContextMap;
struct DOMAIN_RELIABILITY_EXPORT RequestInfo {
RequestInfo();
explicit RequestInfo(const net::URLRequest& request);
~RequestInfo();
bool AccessedNetwork() const;
GURL url;
net::URLRequestStatus status;
net::HttpResponseInfo response_info;
int load_flags;
net::LoadTimingInfo load_timing_info;
bool is_upload;
};
// Creates a context, adds it to the monitor, and returns a pointer to it.
// (The pointer is only valid until the Monitor is destroyed.)
DomainReliabilityContext* AddContext(
scoped_ptr<const DomainReliabilityConfig> config);
// Deletes all contexts from |contexts_| and clears the map.
void ClearContexts();
void OnRequestLegComplete(const RequestInfo& info);
base::WeakPtr<DomainReliabilityMonitor> MakeWeakPtr();
scoped_ptr<base::ThreadChecker> thread_checker_;
scoped_ptr<MockableTime> time_;
const std::string upload_reporter_string_;
DomainReliabilityScheduler::Params scheduler_params_;
DomainReliabilityDispatcher dispatcher_;
scoped_ptr<DomainReliabilityUploader> uploader_;
ContextMap contexts_;
base::WeakPtrFactory<DomainReliabilityMonitor> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(DomainReliabilityMonitor);
};
} // namespace domain_reliability
#endif // COMPONENTS_DOMAIN_RELIABILITY_MONITOR_H_
|