Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(294)

Side by Side Diff: components/proximity_auth/logging/log_buffer.h

Issue 1135293002: Hook up PA_LOG() logs to chrome://proximity-auth WebUI. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: stop using release() Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | components/proximity_auth/logging/log_buffer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Called when a new message is added to the log buffer.
40 virtual void OnLogMessageAdded(const LogMessage& log_message) = 0;
41
42 // Called when all messages in the log buffer are cleared.
43 virtual void OnLogBufferCleared() = 0;
44 };
45
36 LogBuffer(); 46 LogBuffer();
37 ~LogBuffer(); 47 ~LogBuffer();
38 48
39 // Returns the global instance. 49 // Returns the global instance.
40 static LogBuffer* GetInstance(); 50 static LogBuffer* GetInstance();
41 51
52 // Adds and removes log buffer observers.
53 void AddObserver(Observer* observer);
54 void RemoveObserver(Observer* observer);
55
42 // Adds a new log message to the buffer. If the number of log messages exceeds 56 // 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. 57 // the maximum, then the earliest added log will be removed.
44 void AddLogMessage(const LogMessage& log_message); 58 void AddLogMessage(const LogMessage& log_message);
45 59
46 // Clears all logs in the buffer. 60 // Clears all logs in the buffer.
47 void Clear(); 61 void Clear();
48 62
49 // Returns the maximum number of logs that can be stored. 63 // Returns the maximum number of logs that can be stored.
50 size_t MaxBufferSize() const; 64 size_t MaxBufferSize() const;
51 65
52 // Returns the list logs in the buffer, sorted chronologically. 66 // Returns the list logs in the buffer, sorted chronologically.
53 const std::list<LogMessage>* logs() { return &log_messages_; } 67 const std::list<LogMessage>* logs() { return &log_messages_; }
54 68
55 private: 69 private:
56 // The messages currently in the buffer. 70 // The messages currently in the buffer.
57 std::list<LogMessage> log_messages_; 71 std::list<LogMessage> log_messages_;
58 72
73 // List of observers.
74 ObserverList<Observer> observers_;
75
59 DISALLOW_COPY_AND_ASSIGN(LogBuffer); 76 DISALLOW_COPY_AND_ASSIGN(LogBuffer);
60 }; 77 };
61 78
62 } // namespace proximity_auth 79 } // namespace proximity_auth
63 80
64 #endif // COMPONENTS_PROXIMITY_AUTH_LOGGING_LOG_BUFFER_H 81 #endif // COMPONENTS_PROXIMITY_AUTH_LOGGING_LOG_BUFFER_H
OLDNEW
« no previous file with comments | « no previous file | components/proximity_auth/logging/log_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698