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

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

Issue 1546143002: Switch to standard integer types in components/, part 1 of 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_COMPRE SSION_STATS_H_ 5 #ifndef COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_COMPRE SSION_STATS_H_
6 #define COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_COMPRE SSION_STATS_H_ 6 #define COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_COMPRE SSION_STATS_H_
7 7
8 #include <stddef.h>
8 #include <stdint.h> 9 #include <stdint.h>
9 10
10 #include <map> 11 #include <map>
11 #include <string> 12 #include <string>
12 13
13 #include "base/containers/scoped_ptr_hash_map.h" 14 #include "base/containers/scoped_ptr_hash_map.h"
14 #include "base/macros.h" 15 #include "base/macros.h"
15 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
16 #include "base/memory/weak_ptr.h" 17 #include "base/memory/weak_ptr.h"
17 #include "base/prefs/pref_member.h" 18 #include "base/prefs/pref_member.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 // If |delay| is zero, writes directly to the PrefService and does not store 71 // If |delay| is zero, writes directly to the PrefService and does not store
71 // in the maps. 72 // in the maps.
72 DataReductionProxyCompressionStats(DataReductionProxyService* service, 73 DataReductionProxyCompressionStats(DataReductionProxyService* service,
73 PrefService* pref_service, 74 PrefService* pref_service,
74 const base::TimeDelta& delay); 75 const base::TimeDelta& delay);
75 ~DataReductionProxyCompressionStats() override; 76 ~DataReductionProxyCompressionStats() override;
76 77
77 // Records detailed data usage broken down by connection type and domain. Also 78 // Records detailed data usage broken down by connection type and domain. Also
78 // records daily data savings statistics to prefs and reports data savings 79 // records daily data savings statistics to prefs and reports data savings
79 // UMA. |compressed_size| and |original_size| are measured in bytes. 80 // UMA. |compressed_size| and |original_size| are measured in bytes.
80 void UpdateContentLengths(int64 compressed_size, 81 void UpdateContentLengths(int64_t compressed_size,
81 int64 original_size, 82 int64_t original_size,
82 bool data_reduction_proxy_enabled, 83 bool data_reduction_proxy_enabled,
83 DataReductionProxyRequestType request_type, 84 DataReductionProxyRequestType request_type,
84 const std::string& data_usage_host, 85 const std::string& data_usage_host,
85 const std::string& mime_type); 86 const std::string& mime_type);
86 87
87 // Creates a |Value| summary of the persistent state of the network session. 88 // Creates a |Value| summary of the persistent state of the network session.
88 // The caller is responsible for deleting the returned value. 89 // The caller is responsible for deleting the returned value.
89 // Must be called on the UI thread. 90 // Must be called on the UI thread.
90 base::Value* HistoricNetworkStatsInfoToValue(); 91 base::Value* HistoricNetworkStatsInfoToValue();
91 92
92 // Returns the time in milliseconds since epoch that the last update was made 93 // Returns the time in milliseconds since epoch that the last update was made
93 // to the daily original and received content lengths. 94 // to the daily original and received content lengths.
94 int64 GetLastUpdateTime(); 95 int64_t GetLastUpdateTime();
95 96
96 // Resets daily content length statistics. 97 // Resets daily content length statistics.
97 void ResetStatistics(); 98 void ResetStatistics();
98 99
99 // Clears all data saving statistics. 100 // Clears all data saving statistics.
100 void ClearDataSavingStatistics(); 101 void ClearDataSavingStatistics();
101 102
102 // Returns a list of all the daily content lengths. 103 // Returns a list of all the daily content lengths.
103 ContentLengthList GetDailyContentLengths(const char* pref_name); 104 ContentLengthList GetDailyContentLengths(const char* pref_name);
104 105
105 // Returns aggregate received and original content lengths over the specified 106 // Returns aggregate received and original content lengths over the specified
106 // number of days, as well as the time these stats were last updated. 107 // number of days, as well as the time these stats were last updated.
107 void GetContentLengths(unsigned int days, 108 void GetContentLengths(unsigned int days,
108 int64* original_content_length, 109 int64_t* original_content_length,
109 int64* received_content_length, 110 int64_t* received_content_length,
110 int64* last_update_time); 111 int64_t* last_update_time);
111 112
112 // Calls |get_data_usage_callback| with full data usage history. In-memory 113 // Calls |get_data_usage_callback| with full data usage history. In-memory
113 // data usage stats are flushed to storage before querying for full history. 114 // data usage stats are flushed to storage before querying for full history.
114 // An empty vector will be returned if "data_usage_reporting.enabled" pref is 115 // An empty vector will be returned if "data_usage_reporting.enabled" pref is
115 // not enabled or if called immediately after enabling the pref before 116 // not enabled or if called immediately after enabling the pref before
116 // in-memory stats could be initialized from storage. Data usage is sorted 117 // in-memory stats could be initialized from storage. Data usage is sorted
117 // chronologically with the last entry corresponding to |base::Time::Now()|. 118 // chronologically with the last entry corresponding to |base::Time::Now()|.
118 void GetHistoricalDataUsage( 119 void GetHistoricalDataUsage(
119 const HistoricalDataUsageCallback& get_data_usage_callback); 120 const HistoricalDataUsageCallback& get_data_usage_callback);
120 121
(...skipping 11 matching lines...) Expand all
132 // structures used to collect data usage. |data_usage| contains the data usage 133 // structures used to collect data usage. |data_usage| contains the data usage
133 // for the last stored interval. 134 // for the last stored interval.
134 void OnCurrentDataUsageLoaded(scoped_ptr<DataUsageBucket> data_usage); 135 void OnCurrentDataUsageLoaded(scoped_ptr<DataUsageBucket> data_usage);
135 136
136 private: 137 private:
137 // Enum to track the state of loading data usage from storage. 138 // Enum to track the state of loading data usage from storage.
138 enum CurrentDataUsageLoadStatus { NOT_LOADED = 0, LOADING = 1, LOADED = 2 }; 139 enum CurrentDataUsageLoadStatus { NOT_LOADED = 0, LOADING = 1, LOADED = 2 };
139 140
140 friend class DataReductionProxyCompressionStatsTest; 141 friend class DataReductionProxyCompressionStatsTest;
141 142
142 typedef std::map<const char*, int64> DataReductionProxyPrefMap; 143 typedef std::map<const char*, int64_t> DataReductionProxyPrefMap;
143 typedef base::ScopedPtrHashMap<const char*, scoped_ptr<base::ListValue>> 144 typedef base::ScopedPtrHashMap<const char*, scoped_ptr<base::ListValue>>
144 DataReductionProxyListPrefMap; 145 DataReductionProxyListPrefMap;
145 146
146 // Loads all data_reduction_proxy::prefs into the |pref_map_| and 147 // Loads all data_reduction_proxy::prefs into the |pref_map_| and
147 // |list_pref_map_|. 148 // |list_pref_map_|.
148 void Init(); 149 void Init();
149 150
150 // Gets the value of |pref| from the pref service and adds it to the 151 // Gets the value of |pref| from the pref service and adds it to the
151 // |pref_map|. 152 // |pref_map|.
152 void InitInt64Pref(const char* pref); 153 void InitInt64Pref(const char* pref);
153 154
154 // Gets the value of |pref| from the pref service and adds it to the 155 // Gets the value of |pref| from the pref service and adds it to the
155 // |list_pref_map|. 156 // |list_pref_map|.
156 void InitListPref(const char* pref); 157 void InitListPref(const char* pref);
157 158
158 void OnUpdateContentLengths(); 159 void OnUpdateContentLengths();
159 160
160 // Gets the int64 pref at |pref_path| from the |DataReductionProxyPrefMap|. 161 // Gets the int64_t pref at |pref_path| from the |DataReductionProxyPrefMap|.
161 int64 GetInt64(const char* pref_path); 162 int64_t GetInt64(const char* pref_path);
162 163
163 // Updates the pref value in the |DataReductionProxyPrefMap| map. 164 // Updates the pref value in the |DataReductionProxyPrefMap| map.
164 // The pref is later written to |pref service_|. 165 // The pref is later written to |pref service_|.
165 void SetInt64(const char* pref_path, int64 pref_value); 166 void SetInt64(const char* pref_path, int64_t pref_value);
166 167
167 // Increments the pref value in the |DataReductionProxyPrefMap| map. 168 // Increments the pref value in the |DataReductionProxyPrefMap| map.
168 // The pref is later written to |pref service_|. 169 // The pref is later written to |pref service_|.
169 void IncrementInt64Pref(const char* pref_path, int64_t pref_increment); 170 void IncrementInt64Pref(const char* pref_path, int64_t pref_increment);
170 171
171 // Gets the pref list at |pref_path| from the |DataReductionProxyPrefMap|. 172 // Gets the pref list at |pref_path| from the |DataReductionProxyPrefMap|.
172 base::ListValue* GetList(const char* pref_path); 173 base::ListValue* GetList(const char* pref_path);
173 174
174 // Writes the prefs stored in |DataReductionProxyPrefMap| and 175 // Writes the prefs stored in |DataReductionProxyPrefMap| and
175 // |DataReductionProxyListPrefMap| to |pref_service|. 176 // |DataReductionProxyListPrefMap| to |pref_service|.
176 void WritePrefs(); 177 void WritePrefs();
177 178
178 // Starts a timer (if necessary) to write prefs in |kMinutesBetweenWrites| to 179 // Starts a timer (if necessary) to write prefs in |kMinutesBetweenWrites| to
179 // the |pref_service|. 180 // the |pref_service|.
180 void DelayedWritePrefs(); 181 void DelayedWritePrefs();
181 182
182 // Copies the values at each index of |from_list| to the same index in 183 // Copies the values at each index of |from_list| to the same index in
183 // |to_list|. 184 // |to_list|.
184 void TransferList(const base::ListValue& from_list, 185 void TransferList(const base::ListValue& from_list,
185 base::ListValue* to_list); 186 base::ListValue* to_list);
186 187
187 // Gets an int64, stored as a string, in a ListPref at the specified 188 // Gets an int64_t, stored as a string, in a ListPref at the specified
188 // index. 189 // index.
189 int64 GetListPrefInt64Value(const base::ListValue& list_update, size_t index); 190 int64_t GetListPrefInt64Value(const base::ListValue& list_update,
191 size_t index);
190 192
191 // Records content length updates to prefs. 193 // Records content length updates to prefs.
192 void RecordRequestSizePrefs(int64 compressed_size, 194 void RecordRequestSizePrefs(int64_t compressed_size,
193 int64 original_size, 195 int64_t original_size,
194 bool with_data_reduction_proxy_enabled, 196 bool with_data_reduction_proxy_enabled,
195 DataReductionProxyRequestType request_type, 197 DataReductionProxyRequestType request_type,
196 const std::string& mime_type, 198 const std::string& mime_type,
197 const base::Time& now); 199 const base::Time& now);
198 200
199 void IncrementDailyUmaPrefs(int64_t original_size, 201 void IncrementDailyUmaPrefs(int64_t original_size,
200 int64_t received_size, 202 int64_t received_size,
201 const char* original_size_pref, 203 const char* original_size_pref,
202 const char* received_size_pref, 204 const char* received_size_pref,
203 bool data_reduction_proxy_enabled, 205 bool data_reduction_proxy_enabled,
204 const char* original_size_with_proxy_enabled_pref, 206 const char* original_size_with_proxy_enabled_pref,
205 const char* recevied_size_with_proxy_enabled_pref, 207 const char* recevied_size_with_proxy_enabled_pref,
206 bool via_data_reduction_proxy, 208 bool via_data_reduction_proxy,
207 const char* original_size_via_proxy_pref, 209 const char* original_size_via_proxy_pref,
208 const char* received_size_via_proxy_pref); 210 const char* received_size_via_proxy_pref);
209 211
210 // Record UMA with data savings bytes and percent over the past 212 // Record UMA with data savings bytes and percent over the past
211 // |DataReductionProxy::kNumDaysInHistorySummary| days. These numbers 213 // |DataReductionProxy::kNumDaysInHistorySummary| days. These numbers
212 // are displayed to users as their data savings. 214 // are displayed to users as their data savings.
213 void RecordUserVisibleDataSavings(); 215 void RecordUserVisibleDataSavings();
214 216
215 // Record data usage and original size of request broken down by host. |time| 217 // Record data usage and original size of request broken down by host. |time|
216 // is the time at which the data usage occurred. This method should be called 218 // is the time at which the data usage occurred. This method should be called
217 // in real time, so |time| is expected to be |Time::Now()|. 219 // in real time, so |time| is expected to be |Time::Now()|.
218 void RecordDataUsage(const std::string& data_usage_host, 220 void RecordDataUsage(const std::string& data_usage_host,
219 int64 original_request_size, 221 int64_t original_request_size,
220 int64 data_used, 222 int64_t data_used,
221 const base::Time& time); 223 const base::Time& time);
222 224
223 // Persists the in memory data usage information to storage and clears all 225 // Persists the in memory data usage information to storage and clears all
224 // in-memory data usage. Do not call this method unless |data_usage_loaded_| 226 // in-memory data usage. Do not call this method unless |data_usage_loaded_|
225 // is |LOADED|. 227 // is |LOADED|.
226 void PersistDataUsage(); 228 void PersistDataUsage();
227 229
228 // Deletes all historical data usage from storage and memory. This method 230 // Deletes all historical data usage from storage and memory. This method
229 // should not be called when |current_data_usage_load_status_| is |LOADING|. 231 // should not be called when |current_data_usage_load_status_| is |LOADING|.
230 void DeleteHistoricalDataUsage(); 232 void DeleteHistoricalDataUsage();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 base::ThreadChecker thread_checker_; 276 base::ThreadChecker thread_checker_;
275 277
276 base::WeakPtrFactory<DataReductionProxyCompressionStats> weak_factory_; 278 base::WeakPtrFactory<DataReductionProxyCompressionStats> weak_factory_;
277 279
278 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyCompressionStats); 280 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyCompressionStats);
279 }; 281 };
280 282
281 } // namespace data_reduction_proxy 283 } // namespace data_reduction_proxy
282 284
283 #endif // COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_COM PRESSION_STATS_H_ 285 #endif // COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_COM PRESSION_STATS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698