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/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 private: | |
| 44 FRIEND_TEST_ALL_PREFIXES(SystemSessionAnalyzerTest, FetchEvents); | |
| 45 | |
| 46 bool Initialize(); | |
| 47 | |
| 48 // Queries for events pertaining to the last session_cnt sessions. On success, | |
| 49 // returns true and event_infos contains events ordered from newest to oldest. | |
| 50 // Returns false otherwise. Virtual for unit testing. | |
| 51 virtual bool FetchEvents(std::vector<EventInfo>* event_infos) const; | |
| 52 | |
| 53 // The number of sessions to query events for. | |
| 54 uint32_t session_cnt_; | |
| 55 | |
| 56 bool initialized_ = false; | |
| 57 bool init_success_ = false; | |
| 58 | |
| 59 // Information about unclean sessions: start time to duration until the next | |
| 60 // session start, ie *not* session duration. Note: it's easier to get the | |
| 61 // delta to the next session start, and changes nothing wrt classiying | |
|
Sigurður Ásgeirsson
2017/03/07 14:38:39
nit: speling[sic]
manzagop (departed)
2017/03/07 15:49:02
Done.
| |
| 62 // events that occur during sessions assuming query timestamps fall within | |
| 63 // system sessions. | |
| 64 std::map<base::Time, base::TimeDelta> unclean_sessions_; | |
| 65 | |
| 66 // Timestamp of the oldest event. | |
| 67 base::Time coverage_start_; | |
| 68 | |
| 69 DISALLOW_COPY_AND_ASSIGN(SystemSessionAnalyzer); | |
| 70 }; | |
| 71 | |
| 72 } // namespace browser_watcher | |
| 73 | |
| 74 #endif // COMPONENTS_BROWSER_WATCHER_SYSTEM_SESSION_ANALYZER_WIN_H_ | |
| OLD | NEW |