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

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

Issue 2529603004: [Offline Pages] Expanding event logger to be used by harness. (Closed)
Patch Set: more comments. 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/strings/stringprintf.h" 5 #include "base/strings/stringprintf.h"
6 #include "base/time/time.h" 6 #include "base/time/time.h"
7 #include "components/offline_pages/offline_event_logger.h" 7 #include "components/offline_pages/offline_event_logger.h"
8 8
9 namespace offline_pages { 9 namespace offline_pages {
10 10
11 extern const size_t kMaxLogCount = 50;
12
11 OfflineEventLogger::OfflineEventLogger() 13 OfflineEventLogger::OfflineEventLogger()
12 : activities_(kMaxLogCount), is_logging_(false) {} 14 : activities_(0), is_logging_(false), client_(nullptr) {}
13 15
14 OfflineEventLogger::~OfflineEventLogger() {} 16 OfflineEventLogger::~OfflineEventLogger() {}
15 17
18 void OfflineEventLogger::Clear() {
19 activities_.clear();
20 }
21
16 void OfflineEventLogger::SetIsLogging(bool is_logging) { 22 void OfflineEventLogger::SetIsLogging(bool is_logging) {
17 is_logging_ = is_logging; 23 is_logging_ = is_logging;
18 } 24 }
19 25
20 bool OfflineEventLogger::GetIsLogging() { 26 bool OfflineEventLogger::GetIsLogging() {
21 return is_logging_; 27 return is_logging_;
22 } 28 }
23 29
24 void OfflineEventLogger::Clear() { 30 void OfflineEventLogger::GetLogs(std::vector<std::string>* records) {
25 activities_.clear(); 31 DCHECK(records);
32 records->insert(records->end(), activities_.begin(), activities_.end());
26 } 33 }
27 34
28 void OfflineEventLogger::RecordActivity(const std::string& activity) { 35 void OfflineEventLogger::RecordActivity(const std::string& activity) {
29 if (!is_logging_) { 36 if (!is_logging_ || activity.empty())
30 return; 37 return;
31 }
32 if (activities_.size() == kMaxLogCount)
33 activities_.pop_back();
34 38
35 base::Time::Exploded current_time; 39 base::Time::Exploded current_time;
36 base::Time::Now().LocalExplode(&current_time); 40 base::Time::Now().LocalExplode(&current_time);
37 41
38 std::string date_string = base::StringPrintf( 42 std::string date_string = base::StringPrintf(
39 "%d %02d %02d %02d:%02d:%02d", 43 "%d %02d %02d %02d:%02d:%02d",
40 current_time.year, 44 current_time.year,
41 current_time.month, 45 current_time.month,
42 current_time.day_of_month, 46 current_time.day_of_month,
43 current_time.hour, 47 current_time.hour,
44 current_time.minute, 48 current_time.minute,
45 current_time.second); 49 current_time.second);
46 50
47 activities_.push_front(date_string + ": " + activity); 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);
48 } 59 }
49 60
50 void OfflineEventLogger::GetLogs(std::vector<std::string>* records) { 61 void OfflineEventLogger::SetClient(Client* client) {
51 DCHECK(records); 62 DCHECK(client);
52 for (std::deque<std::string>::iterator it = activities_.begin(); 63 SetIsLogging(true);
53 it != activities_.end(); it++) { 64 client_ = client;
54 if (!it->empty())
55 records->push_back(*it);
56 }
57 } 65 }
58 66
59 } // namespace offline_pages 67 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/offline_event_logger.h ('k') | components/offline_pages/offline_event_logger_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698