Update V8 to version 4.6.62.
[chromium-blink-merge.git] / components / device_event_log / device_event_log_impl.h
blob6c3dffeb726f8ce076424e3f5cd065a467c294d1
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.
5 #ifndef COMPONENTS_DEVICE_EVENT_LOG_DEVICE_EVENT_LOG_IMPL_H_
6 #define COMPONENTS_DEVICE_EVENT_LOG_DEVICE_EVENT_LOG_IMPL_H_
8 #include <list>
9 #include <string>
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/single_thread_task_runner.h"
14 #include "base/time/time.h"
15 #include "components/device_event_log/device_event_log.h"
17 namespace device_event_log {
19 // Implementation class for DEVICE_LOG.
20 class DEVICE_EVENT_LOG_EXPORT DeviceEventLogImpl {
21 public:
22 struct LogEntry {
23 LogEntry(const char* filedesc,
24 int file_line,
25 LogType log_type,
26 LogLevel log_level,
27 const std::string& event);
29 std::string file;
30 int file_line;
31 LogType log_type;
32 LogLevel log_level;
33 std::string event;
34 base::Time time;
35 int count;
38 explicit DeviceEventLogImpl(
39 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
40 size_t max_entries);
41 ~DeviceEventLogImpl();
43 // Implements device_event_log::AddEntry.
44 void AddEntry(const char* file,
45 int file_line,
46 LogType type,
47 LogLevel level,
48 const std::string& event);
50 // Implements device_event_log::GetAsString.
51 std::string GetAsString(StringOrder order,
52 const std::string& format,
53 const std::string& types,
54 LogLevel max_level,
55 size_t max_events);
57 // Called from device_event_log::AddEntry if the global instance has not been
58 // created (or has already been destroyed). Logs to LOG(ERROR) or VLOG(1).
59 static void SendToVLogOrErrorLog(const char* file,
60 int file_line,
61 LogType type,
62 LogLevel log_level,
63 const std::string& event);
65 private:
66 friend class DeviceEventLogTest;
68 typedef std::list<LogEntry> LogEntryList;
70 void AddLogEntry(const LogEntry& entry);
71 void RemoveEntry();
73 // For testing
74 size_t max_entries() const { return max_entries_; }
75 void set_max_entries_for_test(size_t entries) { max_entries_ = entries; }
77 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
78 size_t max_entries_;
79 LogEntryList entries_;
80 base::WeakPtrFactory<DeviceEventLogImpl> weak_ptr_factory_;
82 DISALLOW_COPY_AND_ASSIGN(DeviceEventLogImpl);
85 } // namespace device_event_log
87 #endif // COMPONENTS_DEVICE_EVENT_LOG_DEVICE_EVENT_LOG_IMPL_H_