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

Side by Side Diff: components/data_reduction_proxy/core/browser/data_reduction_proxy_pingback_client.h

Issue 2833523002: Adding opt out and previews type information to DRP pingback (Closed)
Patch Set: bengr 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_PINGBA CK_CLIENT_H_ 5 #ifndef COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_PINGBA CK_CLIENT_H_
6 #define COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_PINGBA CK_CLIENT_H_ 6 #define COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_PINGBA CK_CLIENT_H_
7 7
8 #include <stdint.h>
9
8 #include <memory> 10 #include <memory>
11 #include <set>
9 #include <string> 12 #include <string>
13 #include <utility>
10 14
11 #include "base/macros.h" 15 #include "base/macros.h"
12 #include "base/threading/thread_checker.h" 16 #include "base/threading/thread_checker.h"
13 #include "components/data_reduction_proxy/proto/pageload_metrics.pb.h" 17 #include "components/data_reduction_proxy/proto/pageload_metrics.pb.h"
14 #include "net/url_request/url_fetcher_delegate.h" 18 #include "net/url_request/url_fetcher_delegate.h"
15 #include "url/gurl.h" 19 #include "url/gurl.h"
16 20
17 namespace base { 21 namespace base {
18 class Time; 22 class Time;
19 } 23 }
20 24
21 namespace net { 25 namespace net {
22 class URLFetcher; 26 class URLFetcher;
23 class URLRequestContextGetter; 27 class URLRequestContextGetter;
24 } 28 }
25 29
26 namespace data_reduction_proxy { 30 namespace data_reduction_proxy {
27 class DataReductionProxyData; 31 class DataReductionProxyData;
28 struct DataReductionProxyPageLoadTiming; 32 struct DataReductionProxyPageLoadTiming;
29 33
34 using NavigationID = std::pair<uint64_t, std::string>;
35
30 // Manages pingbacks about page load timing information to the data saver proxy 36 // Manages pingbacks about page load timing information to the data saver proxy
31 // server. This class is not thread safe. 37 // server. This class is not thread safe.
32 class DataReductionProxyPingbackClient : public net::URLFetcherDelegate { 38 class DataReductionProxyPingbackClient : public net::URLFetcherDelegate {
33 public: 39 public:
34 // The caller must ensure that |url_request_context| remains alive for the 40 // The caller must ensure that |url_request_context| remains alive for the
35 // lifetime of the |DataReductionProxyPingbackClient| instance. 41 // lifetime of the |DataReductionProxyPingbackClient| instance.
36 explicit DataReductionProxyPingbackClient( 42 explicit DataReductionProxyPingbackClient(
37 net::URLRequestContextGetter* url_request_context); 43 net::URLRequestContextGetter* url_request_context);
38 ~DataReductionProxyPingbackClient() override; 44 ~DataReductionProxyPingbackClient() override;
39 45
40 // Sends a pingback to the data saver proxy server about various timing 46 // Sends a pingback to the data saver proxy server about various timing
41 // information. 47 // information.
42 virtual void SendPingback(const DataReductionProxyData& data, 48 virtual void SendPingback(const DataReductionProxyData& data,
43 const DataReductionProxyPageLoadTiming& timing); 49 const DataReductionProxyPageLoadTiming& timing);
44 50
45 // Sets the probability of actually sending a pingback to the server for any 51 // Sets the probability of actually sending a pingback to the server for any
46 // call to SendPingback. 52 // call to SendPingback.
47 void SetPingbackReportingFraction(float pingback_reporting_fraction); 53 void SetPingbackReportingFraction(float pingback_reporting_fraction);
48 54
55 // Adds an opt out for |tab_identifier_key| for a data saver |page_id|. An opt
56 // out occurs when users dismiss the preview in favor of the full page.
57 void AddOptOut(const NavigationID& navigation_id);
58
59 // Removes any stored data associated with |tab_identifier_key| in a task that
60 // runs later.
61 void ClearNavigationKeyAsync(const NavigationID& navigation_id);
62
63 // The total number of pending loads being tracked due to opt outs.
64 size_t OptOutsSizeForTesting() const;
65
49 protected: 66 protected:
50 // Generates a float in the range [0, 1). Virtualized in testing. 67 // Generates a float in the range [0, 1). Virtualized in testing.
51 virtual float GenerateRandomFloat() const; 68 virtual float GenerateRandomFloat() const;
52 69
53 // Returns the current time. Virtualized in testing. 70 // Returns the current time. Virtualized in testing.
54 virtual base::Time CurrentTime() const; 71 virtual base::Time CurrentTime() const;
55 72
56 private: 73 private:
57 // URLFetcherDelegate implmentation: 74 // URLFetcherDelegate implmentation:
58 void OnURLFetchComplete(const net::URLFetcher* source) override; 75 void OnURLFetchComplete(const net::URLFetcher* source) override;
59 76
60 // Whether a pingback should be sent. 77 // Whether a pingback should be sent.
61 bool ShouldSendPingback() const; 78 bool ShouldSendPingback() const;
62 79
63 // Creates an URLFetcher that will POST to |secure_proxy_url_| using 80 // Creates an URLFetcher that will POST to |secure_proxy_url_| using
64 // |url_request_context_|. The max retries is set to 5. 81 // |url_request_context_|. The max retries is set to 5.
65 // |data_to_send_| will be used to fill the body of the Fetcher, and will be 82 // |data_to_send_| will be used to fill the body of the Fetcher, and will be
66 // reset to an empty RecordPageloadMetricsRequest. 83 // reset to an empty RecordPageloadMetricsRequest.
67 void CreateFetcherForDataAndStart(); 84 void CreateFetcherForDataAndStart();
68 85
86 // Removes any stored data associated with |tab_identifier_key|.
87 void ClearNavigationKeySync(const NavigationID& navigation_id);
88
69 net::URLRequestContextGetter* url_request_context_; 89 net::URLRequestContextGetter* url_request_context_;
70 90
71 // The URL for the data saver proxy's ping back service. 91 // The URL for the data saver proxy's ping back service.
72 const GURL pingback_url_; 92 const GURL pingback_url_;
73 93
74 // The currently running fetcher. 94 // The currently running fetcher.
75 std::unique_ptr<net::URLFetcher> current_fetcher_; 95 std::unique_ptr<net::URLFetcher> current_fetcher_;
76 96
77 // Serialized data to send to the data saver proxy server. 97 // Serialized data to send to the data saver proxy server.
78 RecordPageloadMetricsRequest metrics_request_; 98 RecordPageloadMetricsRequest metrics_request_;
79 99
80 // The probability of sending a pingback to the server. 100 // The probability of sending a pingback to the server.
81 float pingback_reporting_fraction_; 101 float pingback_reporting_fraction_;
82 102
103 // The map of tab identifier keys to page IDs.
104 std::set<NavigationID> opt_outs_;
105
83 base::ThreadChecker thread_checker_; 106 base::ThreadChecker thread_checker_;
84 107
85 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyPingbackClient); 108 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyPingbackClient);
86 }; 109 };
87 110
88 } // namespace data_reduction_proxy 111 } // namespace data_reduction_proxy
89 112
90 #endif // COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_PIN GBACK_CLIENT_H_ 113 #endif // COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_PIN GBACK_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698