Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef COMPONENTS_PROXIMITY_AUTH_LOGGING_LOG_BUFFER_H | 5 #ifndef COMPONENTS_PROXIMITY_AUTH_LOGGING_LOG_BUFFER_H |
| 6 #define COMPONENTS_PROXIMITY_AUTH_LOGGING_LOG_BUFFER_H | 6 #define COMPONENTS_PROXIMITY_AUTH_LOGGING_LOG_BUFFER_H |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/observer_list.h" | |
| 12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 13 | 14 |
| 14 namespace proximity_auth { | 15 namespace proximity_auth { |
| 15 | 16 |
| 16 // Contains logs specific to the Proximity Auth. This buffer has a maximum size | 17 // Contains logs specific to the Proximity Auth. This buffer has a maximum size |
| 17 // and will discard entries in FIFO order. | 18 // and will discard entries in FIFO order. |
| 18 // Call LogBuffer::GetInstance() to get the global LogBuffer instance. | 19 // Call LogBuffer::GetInstance() to get the global LogBuffer instance. |
| 19 class LogBuffer { | 20 class LogBuffer { |
| 20 public: | 21 public: |
| 21 // Represents a single log entry in the log buffer. | 22 // Represents a single log entry in the log buffer. |
| 22 struct LogMessage { | 23 struct LogMessage { |
| 23 const std::string text; | 24 const std::string text; |
| 24 const base::Time time; | 25 const base::Time time; |
| 25 const std::string file; | 26 const std::string file; |
| 26 const int line; | 27 const int line; |
| 27 const logging::LogSeverity severity; | 28 const logging::LogSeverity severity; |
| 28 | 29 |
| 29 LogMessage(const std::string& text, | 30 LogMessage(const std::string& text, |
| 30 const base::Time& time, | 31 const base::Time& time, |
| 31 const std::string& file, | 32 const std::string& file, |
| 32 int line, | 33 int line, |
| 33 logging::LogSeverity severity); | 34 logging::LogSeverity severity); |
| 34 }; | 35 }; |
| 35 | 36 |
| 37 class Observer { | |
| 38 public: | |
| 39 virtual void OnLogMessageAdded(const LogMessage& log_message) = 0; | |
| 40 virtual void OnLogBufferCleared() = 0; | |
|
Ilya Sherman
2015/05/13 00:49:57
Please document these methods.
Tim Song
2015/05/13 02:24:37
Done.
| |
| 41 }; | |
| 42 | |
| 36 LogBuffer(); | 43 LogBuffer(); |
| 37 ~LogBuffer(); | 44 ~LogBuffer(); |
| 38 | 45 |
| 39 // Returns the global instance. | 46 // Returns the global instance. |
| 40 static LogBuffer* GetInstance(); | 47 static LogBuffer* GetInstance(); |
| 41 | 48 |
| 49 // Adds and removes log buffer observers. | |
| 50 void AddObserver(Observer* observer); | |
| 51 void RemoveObserver(Observer* observer); | |
| 52 | |
| 42 // Adds a new log message to the buffer. If the number of log messages exceeds | 53 // Adds a new log message to the buffer. If the number of log messages exceeds |
| 43 // the maximum, then the earliest added log will be removed. | 54 // the maximum, then the earliest added log will be removed. |
| 44 void AddLogMessage(const LogMessage& log_message); | 55 void AddLogMessage(const LogMessage& log_message); |
| 45 | 56 |
| 46 // Clears all logs in the buffer. | 57 // Clears all logs in the buffer. |
| 47 void Clear(); | 58 void Clear(); |
| 48 | 59 |
| 49 // Returns the maximum number of logs that can be stored. | 60 // Returns the maximum number of logs that can be stored. |
| 50 size_t MaxBufferSize() const; | 61 size_t MaxBufferSize() const; |
| 51 | 62 |
| 52 // Returns the list logs in the buffer, sorted chronologically. | 63 // Returns the list logs in the buffer, sorted chronologically. |
| 53 const std::list<LogMessage>* logs() { return &log_messages_; } | 64 const std::list<LogMessage>* logs() { return &log_messages_; } |
| 54 | 65 |
| 55 private: | 66 private: |
| 56 // The messages currently in the buffer. | 67 // The messages currently in the buffer. |
| 57 std::list<LogMessage> log_messages_; | 68 std::list<LogMessage> log_messages_; |
| 58 | 69 |
| 70 // List of observers. | |
| 71 ObserverList<Observer> observers_; | |
| 72 | |
| 59 DISALLOW_COPY_AND_ASSIGN(LogBuffer); | 73 DISALLOW_COPY_AND_ASSIGN(LogBuffer); |
| 60 }; | 74 }; |
| 61 | 75 |
| 62 } // namespace proximity_auth | 76 } // namespace proximity_auth |
| 63 | 77 |
| 64 #endif // COMPONENTS_PROXIMITY_AUTH_LOGGING_LOG_BUFFER_H | 78 #endif // COMPONENTS_PROXIMITY_AUTH_LOGGING_LOG_BUFFER_H |
| OLD | NEW |