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

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: 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 extern const size_t kMaxLogCount = 50;
12
13 OfflineEventLogger::OfflineEventLogger()
14 : activities_(0), is_logging_(false), client_(nullptr) {}
15
16 OfflineEventLogger::~OfflineEventLogger() {}
17
18 void OfflineEventLogger::Clear() {
19 activities_.clear();
20 }
21
22 void OfflineEventLogger::SetIsLogging(bool is_logging) {
23 is_logging_ = is_logging;
24 }
25
26 bool OfflineEventLogger::GetIsLogging() {
27 return is_logging_;
28 }
29
30 void OfflineEventLogger::GetLogs(std::vector<std::string>* records) {
31 DCHECK(records);
32 records->insert(records->end(), activities_.begin(), activities_.end());
33 }
34
35 void OfflineEventLogger::RecordActivity(const std::string& activity) {
36 if (!is_logging_ || activity.empty())
37 return;
38
39 base::Time::Exploded current_time;
40 base::Time::Now().LocalExplode(&current_time);
41
42 std::string date_string = base::StringPrintf(
43 "%d %02d %02d %02d:%02d:%02d",
44 current_time.year,
45 current_time.month,
46 current_time.day_of_month,
47 current_time.hour,
48 current_time.minute,
49 current_time.second);
50
51 std::string log_message = date_string + ": " + activity;
52 if (client_)
53 client_->CustomLog(log_message);
54
55 if (activities_.size() == kMaxLogCount)
56 activities_.pop_back();
57
58 activities_.push_front(log_message);
59 }
60
61 void OfflineEventLogger::SetClient(Client* client) {
62 DCHECK(client);
63 SetIsLogging(true);
64 client_ = client;
65 }
66
67 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/offline_event_logger.h ('k') | components/offline_pages/offline_page_archiver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698