Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / net / spdyproxy / data_saving_metrics.h
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_NET_SPDYPROXY_DATA_SAVING_METRICS_H_
6 #define CHROME_BROWSER_NET_SPDYPROXY_DATA_SAVING_METRICS_H_
7
8 #include "base/time/time.h"
9
10 namespace net {
11 class URLRequest;
12 }
13
14 class PrefService;
15
16 namespace spdyproxy {
17
18 enum DataReductionRequestType {
19   VIA_DATA_REDUCTION_PROXY,  // A request served by the data reduction proxy.
20
21   // Below are reasons why a request is not served by the enabled data
22   // reduction proxy. We don't count off-the-record profile data in all cases.
23   HTTPS,  // An https request.
24   SHORT_BYPASS,  // The client is bypassed by the proxy for a short time.
25   LONG_BYPASS,  // The client is bypassed by the proxy for a long time (due
26                 // to country bypass policy, for example).
27   UNKNOWN_TYPE,  // Any other reason not listed above.
28 };
29
30 // Returns DataReductionRequestType for |request|.
31 DataReductionRequestType GetDataReductionRequestType(
32     const net::URLRequest* request);
33
34 // Returns |received_content_length| as adjusted original content length if
35 // |original_content_length| has the invalid value (-1) or |data_reduction_type|
36 // is not |VIA_DATA_REDUCTION_PROXY|.
37 int64 GetAdjustedOriginalContentLength(
38     DataReductionRequestType data_reduction_type,
39     int64 original_content_length,
40     int64 received_content_length);
41
42 #if defined(OS_ANDROID) || defined(OS_IOS)
43 // This is only exposed for testing. It is normally called by
44 // UpdateContentLengthPrefs.
45 void UpdateContentLengthPrefsForDataReductionProxy(
46     int received_content_length,
47     int original_content_length,
48     bool with_data_reduction_proxy_enabled,
49     DataReductionRequestType data_reduction_type,
50     base::Time now, PrefService* prefs);
51 #endif
52
53 // Records daily data savings statistics to prefs and reports data savings UMA.
54 void UpdateContentLengthPrefs(
55     int received_content_length,
56     int original_content_length,
57     bool with_data_reduction_proxy_enabled,
58     DataReductionRequestType data_reduction_type,
59     PrefService* prefs);
60
61 }  // namespace spdyproxy
62
63 #endif  // CHROME_BROWSER_NET_SPDYPROXY_DATA_SAVING_METRICS_H_