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
{
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
;
21 base::AutoLock
lock(g_log_id_lock
.Get());
22 return g_next_log_id
++;
27 typedef TaskLogger::TaskLog TaskLog
;
29 TaskLogger::TaskLog::TaskLog() : log_id(GenerateLogID()) {}
30 TaskLogger::TaskLog::~TaskLog() {}
32 TaskLogger::TaskLogger() {}
34 TaskLogger::~TaskLogger() {
38 void TaskLogger::RecordLog(scoped_ptr
<TaskLog
> log
) {
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());
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 {
70 } // namespace sync_file_system