Chromium Code Reviews| Index: components/browser_watcher/system_session_analyzer_win.h |
| diff --git a/components/browser_watcher/system_session_analyzer_win.h b/components/browser_watcher/system_session_analyzer_win.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..76cedf7ed7bc134902884a6eba6cba22b6cde864 |
| --- /dev/null |
| +++ b/components/browser_watcher/system_session_analyzer_win.h |
| @@ -0,0 +1,74 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef COMPONENTS_BROWSER_WATCHER_SYSTEM_SESSION_ANALYZER_WIN_H_ |
| +#define COMPONENTS_BROWSER_WATCHER_SYSTEM_SESSION_ANALYZER_WIN_H_ |
| + |
| +#include <map> |
| +#include <memory> |
| +#include <vector> |
| + |
| +#include "base/gtest_prod_util.h" |
| +#include "base/time/time.h" |
| + |
| +namespace browser_watcher { |
| + |
| +// Analyzes system session events for unclean sessions. Initialization is |
| +// expensive and therefore done lazily, as the analyzer is instantiated before |
| +// knowing whether it will be used. |
| +class SystemSessionAnalyzer { |
| + public: |
| + enum Status { |
| + FAILED = 0, |
| + CLEAN = 1, |
| + UNCLEAN = 2, |
| + OUTSIDE_RANGE = 3, |
| + }; |
| + |
| + // Minimal information about a log event. |
| + struct EventInfo { |
| + uint16_t event_id; |
| + base::Time event_time; |
| + }; |
| + |
| + // Creates a SystemSessionAnalyzer that will analyze system sessions based on |
| + // events pertaining to the last session_cnt system sessions. |
| + explicit SystemSessionAnalyzer(uint32_t session_cnt); |
| + virtual ~SystemSessionAnalyzer(); |
| + |
| + // Returns an analysis status for the system session that contains timestamp. |
| + virtual Status IsSessionUnclean(base::Time timestamp); |
| + |
| + private: |
| + FRIEND_TEST_ALL_PREFIXES(SystemSessionAnalyzerTest, FetchEvents); |
| + |
| + bool Initialize(); |
| + |
| + // Queries for events pertaining to the last session_cnt sessions. On success, |
| + // returns true and event_infos contains events ordered from newest to oldest. |
| + // Returns false otherwise. Virtual for unit testing. |
| + virtual bool FetchEvents(std::vector<EventInfo>* event_infos) const; |
| + |
| + // The number of sessions to query events for. |
| + uint32_t session_cnt_; |
| + |
| + bool initialized_ = false; |
| + bool init_success_ = false; |
| + |
| + // Information about unclean sessions: start time to duration until the next |
| + // session start, ie *not* session duration. Note: it's easier to get the |
| + // 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.
|
| + // events that occur during sessions assuming query timestamps fall within |
| + // system sessions. |
| + std::map<base::Time, base::TimeDelta> unclean_sessions_; |
| + |
| + // Timestamp of the oldest event. |
| + base::Time coverage_start_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(SystemSessionAnalyzer); |
| +}; |
| + |
| +} // namespace browser_watcher |
| + |
| +#endif // COMPONENTS_BROWSER_WATCHER_SYSTEM_SESSION_ANALYZER_WIN_H_ |