Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1525)

Unified Diff: components/browser_watcher/system_session_analyzer_win.h

Issue 2715903003: Bound the impact of system instability on chrome instability. (Closed)
Patch Set: Address Siggi's comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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_

Powered by Google App Engine
This is Rietveld 408576698