task_logger.cc revision 46d4c2bc3267f3f028f39e7e311b0f89aba2e4fd
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. 4 5#include "chrome/browser/sync_file_system/task_logger.h" 6 7#include "base/stl_util.h" 8 9namespace sync_file_system { 10 11namespace { 12const size_t kMaxLogSize = 500; 13} // namespace 14 15typedef TaskLogger::TaskLog TaskLog; 16 17TaskLogger::TaskLog::TaskLog() {} 18TaskLogger::TaskLog::~TaskLog() {} 19 20TaskLogger::TaskLogger() {} 21 22TaskLogger::~TaskLogger() { 23 ClearLog(); 24} 25 26void TaskLogger::RecordLog(scoped_ptr<TaskLog> log) { 27 if (!log) 28 return; 29 30 if (log_history_.size() >= kMaxLogSize) { 31 delete log_history_.front(); 32 log_history_.pop_front(); 33 } 34 35 log_history_.push_back(log.release()); 36 37 FOR_EACH_OBSERVER(Observer, observers_, 38 OnLogRecorded(*log_history_.back())); 39} 40 41void TaskLogger::ClearLog() { 42 STLDeleteContainerPointers(log_history_.begin(), log_history_.end()); 43 log_history_.clear(); 44} 45 46void TaskLogger::AddObserver(Observer* observer) { 47 observers_.AddObserver(observer); 48} 49 50void TaskLogger::RemoveObserver(Observer* observer) { 51 observers_.RemoveObserver(observer); 52} 53 54const TaskLogger::LogList& TaskLogger::GetLog() const { 55 return log_history_; 56} 57 58} // namespace sync_file_system 59