| 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/gtest_prod_util.h" |
| 13 #include "base/time/time.h" |
| 14 |
| 15 namespace browser_watcher { |
| 16 |
| 17 // Analyzes system session events for unclean sessions. Initialization is |
| 18 // expensive and therefore done lazily, as the analyzer is instantiated before |
| 19 // knowing whether it will be used. |
| 20 class SystemSessionAnalyzer { |
| 21 public: |
| 22 enum Status { |
| 23 FAILED = 0, |
| 24 CLEAN = 1, |
| 25 UNCLEAN = 2, |
| 26 OUTSIDE_RANGE = 3, |
| 27 }; |
| 28 |
| 29 // Minimal information about a log event. |
| 30 struct EventInfo { |
| 31 uint16_t event_id; |
| 32 base::Time event_time; |
| 33 }; |
| 34 |
| 35 // Creates a SystemSessionAnalyzer that will analyze system sessions based on |
| 36 // events pertaining to the last session_cnt system sessions. |
| 37 explicit SystemSessionAnalyzer(uint32_t session_cnt); |
| 38 virtual ~SystemSessionAnalyzer(); |
| 39 |
| 40 // Returns an analysis status for the system session that contains timestamp. |
| 41 virtual Status IsSessionUnclean(base::Time timestamp); |
| 42 |
| 43 protected: |
| 44 // Queries for events pertaining to the last session_cnt sessions. On success, |
| 45 // returns true and event_infos contains events ordered from newest to oldest. |
| 46 // Returns false otherwise. Virtual for unit testing. |
| 47 virtual bool FetchEvents(std::vector<EventInfo>* event_infos) const; |
| 48 |
| 49 private: |
| 50 FRIEND_TEST_ALL_PREFIXES(SystemSessionAnalyzerTest, FetchEvents); |
| 51 |
| 52 bool Initialize(); |
| 53 |
| 54 // The number of sessions to query events for. |
| 55 uint32_t session_cnt_; |
| 56 |
| 57 bool initialized_ = false; |
| 58 bool init_success_ = false; |
| 59 |
| 60 // Information about unclean sessions: start time to duration until the next |
| 61 // session start, ie *not* session duration. Note: it's easier to get the |
| 62 // delta to the next session start, and changes nothing wrt classifying |
| 63 // events that occur during sessions assuming query timestamps fall within |
| 64 // system sessions. |
| 65 std::map<base::Time, base::TimeDelta> unclean_sessions_; |
| 66 |
| 67 // Timestamp of the oldest event. |
| 68 base::Time coverage_start_; |
| 69 |
| 70 DISALLOW_COPY_AND_ASSIGN(SystemSessionAnalyzer); |
| 71 }; |
| 72 |
| 73 } // namespace browser_watcher |
| 74 |
| 75 #endif // COMPONENTS_BROWSER_WATCHER_SYSTEM_SESSION_ANALYZER_WIN_H_ |
| OLD | NEW |