OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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_DEVICE_EVENT_LOG_DEVICE_EVENT_LOG_IMPL_H_ | 5 #ifndef COMPONENTS_DEVICE_EVENT_LOG_DEVICE_EVENT_LOG_IMPL_H_ |
6 #define COMPONENTS_DEVICE_EVENT_LOG_DEVICE_EVENT_LOG_IMPL_H_ | 6 #define COMPONENTS_DEVICE_EVENT_LOG_DEVICE_EVENT_LOG_IMPL_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <string> | 9 #include <string> |
10 | 10 |
| 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/single_thread_task_runner.h" |
11 #include "base/time/time.h" | 14 #include "base/time/time.h" |
12 #include "components/device_event_log/device_event_log.h" | 15 #include "components/device_event_log/device_event_log.h" |
13 | 16 |
14 namespace device_event_log { | 17 namespace device_event_log { |
15 | 18 |
16 class DeviceEventLogImpl { | 19 // Implementation class for DEVICE_LOG. |
| 20 class DEVICE_EVENT_LOG_EXPORT DeviceEventLogImpl { |
17 public: | 21 public: |
18 struct LogEntry { | 22 struct LogEntry { |
19 LogEntry(const char* filedesc, | 23 LogEntry(const char* filedesc, |
20 int file_line, | 24 int file_line, |
21 LogType log_type, | 25 LogType log_type, |
22 LogLevel log_level, | 26 LogLevel log_level, |
23 const std::string& event); | 27 const std::string& event); |
24 | 28 |
25 std::string file; | 29 std::string file; |
26 int file_line; | 30 int file_line; |
27 LogType log_type; | 31 LogType log_type; |
28 LogLevel log_level; | 32 LogLevel log_level; |
29 std::string event; | 33 std::string event; |
30 base::Time time; | 34 base::Time time; |
31 int count; | 35 int count; |
32 }; | 36 }; |
33 | 37 |
34 explicit DeviceEventLogImpl(size_t max_entries); | 38 explicit DeviceEventLogImpl( |
| 39 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 40 size_t max_entries); |
35 ~DeviceEventLogImpl(); | 41 ~DeviceEventLogImpl(); |
36 | 42 |
37 // Implements device_event_log::AddEntry. | 43 // Implements device_event_log::AddEntry. |
38 void AddEntry(const char* file, | 44 void AddEntry(const char* file, |
39 int file_line, | 45 int file_line, |
40 LogType type, | 46 LogType type, |
41 LogLevel level, | 47 LogLevel level, |
42 const std::string& event); | 48 const std::string& event); |
43 | 49 |
44 // Implements device_event_log::GetAsString. | 50 // Implements device_event_log::GetAsString. |
(...skipping 10 matching lines...) Expand all Loading... |
55 LogType type, | 61 LogType type, |
56 LogLevel log_level, | 62 LogLevel log_level, |
57 const std::string& event); | 63 const std::string& event); |
58 | 64 |
59 private: | 65 private: |
60 friend class DeviceEventLogTest; | 66 friend class DeviceEventLogTest; |
61 | 67 |
62 typedef std::list<LogEntry> LogEntryList; | 68 typedef std::list<LogEntry> LogEntryList; |
63 | 69 |
64 void AddLogEntry(const LogEntry& entry); | 70 void AddLogEntry(const LogEntry& entry); |
| 71 void RemoveEntry(); |
65 | 72 |
66 // For testing | 73 // For testing |
67 size_t max_entries() const { return max_entries_; } | 74 size_t max_entries() const { return max_entries_; } |
68 void set_max_entries_for_test(size_t entries) { max_entries_ = entries; } | 75 void set_max_entries_for_test(size_t entries) { max_entries_ = entries; } |
69 | 76 |
| 77 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
70 size_t max_entries_; | 78 size_t max_entries_; |
71 LogEntryList entries_; | 79 LogEntryList entries_; |
| 80 base::WeakPtrFactory<DeviceEventLogImpl> weak_ptr_factory_; |
72 | 81 |
73 DISALLOW_COPY_AND_ASSIGN(DeviceEventLogImpl); | 82 DISALLOW_COPY_AND_ASSIGN(DeviceEventLogImpl); |
74 }; | 83 }; |
75 | 84 |
76 } // namespace device_event_log | 85 } // namespace device_event_log |
77 | 86 |
78 #endif // COMPONENTS_DEVICE_EVENT_LOG_DEVICE_EVENT_LOG_IMPL_H_ | 87 #endif // COMPONENTS_DEVICE_EVENT_LOG_DEVICE_EVENT_LOG_IMPL_H_ |
OLD | NEW |