Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(242)

Side by Side Diff: components/offline_pages/offline_event_logger.h

Issue 2529603004: [Offline Pages] Expanding event logger to be used by harness. (Closed)
Patch Set: more comments. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/offline_pages/BUILD.gn ('k') | components/offline_pages/offline_event_logger.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 namespace offline_pages { 14 namespace offline_pages {
15 15
16 // Maximum number of recorded Logs to keep track of at any moment. 16 // Maximum number of recorded Logs to keep track of at any moment. Defined in
17 static const size_t kMaxLogCount = 50; 17 // offline_event_logger.cc.
18 extern const size_t kMaxLogCount;
18 19
19 // Facilitates the logging of events. Subclasses should create methods that 20 // Facilitates the logging of events. Subclasses should create methods that
20 // call RecordActivity to write into the log. |SetIsLogging|, |GetLogs|, and 21 // call RecordActivity to write into the log. |SetIsLogging|, |GetLogs|, and
21 // |Clear| are called from the chrome://offline-internals page. 22 // |Clear| are called from the chrome://offline-internals page.
22 // 23 //
23 // Logging should be done by calling the corresponding subclass methods when 24 // 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 // 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 // or when an offlined page has been accessed/saved).
26 // 27 //
27 // This log only keeps track of the last |kMaxLogCount| events. 28 // This log only keeps track of the last |kMaxLogCount| events.
28 class OfflineEventLogger { 29 class OfflineEventLogger {
29 public: 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
30 OfflineEventLogger(); 41 OfflineEventLogger();
31 42
32 ~OfflineEventLogger(); 43 ~OfflineEventLogger();
33 44
34 // Clears the recorded activities. 45 // Clears the recorded activities.
35 void Clear(); 46 void Clear();
36 47
37 // Turns logging on/off. 48 // Turns logging on/off.
38 void SetIsLogging(bool is_logging); 49 void SetIsLogging(bool is_logging);
39 50
40 // Returns whether we are currently logging. 51 // Returns whether we are currently logging.
41 bool GetIsLogging(); 52 bool GetIsLogging();
42 53
43 // Dumps the current activity list into |records|. 54 // Dumps the current activity list into |records|.
44 void GetLogs(std::vector<std::string>* records); 55 void GetLogs(std::vector<std::string>* records);
45 56
46 protected:
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
60 // Sets the client for custom logging process if needed.
61 void SetClient(Client* client);
62
50 private: 63 private:
51 // Recorded offline page activities. 64 // Recorded offline page activities.
52 std::deque<std::string> activities_; 65 std::deque<std::string> activities_;
53 66
54 // Whether we are currently recording logs or not. 67 // Whether we are currently recording logs or not.
55 bool is_logging_; 68 bool is_logging_;
69
70 // Not owned.
71 Client* client_;
56 }; 72 };
57 } // namespace offline_pages 73 } // namespace offline_pages
58 74
59 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_EVENT_LOGGER_H_ 75 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_EVENT_LOGGER_H_
OLDNEW
« no previous file with comments | « components/offline_pages/BUILD.gn ('k') | components/offline_pages/offline_event_logger.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698