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

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

Issue 2471903002: Add MediaServiceThrottler (Closed)
Patch Set: Integrate throttler into MediaPlayerRender 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/macros.h"
12 #include "base/memory/singleton.h"
13 #include "base/time/tick_clock.h"
14 #include "base/time/time.h"
15
16 namespace media {
17
18 class MediaServiceThrottler {
DaleCurtis 2016/11/08 22:35:41 MEDIA_EXPORT?
tguilbert 2016/11/11 03:50:29 Done.
19 public:
20 // Called to get the singleton MediaServiceThrottler instance.
21 // The first thread on which GetInstance() is called is the thread on which
22 // calls to OnMediaServerCrash() will be signaled.
23 static MediaServiceThrottler* GetInstance();
24 virtual ~MediaServiceThrottler();
sandersd (OOO until July 31) 2016/11/08 22:53:44 Can the destructor be made protected? If you need
tguilbert 2016/11/11 03:50:29 Done.
25
26 // Returns the delay to wait until a new client is allowed to be created.
27 base::TimeDelta ScheduleClientCreation();
sandersd (OOO until July 31) 2016/11/08 22:53:44 This is misleading because the scheduling is only
tguilbert 2016/11/11 03:50:29 Updated.
28
29 // Called by the MediaServerCrashListener whenever a crash is detected.
30 void OnMediaServerCrash();
sandersd (OOO until July 31) 2016/11/08 22:53:44 Should be protected or private.
tguilbert 2016/11/11 03:50:29 Done.
31
32 void SetTickClockForTesting(base::TickClock* clock);
33
34 void ResetInternalStateForTesting();
35
36 base::TimeDelta GetBaseThrottlingRateForTesting();
37
38 private:
39 friend struct base::DefaultSingletonTraits<MediaServiceThrottler>;
40 MediaServiceThrottler();
41
42 // Updates |current_craches_| according to a linear decay function.
43 void UpdateServerCrashes();
44
45 // Ensures that the MediaServerCrashListener was properly started (can lead
46 // to OnMediaServerCrash() being called in the case it hasn't).
47 void EnsureCrashListenerStarted();
48
49 // Gets the delay for ScheduleClientCreation(), which grows exponentially
50 // based on |current_crashes_|.
51 base::TimeDelta GetThrottlingDelayFromServerCrashes();
52
53 std::unique_ptr<base::TickClock> clock_;
54 bool is_media_server_crash_listener_running_;
55
56 // Effective number of media server crashes.
57 double current_crashes_;
58
59 // Next time at which a client creation can be scheduled.
60 base::TimeTicks next_schedulable_slot_;
61
62 // Last media server crash time.
63 base::TimeTicks last_server_crash_;
64
65 // Last time UpdateServerCrashes() was called.
66 base::TimeTicks last_update_time_;
sandersd (OOO until July 31) 2016/11/08 22:53:44 Nit: add 'crash' to variable name for clarity.
tguilbert 2016/11/11 03:50:29 Done.
67
68 // Last time ScheduleClientCreation() was called.
69 base::TimeTicks last_schedule_call_;
70
71 DISALLOW_COPY_AND_ASSIGN(MediaServiceThrottler);
72 };
73
74 } // namespace media
75
76 #endif // MEDIA_BASE_ANDROID_MEDIA_SERVICE_THROTTLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698