Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / net / base / file_stream_metrics_win.cc
1 // Copyright (c) 2011 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 #include "net/base/file_stream_metrics.h"
6
7 #include <windows.h>
8
9 #include "base/basictypes.h"
10
11 namespace net {
12
13 namespace {
14
15 struct Range {
16   int low;
17   int high;
18 };
19
20 // The error range list is extracted from WinError.h.
21 //
22 // NOTE: The gaps between the ranges need to be recorded too.
23 // They will have odd-numbered buckets.
24 const Range kErrorRangeList[] = {
25   { 0, 321 },  // 2.
26   { 335, 371 },  // 4.
27   { 383, 387 },  // 6.
28   { 399, 404 },  // etc.
29   { 415, 418 },
30   { 431, 433 },
31   { 447, 868 },
32   { 994, 1471 },
33   { 1500, 1513 },
34   { 1536, 1553 },
35   { 1601, 1654 },
36   { 1700, 1834 },
37   { 1898, 1938 },
38   { 2000, 2024 },
39   { 2048, 2085 },
40   { 2108, 2110 },
41   { 2202, 2203 },
42   { 2250, 2251 },
43   { 2401, 2405 },
44   { 3000, 3021 },
45   { 3950, 3951 },
46   { 4000, 4007 },
47   { 4050, 4066 },
48   { 4096, 4116 },
49   { 4200, 4215 },
50   { 4300, 4353 },
51   { 4390, 4395 },
52   { 4500, 4501 },
53   { 4864, 4905 },
54   { 5001, 5090 },
55   { 5890, 5953 },
56   { 6000, 6023 },
57   { 6118, 6119 },
58   { 6200, 6201 },
59   { 6600, 6649 },
60   { 6700, 6732 },
61   { 6800, 6856 },
62   { 7001, 7071 },
63   { 8001, 8018 },
64   { 8192, 8263 },
65   { 8301, 8640 },
66   { 8704, 8705 },
67   { 8960, 9053 },
68   { 9216, 9218 },
69   { 9263, 9276 },
70   { 9472, 9506 },
71   { 9550, 9573 },
72   { 9600, 9622 },
73   { 9650, 9656 },
74   { 9688, 9723 },
75   { 9750, 9754 },
76   { 9800, 9802 },
77   { 9850, 9853 },
78   { 9900, 9907 },
79   { 10000, 10072 },
80   { 10091, 10113 },
81   { 11001, 11034 },
82   { 12288, 12335 },
83   { 12544, 12559 },
84   { 12595, 12597 },
85   { 12801, 12803 },
86   { 13000, 13026 },
87   { 13800, 13933 },
88   { 14000, 14111 },
89   { 15000, 15039 },
90   { 15080, 15086 },
91   { 15100, 15109 },
92   { 15200, 15208 },
93   { 15250, 15251 },
94   { 15299, 15302 },
95   { 16385, 16436 },
96   { 18432, 18454 },
97   { 20480, 20486 },
98   { 24577, 24607 },
99   { 28673, 28698 },
100   { 32790, 32816 },
101   { 33281, 33322 },
102   { 35005, 35024 },
103   { 36000, 36004 },
104   { 40010, 40011 },
105   { 40067, 40069 },
106   { 53248, 53293 },
107   { 53376, 53382 },
108   { 57344, 57360 },
109   { 57377, 57394 },
110   { 65535, 65536 }  // 2 * kNumErrorRanges.
111 };
112 const size_t kNumErrorRanges = ARRAYSIZE_UNSAFE(kErrorRangeList);
113
114 }  // namespace
115
116 // Windows has very many errors.  We're not interested in most of them, but we
117 // don't know which ones are significant.
118 // This function maps error ranges to specific buckets.
119 // If we get hits on the buckets, we can add those values to the values we
120 // record individually.
121 // If we get values *between* the buckets, we record those as buckets too.
122 int GetFileErrorUmaBucket(int error) {
123   error = HRESULT_CODE(error);
124
125   // This is a linear search, but of a short fixed-size array.
126   // It also gets called infrequently, on errors.
127   for (size_t n = 0; n < kNumErrorRanges; ++n) {
128     if (error < kErrorRangeList[n].low)
129       return (2 * (n + 1)) - 1;  // In gap before the range.
130     if (error <= kErrorRangeList[n].high)
131       return 2 * (n + 1);  // In the range.
132   }
133
134   // After the last bucket.
135   return 2 * kNumErrorRanges + 1;
136 }
137
138 int MaxFileErrorUmaBucket() {
139   return 2 * kNumErrorRanges + 2;
140 }
141
142 int MaxFileErrorUmaValue() {
143   return kErrorRangeList[0].high + 1;
144 }
145
146 }  // namespace net