OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef EXTENSIONS_BROWSER_API_CAST_CHANNEL_LOGGER_H_ |
| 6 #define EXTENSIONS_BROWSER_API_CAST_CHANNEL_LOGGER_H_ |
| 7 |
| 8 #include <stddef.h> |
| 9 |
| 10 #include <deque> |
| 11 #include <map> |
| 12 #include <memory> |
| 13 #include <string> |
| 14 |
| 15 #include "base/macros.h" |
| 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/threading/thread_checker.h" |
| 18 #include "extensions/common/api/cast_channel/logging.pb.h" |
| 19 |
| 20 |
| 21 namespace extensions { |
| 22 namespace api { |
| 23 namespace cast_channel { |
| 24 |
| 25 struct AuthResult; |
| 26 |
| 27 // Holds the most recent errors encountered by a CastSocket. |
| 28 struct LastErrors { |
| 29 public: |
| 30 LastErrors(); |
| 31 ~LastErrors(); |
| 32 |
| 33 // The most recent event that occurred at the time of the error. |
| 34 proto::EventType event_type; |
| 35 |
| 36 // The most recent ChallengeReplyErrorType logged for the socket. |
| 37 proto::ChallengeReplyErrorType challenge_reply_error_type; |
| 38 |
| 39 // The most recent net_return_value logged for the socket. |
| 40 int net_return_value; |
| 41 }; |
| 42 |
| 43 // Called with events that occur on a Cast Channel and remembers any that |
| 44 // warrant reporting to the caller in LastErrors. |
| 45 class Logger : public base::RefCountedThreadSafe<Logger> { |
| 46 public: |
| 47 Logger(); |
| 48 |
| 49 // For events that involves socket / crypto operations that returns a value. |
| 50 void LogSocketEventWithRv(int channel_id, |
| 51 proto::EventType event_type, |
| 52 int rv); |
| 53 |
| 54 // For AUTH_CHALLENGE_REPLY event. |
| 55 void LogSocketChallengeReplyEvent(int channel_id, |
| 56 const AuthResult& auth_result); |
| 57 |
| 58 // Returns the last errors logged for |channel_id|. |
| 59 LastErrors GetLastErrors(int channel_id) const; |
| 60 |
| 61 // Removes a LastErrors entry for |channel_id| if one exists. |
| 62 void ClearLastErrors(int channel_id); |
| 63 |
| 64 private: |
| 65 friend class base::RefCountedThreadSafe<Logger>; |
| 66 ~Logger(); |
| 67 |
| 68 using LastErrorsMap = std::map<int, LastErrors>; |
| 69 |
| 70 // Returns a SocketEvent proto with common fields (EventType, timestamp) |
| 71 // populated. |
| 72 proto::SocketEvent CreateEvent(proto::EventType event_type); |
| 73 |
| 74 // Uses |event| associated with |channel_id| to update its LastErrors. |
| 75 void LogSocketEvent(int channel_id, const proto::SocketEvent& socket_event); |
| 76 |
| 77 LastErrorsMap last_errors_; |
| 78 |
| 79 base::ThreadChecker thread_checker_; |
| 80 |
| 81 DISALLOW_COPY_AND_ASSIGN(Logger); |
| 82 }; |
| 83 } // namespace cast_channel |
| 84 } // namespace api |
| 85 } // namespace extensions |
| 86 |
| 87 #endif // EXTENSIONS_BROWSER_API_CAST_CHANNEL_LOGGER_H_ |
OLD | NEW |