OLD | NEW |
---|---|
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> |
9 #include <string> | 11 #include <string> |
10 | 12 |
11 #include "base/macros.h" | 13 #include "base/macros.h" |
12 #include "base/threading/thread_checker.h" | 14 #include "base/threading/thread_checker.h" |
13 #include "components/data_reduction_proxy/proto/pageload_metrics.pb.h" | 15 #include "components/data_reduction_proxy/proto/pageload_metrics.pb.h" |
14 #include "net/url_request/url_fetcher_delegate.h" | 16 #include "net/url_request/url_fetcher_delegate.h" |
15 #include "url/gurl.h" | 17 #include "url/gurl.h" |
16 | 18 |
17 namespace base { | 19 namespace base { |
(...skipping 15 matching lines...) Expand all Loading... | |
33 public: | 35 public: |
34 // The caller must ensure that |url_request_context| remains alive for the | 36 // The caller must ensure that |url_request_context| remains alive for the |
35 // lifetime of the |DataReductionProxyPingbackClient| instance. | 37 // lifetime of the |DataReductionProxyPingbackClient| instance. |
36 explicit DataReductionProxyPingbackClient( | 38 explicit DataReductionProxyPingbackClient( |
37 net::URLRequestContextGetter* url_request_context); | 39 net::URLRequestContextGetter* url_request_context); |
38 ~DataReductionProxyPingbackClient() override; | 40 ~DataReductionProxyPingbackClient() override; |
39 | 41 |
40 // Sends a pingback to the data saver proxy server about various timing | 42 // Sends a pingback to the data saver proxy server about various timing |
41 // information. | 43 // information. |
42 virtual void SendPingback(const DataReductionProxyData& data, | 44 virtual void SendPingback(const DataReductionProxyData& data, |
43 const DataReductionProxyPageLoadTiming& timing); | 45 const DataReductionProxyPageLoadTiming& timing, |
46 const void* tab_identifier_key); | |
44 | 47 |
45 // Sets the probability of actually sending a pingback to the server for any | 48 // Sets the probability of actually sending a pingback to the server for any |
46 // call to SendPingback. | 49 // call to SendPingback. |
47 void SetPingbackReportingFraction(float pingback_reporting_fraction); | 50 void SetPingbackReportingFraction(float pingback_reporting_fraction); |
48 | 51 |
52 // Adds an opt out for |tab_identifier_key| for a data saver |page_id|. | |
bengr
2017/04/20 17:36:19
What's an opt out? Define somewhere.
RyanSturm
2017/04/20 20:25:45
Done.
| |
53 void AddOptOut(const void* tab_identifier_key, uint64_t page_id); | |
54 | |
55 // Removes any stored data associated with |tab_identifier_key| in a task that | |
56 // runs later. | |
57 void ClearTabKeyAsync(const void* tab_identifier_key); | |
58 | |
59 // The total number of pending loads being tracked due to opt outs. | |
60 size_t PendingTabLoadsForTesting() const; | |
61 | |
49 protected: | 62 protected: |
50 // Generates a float in the range [0, 1). Virtualized in testing. | 63 // Generates a float in the range [0, 1). Virtualized in testing. |
51 virtual float GenerateRandomFloat() const; | 64 virtual float GenerateRandomFloat() const; |
52 | 65 |
53 // Returns the current time. Virtualized in testing. | 66 // Returns the current time. Virtualized in testing. |
54 virtual base::Time CurrentTime() const; | 67 virtual base::Time CurrentTime() const; |
55 | 68 |
56 private: | 69 private: |
57 // URLFetcherDelegate implmentation: | 70 // URLFetcherDelegate implmentation: |
58 void OnURLFetchComplete(const net::URLFetcher* source) override; | 71 void OnURLFetchComplete(const net::URLFetcher* source) override; |
59 | 72 |
60 // Whether a pingback should be sent. | 73 // Whether a pingback should be sent. |
61 bool ShouldSendPingback() const; | 74 bool ShouldSendPingback() const; |
62 | 75 |
63 // Creates an URLFetcher that will POST to |secure_proxy_url_| using | 76 // Creates an URLFetcher that will POST to |secure_proxy_url_| using |
64 // |url_request_context_|. The max retries is set to 5. | 77 // |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 | 78 // |data_to_send_| will be used to fill the body of the Fetcher, and will be |
66 // reset to an empty RecordPageloadMetricsRequest. | 79 // reset to an empty RecordPageloadMetricsRequest. |
67 void CreateFetcherForDataAndStart(); | 80 void CreateFetcherForDataAndStart(); |
68 | 81 |
82 // Removes any stored data associated with |tab_identifier_key|. | |
83 void ClearTabKeySync(const void* tab_identifier_key); | |
84 | |
69 net::URLRequestContextGetter* url_request_context_; | 85 net::URLRequestContextGetter* url_request_context_; |
70 | 86 |
71 // The URL for the data saver proxy's ping back service. | 87 // The URL for the data saver proxy's ping back service. |
72 const GURL pingback_url_; | 88 const GURL pingback_url_; |
73 | 89 |
74 // The currently running fetcher. | 90 // The currently running fetcher. |
75 std::unique_ptr<net::URLFetcher> current_fetcher_; | 91 std::unique_ptr<net::URLFetcher> current_fetcher_; |
76 | 92 |
77 // Serialized data to send to the data saver proxy server. | 93 // Serialized data to send to the data saver proxy server. |
78 RecordPageloadMetricsRequest metrics_request_; | 94 RecordPageloadMetricsRequest metrics_request_; |
79 | 95 |
80 // The probability of sending a pingback to the server. | 96 // The probability of sending a pingback to the server. |
81 float pingback_reporting_fraction_; | 97 float pingback_reporting_fraction_; |
82 | 98 |
99 // The map of tab identifier keys to page IDs. | |
100 std::map<const void*, uint64_t> tab_page_id_map_; | |
101 | |
83 base::ThreadChecker thread_checker_; | 102 base::ThreadChecker thread_checker_; |
84 | 103 |
85 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyPingbackClient); | 104 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyPingbackClient); |
86 }; | 105 }; |
87 | 106 |
88 } // namespace data_reduction_proxy | 107 } // namespace data_reduction_proxy |
89 | 108 |
90 #endif // COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_PIN GBACK_CLIENT_H_ | 109 #endif // COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_PIN GBACK_CLIENT_H_ |
OLD | NEW |