| OLD | NEW |
| (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(¤t_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 | |
| OLD | NEW |