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

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

Powered by Google App Engine
This is Rietveld 408576698