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 <ctime> | |
| 6 | |
| 7 #include "components/offline_pages/offline_event_logger.h" | |
| 8 | |
| 9 namespace offline_pages { | |
| 10 | |
| 11 namespace { | |
| 12 const size_t MAX_LOGGED_ACTIVITY_COUNT = 20; | |
|
Pete Williamson
2016/06/24 00:38:32
Reading your code for the first time, I'm not sure
chili
2016/06/24 02:45:51
Added comment. Let me know if it's not sufficient
Pete Williamson
2016/06/24 16:52:58
OK, thanks for the comment, 20 feels too small to
chili
2016/06/24 20:30:10
Done.
| |
| 13 } | |
| 14 | |
| 15 OfflineEventLogger::OfflineEventLogger() | |
| 16 : activities_(MAX_LOGGED_ACTIVITY_COUNT), is_logging_(false) {} | |
| 17 | |
| 18 OfflineEventLogger::~OfflineEventLogger() {} | |
| 19 | |
| 20 void OfflineEventLogger::SetIsLogging(bool is_logging) { | |
| 21 is_logging_ = is_logging; | |
| 22 } | |
| 23 | |
| 24 void OfflineEventLogger::Clear() { | |
| 25 activities_.clear(); | |
| 26 } | |
| 27 | |
| 28 void OfflineEventLogger::RecordActivity(const std::string& activity) { | |
| 29 if (!is_logging_) { | |
| 30 return; | |
| 31 } | |
| 32 if (activities_.size() > MAX_LOGGED_ACTIVITY_COUNT) | |
| 33 activities_.pop_back(); | |
| 34 | |
| 35 std::time_t current_time = std::time(nullptr); | |
|
dewittj
2016/06/23 22:19:02
This is to low-leve. I think in Chrome we normall
chili
2016/06/24 02:45:51
I looked at time_formatting. Unfortunately, I wan
fgorski
2016/06/24 18:17:33
I think the point is to get away from time_t per c
chili
2016/06/24 20:30:10
hmm... how does this look now?
A combination of u
| |
| 36 char buffer[20]; | |
| 37 | |
| 38 strftime(buffer, 20, "%Y %m %d %H:%M:%S", std::localtime(¤t_time)); | |
| 39 | |
| 40 activities_.push_front(std::string(buffer) + (": " + activity)); | |
| 41 } | |
| 42 | |
| 43 void OfflineEventLogger::GetLogs(std::vector<std::string>& records) { | |
| 44 for (std::deque<std::string>::iterator it = activities_.begin(); | |
| 45 it != activities_.end(); it++) { | |
| 46 if (!it->empty()) | |
| 47 records.push_back(*it); | |
| 48 } | |
| 49 } | |
| 50 | |
| 51 } // namespace offline_pages | |
| OLD | NEW |