OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/sync_file_system/task_logger.h" | 5 #include "chrome/browser/sync_file_system/task_logger.h" |
6 | 6 |
7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
8 | 8 |
9 namespace sync_file_system { | 9 namespace sync_file_system { |
10 | 10 |
11 namespace { | 11 namespace { |
12 const size_t kMaxLogSize = 500; | 12 const size_t kMaxLogSize = 500; |
13 } // namespace | 13 } // namespace |
14 | 14 |
15 typedef TaskLogger::TaskLog TaskLog; | 15 typedef TaskLogger::TaskLog TaskLog; |
16 | 16 |
17 TaskLogger::TaskLog::TaskLog() {} | 17 TaskLogger::TaskLog::TaskLog() {} |
18 TaskLogger::TaskLog::~TaskLog() {} | 18 TaskLogger::TaskLog::~TaskLog() {} |
19 | 19 |
20 TaskLogger::TaskLogger() {} | 20 TaskLogger::TaskLogger() {} |
21 | 21 |
22 TaskLogger::~TaskLogger() { | 22 TaskLogger::~TaskLogger() { |
23 ClearLog(); | 23 ClearLog(); |
24 } | 24 } |
25 | 25 |
26 void TaskLogger::RecordLog(scoped_ptr<TaskLog> log) { | 26 void TaskLogger::RecordLog(scoped_ptr<TaskLog> log) { |
| 27 if (!log) |
| 28 return; |
| 29 |
27 if (log_history_.size() >= kMaxLogSize) { | 30 if (log_history_.size() >= kMaxLogSize) { |
28 delete log_history_.front(); | 31 delete log_history_.front(); |
29 log_history_.pop_front(); | 32 log_history_.pop_front(); |
30 } | 33 } |
31 | 34 |
32 log_history_.push_back(log.release()); | 35 log_history_.push_back(log.release()); |
33 | 36 |
34 FOR_EACH_OBSERVER(Observer, observers_, | 37 FOR_EACH_OBSERVER(Observer, observers_, |
35 OnLogRecorded(*log_history_.back())); | 38 OnLogRecorded(*log_history_.back())); |
36 } | 39 } |
37 | 40 |
38 void TaskLogger::ClearLog() { | 41 void TaskLogger::ClearLog() { |
39 STLDeleteContainerPointers(log_history_.begin(), log_history_.end()); | 42 STLDeleteContainerPointers(log_history_.begin(), log_history_.end()); |
40 log_history_.clear(); | 43 log_history_.clear(); |
41 } | 44 } |
42 | 45 |
43 void TaskLogger::AddObserver(Observer* observer) { | 46 void TaskLogger::AddObserver(Observer* observer) { |
44 observers_.AddObserver(observer); | 47 observers_.AddObserver(observer); |
45 } | 48 } |
46 | 49 |
47 void TaskLogger::RemoveObserver(Observer* observer) { | 50 void TaskLogger::RemoveObserver(Observer* observer) { |
48 observers_.RemoveObserver(observer); | 51 observers_.RemoveObserver(observer); |
49 } | 52 } |
50 | 53 |
51 const TaskLogger::LogList& TaskLogger::GetLog() const { | 54 const TaskLogger::LogList& TaskLogger::GetLog() const { |
52 return log_history_; | 55 return log_history_; |
53 } | 56 } |
54 | 57 |
55 } // namespace sync_file_system | 58 } // namespace sync_file_system |
OLD | NEW |