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

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 OfflineEventLogger::OfflineEventLogger() 11 OfflineEventLogger::OfflineEventLogger()
12 : activities_(kMaxLogCount), is_logging_(false) {} 12 : activities_(kMaxLogCount), is_logging_(false) {}
13 13
14 OfflineEventLogger::~OfflineEventLogger() {} 14 OfflineEventLogger::~OfflineEventLogger() {}
15 15
16 void OfflineEventLogger::Clear() {
fgorski 2016/11/30 17:30:47 Please explain why you are moving the code so much
romax 2016/12/01 01:47:53 I thought the order of the implementation should b
17 activities_.clear();
18 }
19
16 void OfflineEventLogger::SetIsLogging(bool is_logging) { 20 void OfflineEventLogger::SetIsLogging(bool is_logging) {
17 is_logging_ = is_logging; 21 is_logging_ = is_logging;
18 } 22 }
19 23
20 bool OfflineEventLogger::GetIsLogging() { 24 bool OfflineEventLogger::GetIsLogging() {
21 return is_logging_; 25 return is_logging_;
22 } 26 }
23 27
24 void OfflineEventLogger::Clear() { 28 void OfflineEventLogger::GetLogs(std::vector<std::string>* records) {
fgorski 2016/11/30 17:30:47 I see you are moving this code, a few suggestions
romax 2016/12/01 01:47:53 Acknowledged.
25 activities_.clear(); 29 DCHECK(records);
30 for (std::deque<std::string>::iterator it = activities_.begin();
fgorski 2016/11/30 17:30:47 you can probably use some form of auto here.
romax 2016/12/01 01:47:53 Done.
31 it != activities_.end(); it++) {
fgorski 2016/11/30 17:30:47 ++it
romax 2016/12/01 01:47:53 Done.
32 if (!it->empty())
fgorski 2016/11/30 17:30:47 This guard would be more reasonable in record acti
romax 2016/12/01 01:47:52 Done.
33 records->push_back(*it);
34 }
26 } 35 }
27 36
28 void OfflineEventLogger::RecordActivity(const std::string& activity) { 37 void OfflineEventLogger::RecordActivity(const std::string& activity) {
29 if (!is_logging_) { 38 if (!is_logging_) {
30 return; 39 return;
31 } 40 }
32 if (activities_.size() == kMaxLogCount)
33 activities_.pop_back();
34 41
35 base::Time::Exploded current_time; 42 base::Time::Exploded current_time;
36 base::Time::Now().LocalExplode(&current_time); 43 base::Time::Now().LocalExplode(&current_time);
37 44
38 std::string date_string = base::StringPrintf( 45 std::string date_string = base::StringPrintf(
39 "%d %02d %02d %02d:%02d:%02d", 46 "%d %02d %02d %02d:%02d:%02d",
40 current_time.year, 47 current_time.year,
41 current_time.month, 48 current_time.month,
42 current_time.day_of_month, 49 current_time.day_of_month,
43 current_time.hour, 50 current_time.hour,
44 current_time.minute, 51 current_time.minute,
45 current_time.second); 52 current_time.second);
46 53
54 if (client_)
55 client_->CustomLog(activity);
56
57 if (activities_.size() == kMaxLogCount)
58 activities_.pop_back();
59
47 activities_.push_front(date_string + ": " + activity); 60 activities_.push_front(date_string + ": " + activity);
48 } 61 }
49 62
50 void OfflineEventLogger::GetLogs(std::vector<std::string>* records) { 63 void OfflineEventLogger::SetClient(Client* client) {
51 DCHECK(records); 64 SetIsLogging(true);
fgorski 2016/11/30 17:30:47 what if client == nullptr?
romax 2016/12/01 01:47:53 then client_ would be set to nullptr. and nothing
52 for (std::deque<std::string>::iterator it = activities_.begin(); 65 client_ = client;
53 it != activities_.end(); it++) {
54 if (!it->empty())
55 records->push_back(*it);
56 }
57 } 66 }
58 67
59 } // namespace offline_pages 68 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698