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 // Returns true if |event| has any error fields set. | |
104 bool IsErrorEvent(const SocketEvent& event) { | |
105 return (event.has_net_return_value() && | |
106 event.net_return_value() < net::ERR_IO_PENDING) || | |
107 event.has_challenge_reply_error_type() || event.has_nss_error_code(); | |
108 } | |
109 | |
101 } // namespace | 110 } // namespace |
102 | 111 |
103 Logger::AggregatedSocketEventLog::AggregatedSocketEventLog() { | 112 Logger::AggregatedSocketEventLog::AggregatedSocketEventLog() { |
104 } | 113 } |
105 | 114 |
106 Logger::AggregatedSocketEventLog::~AggregatedSocketEventLog() { | 115 Logger::AggregatedSocketEventLog::~AggregatedSocketEventLog() { |
107 } | 116 } |
108 | 117 |
109 Logger::Logger(scoped_ptr<base::TickClock> clock, | 118 Logger::Logger(scoped_ptr<base::TickClock> clock, |
110 base::TimeTicks unix_epoch_time_ticks) | 119 base::TimeTicks unix_epoch_time_ticks) |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
283 } | 292 } |
284 | 293 |
285 std::deque<proto::SocketEvent>& socket_events = it->second->socket_events; | 294 std::deque<proto::SocketEvent>& socket_events = it->second->socket_events; |
286 if (socket_events.size() >= kMaxEventsPerSocket) { | 295 if (socket_events.size() >= kMaxEventsPerSocket) { |
287 socket_events.pop_front(); | 296 socket_events.pop_front(); |
288 log_.set_num_evicted_socket_events(log_.num_evicted_socket_events() + 1); | 297 log_.set_num_evicted_socket_events(log_.num_evicted_socket_events() + 1); |
289 } | 298 } |
290 | 299 |
291 socket_events.push_back(socket_event); | 300 socket_events.push_back(socket_event); |
292 | 301 |
293 it->second->last_errors.event_type = socket_event.type(); | 302 if (IsErrorEvent(socket_event)) { |
miu
2014/10/11 02:16:44
This is up to you, but IMO it hurts readability to
mark a. foltz
2014/10/13 20:32:56
Not a fan of making the existing code block longer
| |
294 if (socket_event.has_net_return_value()) { | 303 it->second->last_errors.event_type = socket_event.type(); |
295 it->second->last_errors.net_return_value = socket_event.net_return_value(); | 304 if (socket_event.has_net_return_value()) { |
305 it->second->last_errors.net_return_value = | |
306 socket_event.net_return_value(); | |
307 } | |
308 if (socket_event.has_challenge_reply_error_type()) { | |
309 it->second->last_errors.challenge_reply_error_type = | |
310 socket_event.challenge_reply_error_type(); | |
311 } | |
312 if (socket_event.has_nss_error_code()) | |
313 it->second->last_errors.nss_error_code = socket_event.nss_error_code(); | |
296 } | 314 } |
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 | 315 |
304 return it->second->aggregated_socket_event; | 316 return it->second->aggregated_socket_event; |
305 } | 317 } |
306 | 318 |
307 scoped_ptr<char[]> Logger::GetLogs(size_t* length) const { | 319 scoped_ptr<char[]> Logger::GetLogs(size_t* length) const { |
308 *length = 0; | 320 *length = 0; |
309 | 321 |
310 Log log; | 322 Log log; |
311 // Copy "global" values from |log_|. Don't use |log_| directly since this | 323 // Copy "global" values from |log_|. Don't use |log_| directly since this |
312 // function is const. | 324 // function is const. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
349 AggregatedSocketEventLogMap::const_iterator it = | 361 AggregatedSocketEventLogMap::const_iterator it = |
350 aggregated_socket_events_.find(channel_id); | 362 aggregated_socket_events_.find(channel_id); |
351 if (it != aggregated_socket_events_.end()) { | 363 if (it != aggregated_socket_events_.end()) { |
352 return it->second->last_errors; | 364 return it->second->last_errors; |
353 } else { | 365 } else { |
354 return LastErrors(); | 366 return LastErrors(); |
355 } | 367 } |
356 } | 368 } |
357 | 369 |
358 } // namespace cast_channel | 370 } // namespace cast_channel |
359 } // namespace api | 371 } // namespace core_api |
360 } // namespace extensions | 372 } // namespace extensions |
OLD | NEW |