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

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: 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 namespace {
12 // Maximum number of recorded Logs to keep track of at any moment.
13 static const size_t kMaxLogCount = 50;
fgorski 2016/12/01 21:42:53 you don't need static here.
romax 2016/12/02 01:57:49 Done.
14 }
15
11 OfflineEventLogger::OfflineEventLogger() 16 OfflineEventLogger::OfflineEventLogger()
12 : activities_(kMaxLogCount), is_logging_(false) {} 17 : activities_(kMaxLogCount), is_logging_(false) {}
13 18
14 OfflineEventLogger::~OfflineEventLogger() {} 19 OfflineEventLogger::~OfflineEventLogger() {}
15 20
21 void OfflineEventLogger::Clear() {
22 activities_.clear();
23 }
24
16 void OfflineEventLogger::SetIsLogging(bool is_logging) { 25 void OfflineEventLogger::SetIsLogging(bool is_logging) {
17 is_logging_ = is_logging; 26 is_logging_ = is_logging;
18 } 27 }
19 28
20 bool OfflineEventLogger::GetIsLogging() { 29 bool OfflineEventLogger::GetIsLogging() {
21 return is_logging_; 30 return is_logging_;
22 } 31 }
23 32
24 void OfflineEventLogger::Clear() { 33 void OfflineEventLogger::GetLogs(std::vector<std::string>* records) {
25 activities_.clear(); 34 DCHECK(records);
35 for (auto it = activities_.begin(); it != activities_.end(); ++it)
fgorski 2016/12/01 21:42:53 Will this work? records->insert( records->end
romax 2016/12/02 01:57:49 Done.
36 records->push_back(*it);
26 } 37 }
27 38
28 void OfflineEventLogger::RecordActivity(const std::string& activity) { 39 void OfflineEventLogger::RecordActivity(const std::string& activity) {
29 if (!is_logging_) { 40 if (!is_logging_ || activity.empty()) {
fgorski 2016/12/01 21:42:52 nit: {} not needed.
romax 2016/12/02 01:57:49 Done.
30 return; 41 return;
31 } 42 }
32 if (activities_.size() == kMaxLogCount)
33 activities_.pop_back();
34 43
35 base::Time::Exploded current_time; 44 base::Time::Exploded current_time;
36 base::Time::Now().LocalExplode(&current_time); 45 base::Time::Now().LocalExplode(&current_time);
37 46
38 std::string date_string = base::StringPrintf( 47 std::string date_string = base::StringPrintf(
39 "%d %02d %02d %02d:%02d:%02d", 48 "%d %02d %02d %02d:%02d:%02d",
40 current_time.year, 49 current_time.year,
41 current_time.month, 50 current_time.month,
42 current_time.day_of_month, 51 current_time.day_of_month,
43 current_time.hour, 52 current_time.hour,
44 current_time.minute, 53 current_time.minute,
45 current_time.second); 54 current_time.second);
46 55
56 if (client_)
57 client_->CustomLog(activity);
58
59 if (activities_.size() == kMaxLogCount)
60 activities_.pop_back();
61
47 activities_.push_front(date_string + ": " + activity); 62 activities_.push_front(date_string + ": " + activity);
48 } 63 }
49 64
50 void OfflineEventLogger::GetLogs(std::vector<std::string>* records) { 65 void OfflineEventLogger::SetClient(Client* client) {
51 DCHECK(records); 66 DCHECK(client);
52 for (std::deque<std::string>::iterator it = activities_.begin(); 67 SetIsLogging(true);
53 it != activities_.end(); it++) { 68 client_ = client;
54 if (!it->empty())
55 records->push_back(*it);
56 }
57 } 69 }
58 70
59 } // namespace offline_pages 71 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698