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

Unified Diff: content/browser/service_worker/service_worker_lifetime_tracker.h

Issue 2706923003: Add UMA for how long service workers run for. (Closed)
Patch Set: tweaks, fmt 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: content/browser/service_worker/service_worker_lifetime_tracker.h
diff --git a/content/browser/service_worker/service_worker_lifetime_tracker.h b/content/browser/service_worker/service_worker_lifetime_tracker.h
new file mode 100644
index 0000000000000000000000000000000000000000..b9cb2bcba40d4d799b8e1043fa78a05579151fed
--- /dev/null
+++ b/content/browser/service_worker/service_worker_lifetime_tracker.h
@@ -0,0 +1,51 @@
+// 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 CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_LIFETIME_TRACKER_H_
+#define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_LIFETIME_TRACKER_H_
+
+#include <map>
+#include <memory>
+
+#include "base/gtest_prod_util.h"
+#include "base/macros.h"
+#include "base/memory/ptr_util.h"
+#include "base/time/tick_clock.h"
+#include "base/timer/timer.h"
+#include "content/common/content_export.h"
+
+namespace content {
+
+// ServiceWorkerLifetimeTracker tracks how long service workers run, for UMA
+// purposes.
+class CONTENT_EXPORT ServiceWorkerLifetimeTracker {
+ public:
+ ServiceWorkerLifetimeTracker();
+ explicit ServiceWorkerLifetimeTracker(
+ std::unique_ptr<base::TickClock> tick_clock);
+ virtual ~ServiceWorkerLifetimeTracker();
+
+ // Called when the worker started running.
+ void StartTiming(int64_t embedded_worker_id);
+ // Called when the worker stopped running.
+ void StopTiming(int64_t embedded_worker_id);
+ // Called when DevTools was attached to the worker. Forgets the outstanding
+ // start timing.
+ void AbortTiming(int64_t embedded_worker_id);
+
+ private:
+ friend class ServiceWorkerLifetimeTrackerTest;
+
+ void RecordHistograms();
+
+ std::unique_ptr<base::TickClock> tick_clock_;
+ std::map<int64_t /* embedded_worker_id */, base::TimeTicks /* start_time */>
+ running_workers_;
+
+ DISALLOW_COPY_AND_ASSIGN(ServiceWorkerLifetimeTracker);
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_LIFETIME_TRACKER_H_

Powered by Google App Engine
This is Rietveld 408576698