Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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 "base/strings/stringprintf.h" | |
| 6 #include "base/time/time.h" | |
| 7 #include "components/offline_pages/offline_event_logger.h" | |
| 8 | |
| 9 namespace offline_pages { | |
| 10 | |
| 11 OfflineEventLogger::OfflineEventLogger() | |
| 12 : activities_(kMaxLogCount), is_logging_(false) {} | |
| 13 | |
| 14 OfflineEventLogger::~OfflineEventLogger() {} | |
| 15 | |
| 16 void OfflineEventLogger::SetIsLogging(bool is_logging) { | |
| 17 is_logging_ = is_logging; | |
| 18 } | |
| 19 | |
| 20 bool OfflineEventLogger::GetIsLogging() { | |
| 21 return is_logging_; | |
| 22 } | |
| 23 | |
| 24 void OfflineEventLogger::Clear() { | |
| 25 activities_.clear(); | |
| 26 } | |
| 27 | |
| 28 void OfflineEventLogger::RecordActivity(const std::string& activity) { | |
|
dewittj
2016/06/24 21:16:41
any chance for OfflineEventLoggerTest?
chili
2016/06/24 21:28:25
I feel like this method (and class) is adequately
| |
| 29 if (!is_logging_) { | |
| 30 return; | |
| 31 } | |
| 32 if (activities_.size() > kMaxLogCount) | |
| 33 activities_.pop_back(); | |
| 34 | |
| 35 base::Time::Exploded current_time; | |
| 36 base::Time::Now().LocalExplode(¤t_time); | |
| 37 | |
| 38 std::string date_string = base::StringPrintf( | |
| 39 "%d %02d %02d %02d:%02d:%02d", | |
| 40 current_time.year, | |
| 41 current_time.month, | |
| 42 current_time.day_of_month, | |
| 43 current_time.hour, | |
| 44 current_time.minute, | |
| 45 current_time.second); | |
| 46 | |
| 47 activities_.push_front(date_string + ": " + activity); | |
| 48 } | |
| 49 | |
| 50 void OfflineEventLogger::GetLogs(std::vector<std::string>* records) { | |
|
dewittj
2016/06/24 21:16:41
nit: add DCHECK(records)
chili
2016/06/24 21:28:25
Done.
| |
| 51 for (std::deque<std::string>::iterator it = activities_.begin(); | |
| 52 it != activities_.end(); it++) { | |
| 53 if (!it->empty()) | |
| 54 records->push_back(*it); | |
| 55 } | |
| 56 } | |
| 57 | |
| 58 } // namespace offline_pages | |
| OLD | NEW |