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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/media/router/cast/CastRequestIdGenerator.java

Issue 1429833002: Cast Media Router: fix a few issues to pass some tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months 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
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/media/router/cast/CastRouteController.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/media/router/cast/CastRequestIdGenerator.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/media/router/cast/CastRequestIdGenerator.java b/chrome/android/java/src/org/chromium/chrome/browser/media/router/cast/CastRequestIdGenerator.java
new file mode 100644
index 0000000000000000000000000000000000000000..c753a838ec3889c5c7a39344c0301f3ef1b54921
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/media/router/cast/CastRequestIdGenerator.java
@@ -0,0 +1,37 @@
+// Copyright 2015 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.
+
+package org.chromium.chrome.browser.media.router.cast;
+
+/**
+ * Returns a request id in a range that is considered fairly unique. These request ids are used to
+ * communicate with the cast device and identify messages and their responses.
+ */
+public class CastRequestIdGenerator {
+ private static final Object LOCK = new Object();
+ private static CastRequestIdGenerator sInstance;
+
+ private int mRequestId;
+
+ /** Returns the next requestId in the range allocated to communicate with the device. */
+ public static int getNextRequestId() {
+ CastRequestIdGenerator instance = getInstance();
+
+ // Return the current |mRequestId| then increment. Never return 0 because it is reserved.
+ if (instance.mRequestId == 0) ++instance.mRequestId;
+ return instance.mRequestId++;
+ }
+
+ /** Returns the Singleton instance of the CastRequestIdGenerator. */
+ private static CastRequestIdGenerator getInstance() {
+ synchronized (LOCK) {
+ if (sInstance == null) sInstance = new CastRequestIdGenerator();
+ }
+ return sInstance;
+ }
+
+ private CastRequestIdGenerator() {
+ mRequestId = (int) Math.floor(Math.random() * 100000.0) * 1000;
+ }
+}
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/media/router/cast/CastRouteController.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698