Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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_BROWSER_WATCHER_SYSTEM_SESSION_ANALYZER_WIN_H_ | |
| 6 #define COMPONENTS_BROWSER_WATCHER_SYSTEM_SESSION_ANALYZER_WIN_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <memory> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/time/time.h" | |
| 13 | |
| 14 namespace browser_watcher { | |
| 15 | |
| 16 // Queries system logs for system session events. | |
| 17 class SystemSessionEventFetcher { | |
| 18 public: | |
| 19 // Minimal information about a log event. | |
| 20 struct EventInfo { | |
| 21 uint16_t event_id; | |
| 22 base::Time event_time; | |
| 23 }; | |
| 24 | |
| 25 // Create a SystemSessionEventFetcher that will query for events pertaining to | |
| 26 // the last session_cnt sessions. | |
| 27 explicit SystemSessionEventFetcher(size_t session_cnt); | |
| 28 | |
| 29 // Query for events pertaining to the last session_cnt sessions. On success, | |
| 30 // returns true and event_infos contains events ordered from newest to oldest. | |
| 31 // Returns false otherwise. | |
| 32 virtual bool FetchEvents(std::vector<EventInfo>* event_infos) const; | |
| 33 | |
| 34 private: | |
| 35 size_t session_cnt_; | |
| 36 | |
| 37 DISALLOW_COPY_AND_ASSIGN(SystemSessionEventFetcher); | |
| 38 }; | |
| 39 | |
| 40 // Analyzes system session events for unclean sessions. | |
| 41 class SystemSessionAnalyzer { | |
| 42 public: | |
| 43 enum Status { | |
| 44 FAILED = 0, | |
| 45 CLEAN = 1, | |
| 46 UNCLEAN = 2, | |
| 47 OUTSIDE_RANGE = 3, | |
| 48 }; | |
| 49 | |
| 50 explicit SystemSessionAnalyzer(std::unique_ptr<SystemSessionEventFetcher>); | |
| 51 virtual ~SystemSessionAnalyzer() = default; | |
| 52 | |
| 53 virtual Status IsSessionUnclean(base::Time timestamp); | |
|
Will Harris
2017/02/27 22:40:11
comment?
manzagop (departed)
2017/02/28 14:51:51
Done.
| |
| 54 | |
| 55 private: | |
| 56 void Initialize(); | |
| 57 | |
| 58 std::unique_ptr<SystemSessionEventFetcher> event_fetcher_; | |
| 59 | |
| 60 bool initialized_ = false; | |
| 61 bool init_success_ = false; | |
| 62 | |
| 63 // Information about unclean sessions: start time to duration until the next | |
| 64 // session start, ie *not* session duration. Note: it's easier to get the | |
| 65 // delta to the next session start, and changes nothing wrt classiying | |
| 66 // events that occur during sessions assuming query timestamps fall within | |
| 67 // system sessions. | |
| 68 std::map<base::Time, base::TimeDelta> unclean_sessions_; | |
| 69 | |
| 70 // Timestamp of the oldest event. | |
| 71 base::Time coverage_start_; | |
| 72 | |
| 73 DISALLOW_COPY_AND_ASSIGN(SystemSessionAnalyzer); | |
| 74 }; | |
| 75 | |
| 76 } // namespace browser_watcher | |
| 77 | |
| 78 #endif // COMPONENTS_BROWSER_WATCHER_SYSTEM_SESSION_ANALYZER_WIN_H_ | |
| OLD | NEW |