Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(574)

Unified Diff: components/offline_pages/offline_event_logger.cc

Issue 2089413002: [Offline Pages] Create a event/activity logger (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add ability to retrieve whether we are currently logging Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/offline_pages/offline_event_logger.h ('k') | components/offline_pages/offline_page_model.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..29635c67cb2e8c04f08f1fa629b613961e04faa3
--- /dev/null
+++ b/components/offline_pages/offline_event_logger.cc
@@ -0,0 +1,58 @@
+// 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 "base/strings/stringprintf.h"
+#include "base/time/time.h"
+#include "components/offline_pages/offline_event_logger.h"
+
+namespace offline_pages {
+
+OfflineEventLogger::OfflineEventLogger()
+ : activities_(kMaxLogCount), is_logging_(false) {}
+
+OfflineEventLogger::~OfflineEventLogger() {}
+
+void OfflineEventLogger::SetIsLogging(bool is_logging) {
+ is_logging_ = is_logging;
+}
+
+bool OfflineEventLogger::GetIsLogging() {
+ return is_logging_;
+}
+
+void OfflineEventLogger::Clear() {
+ activities_.clear();
+}
+
+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
+ if (!is_logging_) {
+ return;
+ }
+ if (activities_.size() > kMaxLogCount)
+ activities_.pop_back();
+
+ base::Time::Exploded current_time;
+ base::Time::Now().LocalExplode(&current_time);
+
+ std::string date_string = base::StringPrintf(
+ "%d %02d %02d %02d:%02d:%02d",
+ current_time.year,
+ current_time.month,
+ current_time.day_of_month,
+ current_time.hour,
+ current_time.minute,
+ current_time.second);
+
+ activities_.push_front(date_string + ": " + activity);
+}
+
+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.
+ for (std::deque<std::string>::iterator it = activities_.begin();
+ it != activities_.end(); it++) {
+ if (!it->empty())
+ records->push_back(*it);
+ }
+}
+
+} // namespace offline_pages
« no previous file with comments | « components/offline_pages/offline_event_logger.h ('k') | components/offline_pages/offline_page_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698