OLD | NEW |
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 #include "extensions/browser/api/cast_channel/logger.h" | 5 #include "extensions/browser/api/cast_channel/logger.h" |
6 | 6 |
| 7 #include <string> |
| 8 |
7 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
8 #include "base/time/tick_clock.h" | 10 #include "base/time/tick_clock.h" |
9 #include "extensions/browser/api/cast_channel/cast_auth_util.h" | 11 #include "extensions/browser/api/cast_channel/cast_auth_util.h" |
10 #include "extensions/browser/api/cast_channel/logger_util.h" | 12 #include "extensions/browser/api/cast_channel/logger_util.h" |
11 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
12 #include "third_party/zlib/zlib.h" | 14 #include "third_party/zlib/zlib.h" |
13 | 15 |
14 namespace extensions { | 16 namespace extensions { |
15 namespace core_api { | 17 namespace core_api { |
16 namespace cast_channel { | 18 namespace cast_channel { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 | 93 |
92 result = deflateEnd(&stream); | 94 result = deflateEnd(&stream); |
93 DCHECK(result == Z_OK || result == Z_DATA_ERROR); | 95 DCHECK(result == Z_OK || result == Z_DATA_ERROR); |
94 | 96 |
95 if (success) | 97 if (success) |
96 *length = out_size - stream.avail_out; | 98 *length = out_size - stream.avail_out; |
97 | 99 |
98 return out.Pass(); | 100 return out.Pass(); |
99 } | 101 } |
100 | 102 |
| 103 // Propagate any error fields set in |event| to |last_errors|. If any error |
| 104 // field in |event| is set, then also set |last_errors->event_type|. |
| 105 void MaybeSetLastErrors(const SocketEvent& event, LastErrors* last_errors) { |
| 106 if (event.has_net_return_value() && |
| 107 event.net_return_value() < net::ERR_IO_PENDING) { |
| 108 last_errors->net_return_value = event.net_return_value(); |
| 109 last_errors->event_type = event.type(); |
| 110 } |
| 111 if (event.has_challenge_reply_error_type()) { |
| 112 last_errors->challenge_reply_error_type = |
| 113 event.challenge_reply_error_type(); |
| 114 last_errors->event_type = event.type(); |
| 115 } |
| 116 if (event.has_nss_error_code()) { |
| 117 last_errors->nss_error_code = event.nss_error_code(); |
| 118 last_errors->event_type = event.type(); |
| 119 } |
| 120 } |
| 121 |
101 } // namespace | 122 } // namespace |
102 | 123 |
103 Logger::AggregatedSocketEventLog::AggregatedSocketEventLog() { | 124 Logger::AggregatedSocketEventLog::AggregatedSocketEventLog() { |
104 } | 125 } |
105 | 126 |
106 Logger::AggregatedSocketEventLog::~AggregatedSocketEventLog() { | 127 Logger::AggregatedSocketEventLog::~AggregatedSocketEventLog() { |
107 } | 128 } |
108 | 129 |
109 Logger::Logger(scoped_ptr<base::TickClock> clock, | 130 Logger::Logger(scoped_ptr<base::TickClock> clock, |
110 base::TimeTicks unix_epoch_time_ticks) | 131 base::TimeTicks unix_epoch_time_ticks) |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 channel_id, make_linked_ptr(new AggregatedSocketEventLog))) | 301 channel_id, make_linked_ptr(new AggregatedSocketEventLog))) |
281 .first; | 302 .first; |
282 it->second->aggregated_socket_event.set_id(channel_id); | 303 it->second->aggregated_socket_event.set_id(channel_id); |
283 } | 304 } |
284 | 305 |
285 std::deque<proto::SocketEvent>& socket_events = it->second->socket_events; | 306 std::deque<proto::SocketEvent>& socket_events = it->second->socket_events; |
286 if (socket_events.size() >= kMaxEventsPerSocket) { | 307 if (socket_events.size() >= kMaxEventsPerSocket) { |
287 socket_events.pop_front(); | 308 socket_events.pop_front(); |
288 log_.set_num_evicted_socket_events(log_.num_evicted_socket_events() + 1); | 309 log_.set_num_evicted_socket_events(log_.num_evicted_socket_events() + 1); |
289 } | 310 } |
290 | |
291 socket_events.push_back(socket_event); | 311 socket_events.push_back(socket_event); |
292 | 312 |
293 it->second->last_errors.event_type = socket_event.type(); | 313 MaybeSetLastErrors(socket_event, &(it->second->last_errors)); |
294 if (socket_event.has_net_return_value()) { | |
295 it->second->last_errors.net_return_value = socket_event.net_return_value(); | |
296 } | |
297 if (socket_event.has_challenge_reply_error_type()) { | |
298 it->second->last_errors.challenge_reply_error_type = | |
299 socket_event.challenge_reply_error_type(); | |
300 } | |
301 if (socket_event.has_nss_error_code()) | |
302 it->second->last_errors.nss_error_code = socket_event.nss_error_code(); | |
303 | 314 |
304 return it->second->aggregated_socket_event; | 315 return it->second->aggregated_socket_event; |
305 } | 316 } |
306 | 317 |
307 scoped_ptr<char[]> Logger::GetLogs(size_t* length) const { | 318 scoped_ptr<char[]> Logger::GetLogs(size_t* length) const { |
308 *length = 0; | 319 *length = 0; |
309 | 320 |
310 Log log; | 321 Log log; |
311 // Copy "global" values from |log_|. Don't use |log_| directly since this | 322 // Copy "global" values from |log_|. Don't use |log_| directly since this |
312 // function is const. | 323 // function is const. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 AggregatedSocketEventLogMap::const_iterator it = | 360 AggregatedSocketEventLogMap::const_iterator it = |
350 aggregated_socket_events_.find(channel_id); | 361 aggregated_socket_events_.find(channel_id); |
351 if (it != aggregated_socket_events_.end()) { | 362 if (it != aggregated_socket_events_.end()) { |
352 return it->second->last_errors; | 363 return it->second->last_errors; |
353 } else { | 364 } else { |
354 return LastErrors(); | 365 return LastErrors(); |
355 } | 366 } |
356 } | 367 } |
357 | 368 |
358 } // namespace cast_channel | 369 } // namespace cast_channel |
359 } // namespace api | 370 } // namespace core_api |
360 } // namespace extensions | 371 } // namespace extensions |
OLD | NEW |