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_
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
{
23 LogEntry(const char* filedesc
,
27 const std::string
& event
);
38 explicit DeviceEventLogImpl(
39 scoped_refptr
<base::SingleThreadTaskRunner
> task_runner
,
41 ~DeviceEventLogImpl();
43 // Implements device_event_log::AddEntry.
44 void AddEntry(const char* file
,
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
,
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
,
63 const std::string
& event
);
66 friend class DeviceEventLogTest
;
68 typedef std::list
<LogEntry
> LogEntryList
;
70 void AddLogEntry(const LogEntry
& entry
);
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_
;
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_