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