Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #ifndef COMPONENTS_OFFLINE_PAGES_OFFLINE_EVENT_LOGGER_H_ | 5 #ifndef COMPONENTS_OFFLINE_PAGES_OFFLINE_EVENT_LOGGER_H_ |
| 6 #define COMPONENTS_OFFLINE_PAGES_OFFLINE_EVENT_LOGGER_H_ | 6 #define COMPONENTS_OFFLINE_PAGES_OFFLINE_EVENT_LOGGER_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 | 13 |
| 14 #define OFFLINE_LOG_TAG \ | |
| 15 std::string(__FILE__) + "(" + std::to_string(__LINE__) + ") :" | |
| 16 | |
| 14 namespace offline_pages { | 17 namespace offline_pages { |
| 15 | 18 |
| 16 // Maximum number of recorded Logs to keep track of at any moment. | 19 // Maximum number of recorded Logs to keep track of at any moment. |
| 17 static const size_t kMaxLogCount = 50; | 20 static const size_t kMaxLogCount = 50; |
| 18 | 21 |
| 19 // Facilitates the logging of events. Subclasses should create methods that | 22 // Facilitates the logging of events. Subclasses should create methods that |
| 20 // call RecordActivity to write into the log. |SetIsLogging|, |GetLogs|, and | 23 // call RecordActivity to write into the log. |SetIsLogging|, |GetLogs|, and |
| 21 // |Clear| are called from the chrome://offline-internals page. | 24 // |Clear| are called from the chrome://offline-internals page. |
| 22 // | 25 // |
| 23 // Logging should be done by calling the corresponding subclass methods when | 26 // 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 | 27 // a loggable event occurs (i.e. when status has changed for a save request |
| 25 // or when an offlined page has been accessed/saved). | 28 // or when an offlined page has been accessed/saved). |
| 26 // | 29 // |
| 27 // This log only keeps track of the last |kMaxLogCount| events. | 30 // This log only keeps track of the last |kMaxLogCount| events. |
| 28 class OfflineEventLogger { | 31 class OfflineEventLogger { |
| 29 public: | 32 public: |
| 33 class Client { | |
|
chili
2016/11/25 00:00:07
So... if I understand it correctly, CustomLog and
romax
2016/11/30 00:15:10
Yes that was another option.
The goal is 'we need
chili
2016/11/30 04:56:39
Keeping the file handle on Java sounds/looks ok to
dougarnett
2016/11/30 18:05:25
It is a good point about hopping back and forth ov
romax
2016/12/01 01:47:52
Yes JNI is hard to test.
The current logging proce
chili
2016/12/01 21:07:04
I see.
As I mentioned, I'm fine with the CL as is
| |
| 34 public: | |
| 35 virtual void CustomLog(const std::string& message); | |
|
chili
2016/11/30 04:56:40
nit - should this also have = 0?
romax
2016/12/01 01:47:52
Done.
| |
| 36 }; | |
| 37 | |
| 30 OfflineEventLogger(); | 38 OfflineEventLogger(); |
| 31 | 39 |
| 32 ~OfflineEventLogger(); | 40 ~OfflineEventLogger(); |
| 33 | 41 |
| 34 // Clears the recorded activities. | 42 // Clears the recorded activities. |
| 35 void Clear(); | 43 void Clear(); |
| 36 | 44 |
| 37 // Turns logging on/off. | 45 // Turns logging on/off. |
| 38 void SetIsLogging(bool is_logging); | 46 void SetIsLogging(bool is_logging); |
| 39 | 47 |
| 40 // Returns whether we are currently logging. | 48 // Returns whether we are currently logging. |
| 41 bool GetIsLogging(); | 49 bool GetIsLogging(); |
| 42 | 50 |
| 43 // Dumps the current activity list into |records|. | 51 // Dumps the current activity list into |records|. |
| 44 void GetLogs(std::vector<std::string>* records); | 52 void GetLogs(std::vector<std::string>* records); |
| 45 | 53 |
| 46 protected: | 54 // Sets client. |
| 55 void SetClient(Client* client); | |
| 56 | |
| 47 // Write the activity into the cycling log if we are currently logging. | 57 // Write the activity into the cycling log if we are currently logging. |
| 48 void RecordActivity(const std::string& activity); | 58 void RecordActivity(const std::string& activity); |
| 49 | 59 |
| 50 private: | 60 private: |
| 51 // Recorded offline page activities. | 61 // Recorded offline page activities. |
| 52 std::deque<std::string> activities_; | 62 std::deque<std::string> activities_; |
| 53 | 63 |
| 54 // Whether we are currently recording logs or not. | 64 // Whether we are currently recording logs or not. |
| 55 bool is_logging_; | 65 bool is_logging_; |
| 66 | |
| 67 // Not owned. | |
| 68 Client* client_; | |
| 56 }; | 69 }; |
| 57 } // namespace offline_pages | 70 } // namespace offline_pages |
| 58 | 71 |
| 59 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_EVENT_LOGGER_H_ | 72 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_EVENT_LOGGER_H_ |
| OLD | NEW |