Chromium Code Reviews| 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 the event type should be reported to the API as the last | |
| 104 // socket event before an error occurred. Some events are not interesting and | |
| 105 // should be ignored. | |
| 106 bool IsInterestingEventType(EventType type) { | |
| 107 switch (type) { | |
| 108 case proto::READY_STATE_CHANGED: | |
| 109 case proto::ERROR_STATE_CHANGED: | |
|
imcheng
2014/09/17 22:34:08
Are other state changes (read/write/connect states
mark a. foltz
2014/10/09 23:51:42
Changed this to just check for errors set as you m
| |
| 110 case proto::NOTIFY_ON_MESSAGE: | |
| 111 case proto::NOTIFY_ON_ERROR: | |
| 112 return false; | |
| 113 default: | |
| 114 return true; | |
| 115 } | |
| 116 } | |
| 117 | |
| 101 } // namespace | 118 } // namespace |
| 102 | 119 |
| 103 Logger::AggregatedSocketEventLog::AggregatedSocketEventLog() { | 120 Logger::AggregatedSocketEventLog::AggregatedSocketEventLog() { |
| 104 } | 121 } |
| 105 | 122 |
| 106 Logger::AggregatedSocketEventLog::~AggregatedSocketEventLog() { | 123 Logger::AggregatedSocketEventLog::~AggregatedSocketEventLog() { |
| 107 } | 124 } |
| 108 | 125 |
| 109 Logger::Logger(scoped_ptr<base::TickClock> clock, | 126 Logger::Logger(scoped_ptr<base::TickClock> clock, |
| 110 base::TimeTicks unix_epoch_time_ticks) | 127 base::TimeTicks unix_epoch_time_ticks) |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 } | 300 } |
| 284 | 301 |
| 285 std::deque<proto::SocketEvent>& socket_events = it->second->socket_events; | 302 std::deque<proto::SocketEvent>& socket_events = it->second->socket_events; |
| 286 if (socket_events.size() >= kMaxEventsPerSocket) { | 303 if (socket_events.size() >= kMaxEventsPerSocket) { |
| 287 socket_events.pop_front(); | 304 socket_events.pop_front(); |
| 288 log_.set_num_evicted_socket_events(log_.num_evicted_socket_events() + 1); | 305 log_.set_num_evicted_socket_events(log_.num_evicted_socket_events() + 1); |
| 289 } | 306 } |
| 290 | 307 |
| 291 socket_events.push_back(socket_event); | 308 socket_events.push_back(socket_event); |
| 292 | 309 |
| 293 it->second->last_errors.event_type = socket_event.type(); | 310 if (IsInterestingEventType(socket_event.type())) { |
| 294 if (socket_event.has_net_return_value()) { | 311 it->second->last_errors.event_type = socket_event.type(); |
| 312 } | |
| 313 if (socket_event.has_net_return_value() && | |
| 314 socket_event.net_return_value() != net::ERR_IO_PENDING) { | |
| 295 it->second->last_errors.net_return_value = socket_event.net_return_value(); | 315 it->second->last_errors.net_return_value = socket_event.net_return_value(); |
| 296 } | 316 } |
| 297 if (socket_event.has_challenge_reply_error_type()) { | 317 if (socket_event.has_challenge_reply_error_type()) { |
| 298 it->second->last_errors.challenge_reply_error_type = | 318 it->second->last_errors.challenge_reply_error_type = |
| 299 socket_event.challenge_reply_error_type(); | 319 socket_event.challenge_reply_error_type(); |
| 300 } | 320 } |
| 301 if (socket_event.has_nss_error_code()) | 321 if (socket_event.has_nss_error_code()) |
| 302 it->second->last_errors.nss_error_code = socket_event.nss_error_code(); | 322 it->second->last_errors.nss_error_code = socket_event.nss_error_code(); |
| 303 | 323 |
| 304 return it->second->aggregated_socket_event; | 324 return it->second->aggregated_socket_event; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 349 AggregatedSocketEventLogMap::const_iterator it = | 369 AggregatedSocketEventLogMap::const_iterator it = |
| 350 aggregated_socket_events_.find(channel_id); | 370 aggregated_socket_events_.find(channel_id); |
| 351 if (it != aggregated_socket_events_.end()) { | 371 if (it != aggregated_socket_events_.end()) { |
| 352 return it->second->last_errors; | 372 return it->second->last_errors; |
| 353 } else { | 373 } else { |
| 354 return LastErrors(); | 374 return LastErrors(); |
| 355 } | 375 } |
| 356 } | 376 } |
| 357 | 377 |
| 358 } // namespace cast_channel | 378 } // namespace cast_channel |
| 359 } // namespace api | 379 } // namespace core_api |
| 360 } // namespace extensions | 380 } // namespace extensions |
| OLD | NEW |