Chromium Code Reviews| Index: components/offline_pages/offline_event_logger.cc |
| diff --git a/components/offline_pages/offline_event_logger.cc b/components/offline_pages/offline_event_logger.cc |
| index 810c2a667e670621ca37eb0b15eff815388b3744..5e348a8179dde2c13cbed94f0ceea5417cc51fba 100644 |
| --- a/components/offline_pages/offline_event_logger.cc |
| +++ b/components/offline_pages/offline_event_logger.cc |
| @@ -8,11 +8,20 @@ |
| namespace offline_pages { |
| +namespace { |
| +// Maximum number of recorded Logs to keep track of at any moment. |
| +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.
|
| +} |
| + |
| OfflineEventLogger::OfflineEventLogger() |
| : activities_(kMaxLogCount), is_logging_(false) {} |
| OfflineEventLogger::~OfflineEventLogger() {} |
| +void OfflineEventLogger::Clear() { |
| + activities_.clear(); |
| +} |
| + |
| void OfflineEventLogger::SetIsLogging(bool is_logging) { |
| is_logging_ = is_logging; |
| } |
| @@ -21,16 +30,16 @@ bool OfflineEventLogger::GetIsLogging() { |
| return is_logging_; |
| } |
| -void OfflineEventLogger::Clear() { |
| - activities_.clear(); |
| +void OfflineEventLogger::GetLogs(std::vector<std::string>* records) { |
| + DCHECK(records); |
| + 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.
|
| + records->push_back(*it); |
| } |
| void OfflineEventLogger::RecordActivity(const std::string& activity) { |
| - if (!is_logging_) { |
| + if (!is_logging_ || activity.empty()) { |
|
fgorski
2016/12/01 21:42:52
nit: {} not needed.
romax
2016/12/02 01:57:49
Done.
|
| return; |
| } |
| - if (activities_.size() == kMaxLogCount) |
| - activities_.pop_back(); |
| base::Time::Exploded current_time; |
| base::Time::Now().LocalExplode(¤t_time); |
| @@ -44,16 +53,19 @@ void OfflineEventLogger::RecordActivity(const std::string& activity) { |
| current_time.minute, |
| current_time.second); |
| + if (client_) |
| + client_->CustomLog(activity); |
| + |
| + if (activities_.size() == kMaxLogCount) |
| + activities_.pop_back(); |
| + |
| activities_.push_front(date_string + ": " + activity); |
| } |
| -void OfflineEventLogger::GetLogs(std::vector<std::string>* records) { |
| - DCHECK(records); |
| - for (std::deque<std::string>::iterator it = activities_.begin(); |
| - it != activities_.end(); it++) { |
| - if (!it->empty()) |
| - records->push_back(*it); |
| - } |
| +void OfflineEventLogger::SetClient(Client* client) { |
| + DCHECK(client); |
| + SetIsLogging(true); |
| + client_ = client; |
| } |
| } // namespace offline_pages |