Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / drive / event_logger.cc
blob904435d76eb2cd83ed5e7fa205a24c9048a0c4a1
1 // Copyright (c) 2012 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 #include "chrome/browser/drive/event_logger.h"
7 #include "base/logging.h"
8 #include "base/strings/stringprintf.h"
10 namespace drive {
12 EventLogger::Event::Event(
13 int id, logging::LogSeverity severity, const std::string& what)
14 : id(id),
15 severity(severity),
16 when(base::Time::Now()),
17 what(what) {
20 EventLogger::EventLogger()
21 : history_size_(kDefaultHistorySize),
22 next_event_id_(0) {
25 EventLogger::~EventLogger() {
28 void EventLogger::Log(logging::LogSeverity severity, const std::string& what) {
29 base::AutoLock auto_lock(lock_);
30 history_.push_back(Event(next_event_id_, severity, what));
31 ++next_event_id_;
32 if (history_.size() > history_size_)
33 history_.pop_front();
36 void EventLogger::SetHistorySize(size_t history_size) {
37 base::AutoLock auto_lock(lock_);
38 history_.clear();
39 history_size_ = history_size;
42 std::vector<EventLogger::Event> EventLogger::GetHistory() {
43 base::AutoLock auto_lock(lock_);
44 std::vector<Event> output;
45 output.assign(history_.begin(), history_.end());
46 return output;
50 } // namespace drive