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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_PROXIMITY_AUTH_LOGGING_LOG_BUFFER_H
6 #define COMPONENTS_PROXIMITY_AUTH_LOGGING_LOG_BUFFER_H
10 #include "base/logging.h"
11 #include "base/macros.h"
12 #include "base/observer_list.h"
13 #include "base/time/time.h"
15 namespace proximity_auth
{
17 // Contains logs specific to the Proximity Auth. This buffer has a maximum size
18 // and will discard entries in FIFO order.
19 // Call LogBuffer::GetInstance() to get the global LogBuffer instance.
22 // Represents a single log entry in the log buffer.
24 const std::string text
;
25 const base::Time time
;
26 const std::string file
;
28 const logging::LogSeverity severity
;
30 LogMessage(const std::string
& text
,
31 const base::Time
& time
,
32 const std::string
& file
,
34 logging::LogSeverity severity
);
39 // Called when a new message is added to the log buffer.
40 virtual void OnLogMessageAdded(const LogMessage
& log_message
) = 0;
42 // Called when all messages in the log buffer are cleared.
43 virtual void OnLogBufferCleared() = 0;
49 // Returns the global instance.
50 static LogBuffer
* GetInstance();
52 // Adds and removes log buffer observers.
53 void AddObserver(Observer
* observer
);
54 void RemoveObserver(Observer
* observer
);
56 // Adds a new log message to the buffer. If the number of log messages exceeds
57 // the maximum, then the earliest added log will be removed.
58 void AddLogMessage(const LogMessage
& log_message
);
60 // Clears all logs in the buffer.
63 // Returns the maximum number of logs that can be stored.
64 size_t MaxBufferSize() const;
66 // Returns the list logs in the buffer, sorted chronologically.
67 const std::list
<LogMessage
>* logs() { return &log_messages_
; }
70 // The messages currently in the buffer.
71 std::list
<LogMessage
> log_messages_
;
74 base::ObserverList
<Observer
> observers_
;
76 DISALLOW_COPY_AND_ASSIGN(LogBuffer
);
79 } // namespace proximity_auth
81 #endif // COMPONENTS_PROXIMITY_AUTH_LOGGING_LOG_BUFFER_H