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 #ifndef COMPONENTS_OFFLINE_PAGES_OFFLINE_EVENT_LOGGER_H_ |
| 6 #define COMPONENTS_OFFLINE_PAGES_OFFLINE_EVENT_LOGGER_H_ |
| 7 |
| 8 #include <deque> |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/macros.h" |
| 13 |
| 14 namespace offline_pages { |
| 15 |
| 16 // Maximum number of recorded Logs to keep track of at any moment. |
| 17 static const size_t kMaxLogCount = 50; |
| 18 |
| 19 // Facilitates the logging of events. Subclasses should create methods that |
| 20 // call RecordActivity to write into the log. |SetIsLogging|, |GetLogs|, and |
| 21 // |Clear| are called from the chrome://offline-internals page. |
| 22 // |
| 23 // Logging should be done by calling the corresponding subclass methods when |
| 24 // a loggable event occurs (i.e. when status has changed for a save request |
| 25 // or when an offlined page has been accessed/saved). |
| 26 // |
| 27 // This log only keeps track of the last |kMaxLogCount| events. |
| 28 class OfflineEventLogger { |
| 29 public: |
| 30 OfflineEventLogger(); |
| 31 |
| 32 ~OfflineEventLogger(); |
| 33 |
| 34 // Clears the recorded activities. |
| 35 void Clear(); |
| 36 |
| 37 // Turns logging on/off. |
| 38 void SetIsLogging(bool is_logging); |
| 39 |
| 40 // Returns whether we are currently logging. |
| 41 bool GetIsLogging(); |
| 42 |
| 43 // Dumps the current activity list into |records|. |
| 44 void GetLogs(std::vector<std::string>* records); |
| 45 |
| 46 protected: |
| 47 // Write the activity into the cycling log if we are currently logging. |
| 48 void RecordActivity(const std::string& activity); |
| 49 |
| 50 private: |
| 51 // Recorded offline page activities. |
| 52 std::deque<std::string> activities_; |
| 53 |
| 54 // Whether we are currently recording logs or not. |
| 55 bool is_logging_; |
| 56 }; |
| 57 } // namespace offline_pages |
| 58 |
| 59 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_EVENT_LOGGER_H_ |
OLD | NEW |