Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / sync_file_system / task_logger.cc
blob8d8c5857f39f0279c480d76e11f719681115f000
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 #include "chrome/browser/sync_file_system/task_logger.h"
7 #include "base/lazy_instance.h"
8 #include "base/stl_util.h"
9 #include "base/synchronization/lock.h"
11 namespace sync_file_system {
13 namespace {
15 const size_t kMaxLogSize = 500;
17 int g_next_log_id = 1;
18 base::LazyInstance<base::Lock>::Leaky g_log_id_lock = LAZY_INSTANCE_INITIALIZER;
20 int GenerateLogID() {
21 base::AutoLock lock(g_log_id_lock.Get());
22 return g_next_log_id++;
25 } // namespace
27 typedef TaskLogger::TaskLog TaskLog;
29 TaskLogger::TaskLog::TaskLog() : log_id(GenerateLogID()) {}
30 TaskLogger::TaskLog::~TaskLog() {}
32 TaskLogger::TaskLogger() {}
34 TaskLogger::~TaskLogger() {
35 ClearLog();
38 void TaskLogger::RecordLog(scoped_ptr<TaskLog> log) {
39 if (!log)
40 return;
42 if (log_history_.size() >= kMaxLogSize) {
43 delete log_history_.front();
44 log_history_.pop_front();
47 log_history_.push_back(log.release());
49 FOR_EACH_OBSERVER(Observer, observers_,
50 OnLogRecorded(*log_history_.back()));
53 void TaskLogger::ClearLog() {
54 STLDeleteContainerPointers(log_history_.begin(), log_history_.end());
55 log_history_.clear();
58 void TaskLogger::AddObserver(Observer* observer) {
59 observers_.AddObserver(observer);
62 void TaskLogger::RemoveObserver(Observer* observer) {
63 observers_.RemoveObserver(observer);
66 const TaskLogger::LogList& TaskLogger::GetLog() const {
67 return log_history_;
70 } // namespace sync_file_system