Chromium Code Reviews| 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..28b3e9b2604ff0af4844029cfdc5af55d9536437 |
| --- /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(); |
| + ServiceWorkerLifetimeTracker(std::unique_ptr<base::TickClock> tick_clock); |
| + virtual ~ServiceWorkerLifetimeTracker(); |
| + |
| + // Called when the worker started running. |
| + void StartTiming(int64_t version_id); |
|
nhiroki
2017/02/28 08:50:07
Can you replace version_id with embedded_worker_id
|
| + // Called when the worker stopped running. |
| + void StopTiming(int64_t version_id); |
| + // Called when DevTools was attached to the worker. Forgets the outstanding |
| + // start timing. |
| + void AbortTiming(int64_t version_id); |
| + |
| + private: |
| + friend class ServiceWorkerLifetimeTrackerTest; |
| + |
| + void RecordHistograms(); |
| + |
| + std::unique_ptr<base::TickClock> tick_clock_; |
| + std::map<int64_t /* version_id */, base::TimeTicks /* start_time */> |
| + running_workers_; |
| + base::RepeatingTimer timer_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ServiceWorkerLifetimeTracker); |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_LIFETIME_TRACKER_H_ |