| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 case AuthResult::ERROR_CANNOT_EXTRACT_PUBLIC_KEY: | 57 case AuthResult::ERROR_CANNOT_EXTRACT_PUBLIC_KEY: |
| 58 return proto::CHALLENGE_REPLY_ERROR_CANNOT_EXTRACT_PUBLIC_KEY; | 58 return proto::CHALLENGE_REPLY_ERROR_CANNOT_EXTRACT_PUBLIC_KEY; |
| 59 case AuthResult::ERROR_SIGNED_BLOBS_MISMATCH: | 59 case AuthResult::ERROR_SIGNED_BLOBS_MISMATCH: |
| 60 return proto::CHALLENGE_REPLY_ERROR_SIGNED_BLOBS_MISMATCH; | 60 return proto::CHALLENGE_REPLY_ERROR_SIGNED_BLOBS_MISMATCH; |
| 61 default: | 61 default: |
| 62 NOTREACHED(); | 62 NOTREACHED(); |
| 63 return proto::CHALLENGE_REPLY_ERROR_NONE; | 63 return proto::CHALLENGE_REPLY_ERROR_NONE; |
| 64 } | 64 } |
| 65 } | 65 } |
| 66 | 66 |
| 67 scoped_ptr<char[]> Compress(const std::string& input, size_t* length) { | 67 std::unique_ptr<char[]> Compress(const std::string& input, size_t* length) { |
| 68 *length = 0; | 68 *length = 0; |
| 69 z_stream stream = {0}; | 69 z_stream stream = {0}; |
| 70 int result = deflateInit2(&stream, | 70 int result = deflateInit2(&stream, |
| 71 Z_DEFAULT_COMPRESSION, | 71 Z_DEFAULT_COMPRESSION, |
| 72 Z_DEFLATED, | 72 Z_DEFLATED, |
| 73 // 16 is added to produce a gzip header + trailer. | 73 // 16 is added to produce a gzip header + trailer. |
| 74 MAX_WBITS + 16, | 74 MAX_WBITS + 16, |
| 75 8, // memLevel = 8 is default. | 75 8, // memLevel = 8 is default. |
| 76 Z_DEFAULT_STRATEGY); | 76 Z_DEFAULT_STRATEGY); |
| 77 DCHECK_EQ(Z_OK, result); | 77 DCHECK_EQ(Z_OK, result); |
| 78 | 78 |
| 79 size_t out_size = deflateBound(&stream, input.size()); | 79 size_t out_size = deflateBound(&stream, input.size()); |
| 80 scoped_ptr<char[]> out(new char[out_size]); | 80 std::unique_ptr<char[]> out(new char[out_size]); |
| 81 | 81 |
| 82 stream.next_in = reinterpret_cast<uint8_t*>(const_cast<char*>(input.data())); | 82 stream.next_in = reinterpret_cast<uint8_t*>(const_cast<char*>(input.data())); |
| 83 stream.avail_in = input.size(); | 83 stream.avail_in = input.size(); |
| 84 stream.next_out = reinterpret_cast<uint8_t*>(out.get()); | 84 stream.next_out = reinterpret_cast<uint8_t*>(out.get()); |
| 85 stream.avail_out = out_size; | 85 stream.avail_out = out_size; |
| 86 | 86 |
| 87 // Do a one-shot compression. This will return Z_STREAM_END only if |output| | 87 // Do a one-shot compression. This will return Z_STREAM_END only if |output| |
| 88 // is large enough to hold all compressed data. | 88 // is large enough to hold all compressed data. |
| 89 result = deflate(&stream, Z_FINISH); | 89 result = deflate(&stream, Z_FINISH); |
| 90 | 90 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 118 } | 118 } |
| 119 | 119 |
| 120 } // namespace | 120 } // namespace |
| 121 | 121 |
| 122 Logger::AggregatedSocketEventLog::AggregatedSocketEventLog() { | 122 Logger::AggregatedSocketEventLog::AggregatedSocketEventLog() { |
| 123 } | 123 } |
| 124 | 124 |
| 125 Logger::AggregatedSocketEventLog::~AggregatedSocketEventLog() { | 125 Logger::AggregatedSocketEventLog::~AggregatedSocketEventLog() { |
| 126 } | 126 } |
| 127 | 127 |
| 128 Logger::Logger(scoped_ptr<base::Clock> clock, base::Time unix_epoch_time) | 128 Logger::Logger(std::unique_ptr<base::Clock> clock, base::Time unix_epoch_time) |
| 129 : clock_(std::move(clock)), unix_epoch_time_(unix_epoch_time) { | 129 : clock_(std::move(clock)), unix_epoch_time_(unix_epoch_time) { |
| 130 DCHECK(clock_); | 130 DCHECK(clock_); |
| 131 | 131 |
| 132 // Logger may not be necessarily be created on the IO thread, but logging | 132 // Logger may not be necessarily be created on the IO thread, but logging |
| 133 // happens exclusively there. | 133 // happens exclusively there. |
| 134 thread_checker_.DetachFromThread(); | 134 thread_checker_.DetachFromThread(); |
| 135 } | 135 } |
| 136 | 136 |
| 137 Logger::~Logger() { | 137 Logger::~Logger() { |
| 138 } | 138 } |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 socket_events.pop_front(); | 304 socket_events.pop_front(); |
| 305 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); |
| 306 } | 306 } |
| 307 socket_events.push_back(socket_event); | 307 socket_events.push_back(socket_event); |
| 308 | 308 |
| 309 MaybeSetLastErrors(socket_event, &(it->second->last_errors)); | 309 MaybeSetLastErrors(socket_event, &(it->second->last_errors)); |
| 310 | 310 |
| 311 return it->second->aggregated_socket_event; | 311 return it->second->aggregated_socket_event; |
| 312 } | 312 } |
| 313 | 313 |
| 314 scoped_ptr<char[]> Logger::GetLogs(size_t* length) const { | 314 std::unique_ptr<char[]> Logger::GetLogs(size_t* length) const { |
| 315 *length = 0; | 315 *length = 0; |
| 316 | 316 |
| 317 Log log; | 317 Log log; |
| 318 // Copy "global" values from |log_|. Don't use |log_| directly since this | 318 // Copy "global" values from |log_|. Don't use |log_| directly since this |
| 319 // function is const. | 319 // function is const. |
| 320 log.CopyFrom(log_); | 320 log.CopyFrom(log_); |
| 321 | 321 |
| 322 for (AggregatedSocketEventLogMap::const_iterator it = | 322 for (AggregatedSocketEventLogMap::const_iterator it = |
| 323 aggregated_socket_events_.begin(); | 323 aggregated_socket_events_.begin(); |
| 324 it != aggregated_socket_events_.end(); | 324 it != aggregated_socket_events_.end(); |
| 325 ++it) { | 325 ++it) { |
| 326 AggregatedSocketEvent* new_aggregated_socket_event = | 326 AggregatedSocketEvent* new_aggregated_socket_event = |
| 327 log.add_aggregated_socket_event(); | 327 log.add_aggregated_socket_event(); |
| 328 new_aggregated_socket_event->CopyFrom(it->second->aggregated_socket_event); | 328 new_aggregated_socket_event->CopyFrom(it->second->aggregated_socket_event); |
| 329 | 329 |
| 330 const std::deque<SocketEvent>& socket_events = it->second->socket_events; | 330 const std::deque<SocketEvent>& socket_events = it->second->socket_events; |
| 331 for (std::deque<SocketEvent>::const_iterator socket_event_it = | 331 for (std::deque<SocketEvent>::const_iterator socket_event_it = |
| 332 socket_events.begin(); | 332 socket_events.begin(); |
| 333 socket_event_it != socket_events.end(); | 333 socket_event_it != socket_events.end(); |
| 334 ++socket_event_it) { | 334 ++socket_event_it) { |
| 335 SocketEvent* socket_event = | 335 SocketEvent* socket_event = |
| 336 new_aggregated_socket_event->add_socket_event(); | 336 new_aggregated_socket_event->add_socket_event(); |
| 337 socket_event->CopyFrom(*socket_event_it); | 337 socket_event->CopyFrom(*socket_event_it); |
| 338 } | 338 } |
| 339 } | 339 } |
| 340 | 340 |
| 341 std::string serialized; | 341 std::string serialized; |
| 342 if (!log.SerializeToString(&serialized)) { | 342 if (!log.SerializeToString(&serialized)) { |
| 343 VLOG(2) << "Failed to serialized proto to string."; | 343 VLOG(2) << "Failed to serialized proto to string."; |
| 344 return scoped_ptr<char[]>(); | 344 return std::unique_ptr<char[]>(); |
| 345 } | 345 } |
| 346 | 346 |
| 347 return Compress(serialized, length); | 347 return Compress(serialized, length); |
| 348 } | 348 } |
| 349 | 349 |
| 350 void Logger::Reset() { | 350 void Logger::Reset() { |
| 351 aggregated_socket_events_.clear(); | 351 aggregated_socket_events_.clear(); |
| 352 log_.Clear(); | 352 log_.Clear(); |
| 353 } | 353 } |
| 354 | 354 |
| 355 LastErrors Logger::GetLastErrors(int channel_id) const { | 355 LastErrors Logger::GetLastErrors(int channel_id) const { |
| 356 AggregatedSocketEventLogMap::const_iterator it = | 356 AggregatedSocketEventLogMap::const_iterator it = |
| 357 aggregated_socket_events_.find(channel_id); | 357 aggregated_socket_events_.find(channel_id); |
| 358 if (it != aggregated_socket_events_.end()) { | 358 if (it != aggregated_socket_events_.end()) { |
| 359 return it->second->last_errors; | 359 return it->second->last_errors; |
| 360 } else { | 360 } else { |
| 361 return LastErrors(); | 361 return LastErrors(); |
| 362 } | 362 } |
| 363 } | 363 } |
| 364 | 364 |
| 365 } // namespace cast_channel | 365 } // namespace cast_channel |
| 366 } // namespace api | 366 } // namespace api |
| 367 } // namespace extensions | 367 } // namespace extensions |
| OLD | NEW |