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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/stl_util.h" | |
11 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
12 | 11 |
13 namespace sync_file_system { | 12 namespace sync_file_system { |
14 | 13 |
15 namespace { | 14 namespace { |
16 | 15 |
17 const size_t kMaxLogSize = 500; | 16 const size_t kMaxLogSize = 500; |
18 | 17 |
19 int g_next_log_id = 1; | 18 int g_next_log_id = 1; |
20 base::LazyInstance<base::Lock>::Leaky g_log_id_lock = LAZY_INSTANCE_INITIALIZER; | 19 base::LazyInstance<base::Lock>::Leaky g_log_id_lock = LAZY_INSTANCE_INITIALIZER; |
(...skipping 14 matching lines...) Expand all Loading... |
35 | 34 |
36 TaskLogger::~TaskLogger() { | 35 TaskLogger::~TaskLogger() { |
37 ClearLog(); | 36 ClearLog(); |
38 } | 37 } |
39 | 38 |
40 void TaskLogger::RecordLog(std::unique_ptr<TaskLog> log) { | 39 void TaskLogger::RecordLog(std::unique_ptr<TaskLog> log) { |
41 if (!log) | 40 if (!log) |
42 return; | 41 return; |
43 | 42 |
44 if (log_history_.size() >= kMaxLogSize) { | 43 if (log_history_.size() >= kMaxLogSize) { |
45 delete log_history_.front(); | |
46 log_history_.pop_front(); | 44 log_history_.pop_front(); |
47 } | 45 } |
48 | 46 |
49 log_history_.push_back(log.release()); | 47 log_history_.push_back(std::move(log)); |
50 | 48 |
51 FOR_EACH_OBSERVER(Observer, observers_, | 49 FOR_EACH_OBSERVER(Observer, observers_, |
52 OnLogRecorded(*log_history_.back())); | 50 OnLogRecorded(*log_history_.back())); |
53 } | 51 } |
54 | 52 |
55 void TaskLogger::ClearLog() { | 53 void TaskLogger::ClearLog() { |
56 base::STLDeleteContainerPointers(log_history_.begin(), log_history_.end()); | |
57 log_history_.clear(); | 54 log_history_.clear(); |
58 } | 55 } |
59 | 56 |
60 void TaskLogger::AddObserver(Observer* observer) { | 57 void TaskLogger::AddObserver(Observer* observer) { |
61 observers_.AddObserver(observer); | 58 observers_.AddObserver(observer); |
62 } | 59 } |
63 | 60 |
64 void TaskLogger::RemoveObserver(Observer* observer) { | 61 void TaskLogger::RemoveObserver(Observer* observer) { |
65 observers_.RemoveObserver(observer); | 62 observers_.RemoveObserver(observer); |
66 } | 63 } |
67 | 64 |
68 const TaskLogger::LogList& TaskLogger::GetLog() const { | 65 const TaskLogger::LogList& TaskLogger::GetLog() const { |
69 return log_history_; | 66 return log_history_; |
70 } | 67 } |
71 | 68 |
72 } // namespace sync_file_system | 69 } // namespace sync_file_system |
OLD | NEW |