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/lazy_instance.h" |
7 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "base/synchronization/lock.h" |
8 | 10 |
9 namespace sync_file_system { | 11 namespace sync_file_system { |
10 | 12 |
11 namespace { | 13 namespace { |
| 14 |
12 const size_t kMaxLogSize = 500; | 15 const size_t kMaxLogSize = 500; |
| 16 |
| 17 int g_next_log_id = 1; |
| 18 base::LazyInstance<base::Lock>::Leaky g_log_id_lock = LAZY_INSTANCE_INITIALIZER; |
| 19 |
| 20 int GenerateLogID() { |
| 21 base::AutoLock lock(g_log_id_lock.Get()); |
| 22 return g_next_log_id++; |
| 23 } |
| 24 |
13 } // namespace | 25 } // namespace |
14 | 26 |
15 typedef TaskLogger::TaskLog TaskLog; | 27 typedef TaskLogger::TaskLog TaskLog; |
16 | 28 |
17 TaskLogger::TaskLog::TaskLog() {} | 29 TaskLogger::TaskLog::TaskLog() : log_id(GenerateLogID()) {} |
18 TaskLogger::TaskLog::~TaskLog() {} | 30 TaskLogger::TaskLog::~TaskLog() {} |
19 | 31 |
20 TaskLogger::TaskLogger() {} | 32 TaskLogger::TaskLogger() {} |
21 | 33 |
22 TaskLogger::~TaskLogger() { | 34 TaskLogger::~TaskLogger() { |
23 ClearLog(); | 35 ClearLog(); |
24 } | 36 } |
25 | 37 |
26 void TaskLogger::RecordLog(scoped_ptr<TaskLog> log) { | 38 void TaskLogger::RecordLog(scoped_ptr<TaskLog> log) { |
27 if (!log) | 39 if (!log) |
(...skipping 21 matching lines...) Expand all Loading... |
49 | 61 |
50 void TaskLogger::RemoveObserver(Observer* observer) { | 62 void TaskLogger::RemoveObserver(Observer* observer) { |
51 observers_.RemoveObserver(observer); | 63 observers_.RemoveObserver(observer); |
52 } | 64 } |
53 | 65 |
54 const TaskLogger::LogList& TaskLogger::GetLog() const { | 66 const TaskLogger::LogList& TaskLogger::GetLog() const { |
55 return log_history_; | 67 return log_history_; |
56 } | 68 } |
57 | 69 |
58 } // namespace sync_file_system | 70 } // namespace sync_file_system |
OLD | NEW |