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

Side by Side 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: Address initial comments 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 unified diff | Download patch
OLDNEW
(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 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 void OfflineEventLogger::Clear() {
21 activities_.clear();
22 }
23
24 void OfflineEventLogger::RecordActivity(const std::string& activity) {
25 if (!is_logging_) {
26 return;
27 }
28 if (activities_.size() > kMaxLogCount)
29 activities_.pop_back();
30
31 std::time_t current_time = std::time(nullptr);
32 char buffer[20];
33
34 strftime(buffer, 20, "%Y %m %d %H:%M:%S", std::localtime(&current_time));
35
36 activities_.push_front(std::string(buffer) + (": " + activity));
37 }
38
39 void OfflineEventLogger::GetLogs(std::vector<std::string>& records) {
40 for (std::deque<std::string>::iterator it = activities_.begin();
41 it != activities_.end(); it++) {
42 if (!it->empty())
43 records.push_back(*it);
44 }
45 }
46
47 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698