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

Side by Side Diff: components/offline_pages/offline_event_logger.cc

Issue 2489443002: Move all components/offline_pages/ files into component/offline_pages/core (Closed)
Patch Set: more rebase Created 4 years 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 "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) {
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(&current_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) {
51 DCHECK(records);
52 for (std::deque<std::string>::iterator it = activities_.begin();
53 it != activities_.end(); it++) {
54 if (!it->empty())
55 records->push_back(*it);
56 }
57 }
58
59 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698