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 CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_LIFETIME_TRACKER_H_ | |
| 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_LIFETIME_TRACKER_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <memory> | |
| 10 | |
| 11 #include "base/gtest_prod_util.h" | |
| 12 #include "base/macros.h" | |
| 13 #include "base/memory/ptr_util.h" | |
| 14 #include "base/time/tick_clock.h" | |
| 15 #include "base/timer/timer.h" | |
| 16 #include "content/common/content_export.h" | |
| 17 | |
| 18 namespace content { | |
| 19 | |
| 20 // ServiceWorkerLifetimeTracker tracks how long service workers run, for UMA | |
| 21 // purposes. | |
| 22 class CONTENT_EXPORT ServiceWorkerLifetimeTracker { | |
| 23 public: | |
| 24 ServiceWorkerLifetimeTracker(); | |
| 25 ServiceWorkerLifetimeTracker(std::unique_ptr<base::TickClock> tick_clock); | |
| 26 virtual ~ServiceWorkerLifetimeTracker(); | |
| 27 | |
| 28 // Called when the worker started running. | |
| 29 void StartTiming(int64_t version_id); | |
| 30 // Called when the worker stopped running. | |
| 31 void StopTiming(int64_t version_id); | |
| 32 // Called when DevTools was attached to the worker. Forgets the outstanding | |
| 33 // start timing. | |
| 34 void AbortTiming(int64_t version_id); | |
| 35 | |
| 36 private: | |
| 37 friend class ServiceWorkerLifetimeTrackerTest; | |
| 38 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerLifetimeTrackerTest, Metrics); | |
|
nhiroki
2017/02/23 07:54:23
Is this FRIEND_TEST_ALL_PREFIXES necessary? It loo
falken
2017/02/23 08:18:18
Ah, that was also refactored away. Done.
| |
| 39 | |
| 40 void RecordHistograms(); | |
| 41 | |
| 42 std::unique_ptr<base::TickClock> tick_clock_; | |
| 43 std::map<int64_t /* version_id */, base::TimeTicks /* start_time */> | |
| 44 running_workers_; | |
| 45 base::RepeatingTimer timer_; | |
| 46 base::WeakPtrFactory<ServiceWorkerLifetimeTracker> weak_factory_; | |
| 47 | |
| 48 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerLifetimeTracker); | |
| 49 }; | |
| 50 | |
| 51 } // namespace content | |
| 52 | |
| 53 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_LIFETIME_TRACKER_H_ | |
| OLD | NEW |