Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/toolkit/components/url-classifier/UrlClassifierTelemetryUtils.cpp
Line
Count
Source (jump to first uncovered line)
1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
 *  * License, v. 2.0. If a copy of the MPL was not distributed with this
3
 *   * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5
#include "UrlClassifierTelemetryUtils.h"
6
#include "mozilla/Assertions.h"
7
8
namespace mozilla {
9
namespace safebrowsing {
10
11
uint8_t
12
NetworkErrorToBucket(nsresult rv)
13
{
14
  switch(rv) {
15
  // Connection errors
16
  case NS_ERROR_ALREADY_CONNECTED:        return 2;
17
  case NS_ERROR_NOT_CONNECTED:            return 3;
18
  case NS_ERROR_CONNECTION_REFUSED:       return 4;
19
  case NS_ERROR_NET_TIMEOUT:              return 5;
20
  case NS_ERROR_OFFLINE:                  return 6;
21
  case NS_ERROR_PORT_ACCESS_NOT_ALLOWED:  return 7;
22
  case NS_ERROR_NET_RESET:                return 8;
23
  case NS_ERROR_NET_INTERRUPT:            return 9;
24
  case NS_ERROR_PROXY_CONNECTION_REFUSED: return 10;
25
  case NS_ERROR_NET_PARTIAL_TRANSFER:     return 11;
26
  case NS_ERROR_NET_INADEQUATE_SECURITY:  return 12;
27
  // DNS errors
28
  case NS_ERROR_UNKNOWN_HOST:             return 13;
29
  case NS_ERROR_DNS_LOOKUP_QUEUE_FULL:    return 14;
30
  case NS_ERROR_UNKNOWN_PROXY_HOST:       return 15;
31
  // Others
32
  default:                                return 1;
33
  }
34
}
35
36
uint32_t
37
HTTPStatusToBucket(uint32_t status)
38
0
{
39
0
  uint32_t statusBucket;
40
0
  switch (status) {
41
0
  case 100:
42
0
  case 101:
43
0
    // Unexpected 1xx return code
44
0
    statusBucket = 0;
45
0
    break;
46
0
  case 200:
47
0
    // OK - Data is available in the HTTP response body.
48
0
    statusBucket = 1;
49
0
    break;
50
0
  case 201:
51
0
  case 202:
52
0
  case 203:
53
0
  case 205:
54
0
  case 206:
55
0
    // Unexpected 2xx return code
56
0
    statusBucket = 2;
57
0
    break;
58
0
  case 204:
59
0
    // No Content
60
0
    statusBucket = 3;
61
0
    break;
62
0
  case 300:
63
0
  case 301:
64
0
  case 302:
65
0
  case 303:
66
0
  case 304:
67
0
  case 305:
68
0
  case 307:
69
0
  case 308:
70
0
    // Unexpected 3xx return code
71
0
    statusBucket = 4;
72
0
    break;
73
0
  case 400:
74
0
    // Bad Request - The HTTP request was not correctly formed.
75
0
    // The client did not provide all required CGI parameters.
76
0
    statusBucket = 5;
77
0
    break;
78
0
  case 401:
79
0
  case 402:
80
0
  case 405:
81
0
  case 406:
82
0
  case 407:
83
0
  case 409:
84
0
  case 410:
85
0
  case 411:
86
0
  case 412:
87
0
  case 414:
88
0
  case 415:
89
0
  case 416:
90
0
  case 417:
91
0
  case 421:
92
0
  case 426:
93
0
  case 428:
94
0
  case 429:
95
0
  case 431:
96
0
  case 451:
97
0
    // Unexpected 4xx return code
98
0
    statusBucket = 6;
99
0
    break;
100
0
  case 403:
101
0
    // Forbidden - The client id is invalid.
102
0
    statusBucket = 7;
103
0
    break;
104
0
  case 404:
105
0
    // Not Found
106
0
    statusBucket = 8;
107
0
    break;
108
0
  case 408:
109
0
    // Request Timeout
110
0
    statusBucket = 9;
111
0
    break;
112
0
  case 413:
113
0
    // Request Entity Too Large - Bug 1150334
114
0
    statusBucket = 10;
115
0
    break;
116
0
  case 500:
117
0
  case 501:
118
0
  case 510:
119
0
    // Unexpected 5xx return code
120
0
    statusBucket = 11;
121
0
    break;
122
0
  case 502:
123
0
  case 504:
124
0
  case 511:
125
0
    // Local network errors, we'll ignore these.
126
0
    statusBucket = 12;
127
0
    break;
128
0
  case 503:
129
0
    // Service Unavailable - The server cannot handle the request.
130
0
    // Clients MUST follow the backoff behavior specified in the
131
0
    // Request Frequency section.
132
0
    statusBucket = 13;
133
0
    break;
134
0
  case 505:
135
0
    // HTTP Version Not Supported - The server CANNOT handle the requested
136
0
    // protocol major version.
137
0
    statusBucket = 14;
138
0
    break;
139
0
  default:
140
0
    statusBucket = 15;
141
0
  };
142
0
  return statusBucket;
143
0
}
144
145
} // namespace safebrowsing
146
} // namespace mozilla