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 { | |
|
Sigurður Ásgeirsson
2017/03/06 19:00:10
This class appears to be a test seam, and it's sta
manzagop (departed)
2017/03/06 21:14:42
Done.
| |
| 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 // Creates a SystemSessionEventFetcher that will query for events pertaining | |
| 26 // to the last session_cnt sessions. | |
| 27 explicit SystemSessionEventFetcher(uint32_t session_cnt); | |
| 28 | |
| 29 // Queries 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 uint32_t session_cnt_; | |
| 36 | |
| 37 DISALLOW_COPY_AND_ASSIGN(SystemSessionEventFetcher); | |
| 38 }; | |
| 39 | |
| 40 // Analyzes system session events for unclean sessions. Initialization is | |
| 41 // expensive and therefore done lazily, as the analyzer is instantiated before | |
| 42 // knowing whether it will be used. | |
| 43 class SystemSessionAnalyzer { | |
| 44 public: | |
| 45 enum Status { | |
| 46 FAILED = 0, | |
| 47 CLEAN = 1, | |
| 48 UNCLEAN = 2, | |
| 49 OUTSIDE_RANGE = 3, | |
| 50 }; | |
| 51 | |
| 52 explicit SystemSessionAnalyzer(SystemSessionEventFetcher* fetcher); | |
| 53 virtual ~SystemSessionAnalyzer(); | |
| 54 | |
| 55 // Returns an analysis status for the system session that contains timestamp. | |
| 56 virtual Status IsSessionUnclean(base::Time timestamp); | |
| 57 | |
| 58 private: | |
| 59 void Initialize(); | |
| 60 | |
| 61 SystemSessionEventFetcher* event_fetcher_; // Not owned. | |
| 62 | |
| 63 bool initialized_ = false; | |
| 64 bool init_success_ = false; | |
| 65 | |
| 66 // Information about unclean sessions: start time to duration until the next | |
| 67 // session start, ie *not* session duration. Note: it's easier to get the | |
| 68 // delta to the next session start, and changes nothing wrt classiying | |
| 69 // events that occur during sessions assuming query timestamps fall within | |
| 70 // system sessions. | |
| 71 std::map<base::Time, base::TimeDelta> unclean_sessions_; | |
| 72 | |
| 73 // Timestamp of the oldest event. | |
| 74 base::Time coverage_start_; | |
| 75 | |
| 76 DISALLOW_COPY_AND_ASSIGN(SystemSessionAnalyzer); | |
| 77 }; | |
| 78 | |
| 79 } // namespace browser_watcher | |
| 80 | |
| 81 #endif // COMPONENTS_BROWSER_WATCHER_SYSTEM_SESSION_ANALYZER_WIN_H_ | |
| OLD | NEW |