Index: components/offline_pages/offline_event_logger.cc |
diff --git a/components/offline_pages/offline_event_logger.cc b/components/offline_pages/offline_event_logger.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..5fe5781126434d53b10d752f25057201fce7be2e |
--- /dev/null |
+++ b/components/offline_pages/offline_event_logger.cc |
@@ -0,0 +1,51 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include <ctime> |
+ |
+#include "components/offline_pages/offline_event_logger.h" |
+ |
+namespace offline_pages { |
+ |
+namespace { |
+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.
|
+} |
+ |
+OfflineEventLogger::OfflineEventLogger() |
+ : activities_(MAX_LOGGED_ACTIVITY_COUNT), is_logging_(false) {} |
+ |
+OfflineEventLogger::~OfflineEventLogger() {} |
+ |
+void OfflineEventLogger::SetIsLogging(bool is_logging) { |
+ is_logging_ = is_logging; |
+} |
+ |
+void OfflineEventLogger::Clear() { |
+ activities_.clear(); |
+} |
+ |
+void OfflineEventLogger::RecordActivity(const std::string& activity) { |
+ if (!is_logging_) { |
+ return; |
+ } |
+ if (activities_.size() > MAX_LOGGED_ACTIVITY_COUNT) |
+ activities_.pop_back(); |
+ |
+ 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
|
+ char buffer[20]; |
+ |
+ strftime(buffer, 20, "%Y %m %d %H:%M:%S", std::localtime(¤t_time)); |
+ |
+ activities_.push_front(std::string(buffer) + (": " + activity)); |
+} |
+ |
+void OfflineEventLogger::GetLogs(std::vector<std::string>& records) { |
+ for (std::deque<std::string>::iterator it = activities_.begin(); |
+ it != activities_.end(); it++) { |
+ if (!it->empty()) |
+ records.push_back(*it); |
+ } |
+} |
+ |
+} // namespace offline_pages |