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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: media/base/android/media_service_throttler.h
diff --git a/media/base/android/media_service_throttler.h b/media/base/android/media_service_throttler.h
new file mode 100644
index 0000000000000000000000000000000000000000..1d2773d737258f98acc3f00c6485972959c9dad9
--- /dev/null
+++ b/media/base/android/media_service_throttler.h
@@ -0,0 +1,76 @@
+// Copyright 2016 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 MEDIA_BASE_ANDROID_MEDIA_SERVICE_THROTTLER_H_
+#define MEDIA_BASE_ANDROID_MEDIA_SERVICE_THROTTLER_H_
+
+#include <memory>
+
+#include "base/callback_forward.h"
+#include "base/macros.h"
+#include "base/memory/singleton.h"
+#include "base/time/tick_clock.h"
+#include "base/time/time.h"
+
+namespace media {
+
+class MediaServiceThrottler {
DaleCurtis 2016/11/08 22:35:41 MEDIA_EXPORT?
tguilbert 2016/11/11 03:50:29 Done.
+ public:
+ // Called to get the singleton MediaServiceThrottler instance.
+ // The first thread on which GetInstance() is called is the thread on which
+ // calls to OnMediaServerCrash() will be signaled.
+ static MediaServiceThrottler* GetInstance();
+ 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.
+
+ // Returns the delay to wait until a new client is allowed to be created.
+ 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.
+
+ // Called by the MediaServerCrashListener whenever a crash is detected.
+ 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.
+
+ void SetTickClockForTesting(base::TickClock* clock);
+
+ void ResetInternalStateForTesting();
+
+ base::TimeDelta GetBaseThrottlingRateForTesting();
+
+ private:
+ friend struct base::DefaultSingletonTraits<MediaServiceThrottler>;
+ MediaServiceThrottler();
+
+ // Updates |current_craches_| according to a linear decay function.
+ void UpdateServerCrashes();
+
+ // Ensures that the MediaServerCrashListener was properly started (can lead
+ // to OnMediaServerCrash() being called in the case it hasn't).
+ void EnsureCrashListenerStarted();
+
+ // Gets the delay for ScheduleClientCreation(), which grows exponentially
+ // based on |current_crashes_|.
+ base::TimeDelta GetThrottlingDelayFromServerCrashes();
+
+ std::unique_ptr<base::TickClock> clock_;
+ bool is_media_server_crash_listener_running_;
+
+ // Effective number of media server crashes.
+ double current_crashes_;
+
+ // Next time at which a client creation can be scheduled.
+ base::TimeTicks next_schedulable_slot_;
+
+ // Last media server crash time.
+ base::TimeTicks last_server_crash_;
+
+ // Last time UpdateServerCrashes() was called.
+ 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.
+
+ // Last time ScheduleClientCreation() was called.
+ base::TimeTicks last_schedule_call_;
+
+ DISALLOW_COPY_AND_ASSIGN(MediaServiceThrottler);
+};
+
+} // namespace media
+
+#endif // MEDIA_BASE_ANDROID_MEDIA_SERVICE_THROTTLER_H_

Powered by Google App Engine
This is Rietveld 408576698