| 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. Defined in | |
| 17 // offline_event_logger.cc. | |
| 18 extern const size_t kMaxLogCount; | |
| 19 | |
| 20 // Facilitates the logging of events. Subclasses should create methods that | |
| 21 // call RecordActivity to write into the log. |SetIsLogging|, |GetLogs|, and | |
| 22 // |Clear| are called from the chrome://offline-internals page. | |
| 23 // | |
| 24 // Logging should be done by calling the corresponding subclass methods when | |
| 25 // a loggable event occurs (i.e. when status has changed for a save request | |
| 26 // or when an offlined page has been accessed/saved). | |
| 27 // | |
| 28 // This log only keeps track of the last |kMaxLogCount| events. | |
| 29 class OfflineEventLogger { | |
| 30 public: | |
| 31 // This client interface should be implemented by the class which provides the | |
| 32 // ability to pipe the log somewhere else (Eg. a java class which can write | |
| 33 // logs into a file). It's optional and uses SetClient() to attach the client | |
| 34 // to the event logger instance. | |
| 35 class Client { | |
| 36 public: | |
| 37 virtual ~Client(){}; | |
| 38 virtual void CustomLog(const std::string& message) = 0; | |
| 39 }; | |
| 40 | |
| 41 OfflineEventLogger(); | |
| 42 | |
| 43 ~OfflineEventLogger(); | |
| 44 | |
| 45 // Clears the recorded activities. | |
| 46 void Clear(); | |
| 47 | |
| 48 // Turns logging on/off. | |
| 49 void SetIsLogging(bool is_logging); | |
| 50 | |
| 51 // Returns whether we are currently logging. | |
| 52 bool GetIsLogging(); | |
| 53 | |
| 54 // Dumps the current activity list into |records|. | |
| 55 void GetLogs(std::vector<std::string>* records); | |
| 56 | |
| 57 // Write the activity into the cycling log if we are currently logging. | |
| 58 void RecordActivity(const std::string& activity); | |
| 59 | |
| 60 // Sets the client for custom logging process if needed. | |
| 61 void SetClient(Client* client); | |
| 62 | |
| 63 private: | |
| 64 // Recorded offline page activities. | |
| 65 std::deque<std::string> activities_; | |
| 66 | |
| 67 // Whether we are currently recording logs or not. | |
| 68 bool is_logging_; | |
| 69 | |
| 70 // Not owned. | |
| 71 Client* client_; | |
| 72 }; | |
| 73 } // namespace offline_pages | |
| 74 | |
| 75 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_EVENT_LOGGER_H_ | |
| OLD | NEW |