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

Side by Side Diff: media/base/android/media_service_throttler.h

Issue 2471903002: Add MediaServiceThrottler (Closed)
Patch Set: Release resources after 1 min. +2 UTS. Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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 MEDIA_BASE_ANDROID_MEDIA_SERVICE_THROTTLER_H_
6 #define MEDIA_BASE_ANDROID_MEDIA_SERVICE_THROTTLER_H_
7
8 #include <memory>
9
10 #include "base/callback_forward.h"
11 #include "base/cancelable_callback.h"
12 #include "base/macros.h"
13 #include "base/lazy_instance.h"
14 #include "base/single_thread_task_runner.h"
15 #include "base/time/tick_clock.h"
16 #include "base/time/time.h"
17 #include "media/base/media_export.h"
18
19 namespace media {
20 class MediaServerCrashListener;
21
22 class MEDIA_EXPORT MediaServiceThrottler {
23 public:
24 // Called to get the singleton MediaServiceThrottler instance.
25 // The first thread on which GetInstance() is called is the thread on which
26 // calls to OnMediaServerCrash() will be signaled.
27 static MediaServiceThrottler* GetInstance();
28
29 // Returns the delay to wait until a new client is allowed to be created.
30 base::TimeDelta GetDelayForClientCreation();
31
32 void SetTickClockForTesting(base::TickClock* clock);
DaleCurtis 2016/11/11 23:32:16 Usually I'd put these as a single block with a com
tguilbert 2016/11/14 23:18:08 Done.
33
34 void ResetInternalStateForTesting();
35
36 base::TimeDelta GetBaseThrottlingRateForTesting();
37
38 bool IsCrashListenerAliveForTesting();
39
40 void SetCrashListenerTaskRunnerForTesting(
41 scoped_refptr<base::SingleThreadTaskRunner> crash_listener_task_runner);
42
43 private:
44 friend struct base::DefaultLazyInstanceTraits<MediaServiceThrottler>;
45 friend class MediaServiceThrottlerTest;
tguilbert 2016/11/11 03:50:29 Is adding tests as a friend class frowned upon? sa
sandersd (OOO until July 31) 2016/11/11 18:55:14 Friend classes are fine for testing, and common in
46
47 MediaServiceThrottler();
48 virtual ~MediaServiceThrottler();
49
50 // Called by the |crash_listener_| whenever a crash is detected.
51 void OnMediaServerCrash();
52
53 // Updates |current_craches_| according to a linear decay function.
54 void UpdateServerCrashes();
55
56 // Ensures that the MediaServerCrashListener was properly started (can lead
57 // to OnMediaServerCrash() being called in the case it hasn't).
58 void EnsureCrashListenerStarted();
59
60 // Frees up the resources used by |crash_listener_|;
61 void ReleaseCrashListener();
62
63 // Gets the delay for ScheduleClientCreation(), which grows exponentially
64 // based on |current_crashes_|.
65 base::TimeDelta GetThrottlingDelayFromServerCrashes();
66
67 std::unique_ptr<base::TickClock> clock_;
68
69 // Effective number of media server crashes.
DaleCurtis 2016/11/11 23:32:16 Explain why it's a double.
tguilbert 2016/11/14 23:18:08 Done.
70 double current_crashes_;
71
72 // Next time at which a client creation can be scheduled.
73 base::TimeTicks next_schedulable_slot_;
74
75 // Last media server crash time.
76 base::TimeTicks last_server_crash_;
77
78 // Last time UpdateServerCrashes() was called.
79 base::TimeTicks last_current_crash_update_time_;
80
81 // Last time ScheduleClientCreation() was called.
82 base::TimeTicks last_schedule_call_;
83
84 // Callbacks used to release |crash_listener_| after 60s of inactivity.
85 base::Closure release_crash_listener_cb_;
86 base::CancelableClosure cancelable_release_crash_listener_cb_;
87
88 // Listener that verifies
89 std::unique_ptr<MediaServerCrashListener> crash_listener_;
90
91 scoped_refptr<base::SingleThreadTaskRunner> crash_listener_task_runner_;
92
93 DISALLOW_COPY_AND_ASSIGN(MediaServiceThrottler);
94 };
95
96 } // namespace media
97
98 #endif // MEDIA_BASE_ANDROID_MEDIA_SERVICE_THROTTLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698