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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/media/router/cast/CreateRouteRequest.java

Issue 2801033002: Revert of Android: Remove GetApplicationContext part 2 (Closed)
Patch Set: Created 3 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.media.router.cast; 5 package org.chromium.chrome.browser.media.router.cast;
6 6
7 import android.annotation.SuppressLint; 7 import android.annotation.SuppressLint;
8 import android.content.Context;
8 import android.os.Bundle; 9 import android.os.Bundle;
9 10
10 import com.google.android.gms.cast.ApplicationMetadata; 11 import com.google.android.gms.cast.ApplicationMetadata;
11 import com.google.android.gms.cast.Cast; 12 import com.google.android.gms.cast.Cast;
12 import com.google.android.gms.cast.CastStatusCodes; 13 import com.google.android.gms.cast.CastStatusCodes;
13 import com.google.android.gms.cast.LaunchOptions; 14 import com.google.android.gms.cast.LaunchOptions;
14 import com.google.android.gms.common.ConnectionResult; 15 import com.google.android.gms.common.ConnectionResult;
15 import com.google.android.gms.common.api.GoogleApiClient; 16 import com.google.android.gms.common.api.GoogleApiClient;
16 import com.google.android.gms.common.api.PendingResult; 17 import com.google.android.gms.common.api.PendingResult;
17 import com.google.android.gms.common.api.ResultCallback; 18 import com.google.android.gms.common.api.ResultCallback;
18 import com.google.android.gms.common.api.Status; 19 import com.google.android.gms.common.api.Status;
19 20
20 import org.chromium.base.ContextUtils;
21 import org.chromium.base.Log; 21 import org.chromium.base.Log;
22 import org.chromium.chrome.browser.media.router.ChromeMediaRouter; 22 import org.chromium.chrome.browser.media.router.ChromeMediaRouter;
23 import org.chromium.chrome.browser.media.router.MediaRoute; 23 import org.chromium.chrome.browser.media.router.MediaRoute;
24 24
25 /** 25 /**
26 * Establishes a {@link MediaRoute} by starting a Cast application represented b y the given 26 * Establishes a {@link MediaRoute} by starting a Cast application represented b y the given
27 * presentation URL. Reports success or failure to {@link ChromeMediaRouter}. 27 * presentation URL. Reports success or failure to {@link ChromeMediaRouter}.
28 * Since there're numerous asynchronous calls involved in getting the applicatio n to launch 28 * Since there're numerous asynchronous calls involved in getting the applicatio n to launch
29 * the class is implemented as a state machine. 29 * the class is implemented as a state machine.
30 */ 30 */
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 public boolean isIncognito() { 157 public boolean isIncognito() {
158 return mIsIncognito; 158 return mIsIncognito;
159 } 159 }
160 160
161 public int getNativeRequestId() { 161 public int getNativeRequestId() {
162 return mRequestId; 162 return mRequestId;
163 } 163 }
164 164
165 /** 165 /**
166 * Starts the process of launching the application on the Cast device. 166 * Starts the process of launching the application on the Cast device.
167 * @param applicationContext application context
168 * implementation provided by the caller.
167 */ 169 */
168 public void start() { 170 public void start(Context applicationContext) {
171 assert applicationContext != null;
172
169 if (mState != STATE_IDLE) throwInvalidState(); 173 if (mState != STATE_IDLE) throwInvalidState();
170 174
171 mApiClient = createApiClient(mCastListener); 175 mApiClient = createApiClient(mCastListener, applicationContext);
172 mApiClient.connect(); 176 mApiClient.connect();
173 mState = STATE_CONNECTING_TO_API; 177 mState = STATE_CONNECTING_TO_API;
174 } 178 }
175 179
176 @Override 180 @Override
177 public void onConnected(Bundle connectionHint) { 181 public void onConnected(Bundle connectionHint) {
178 if (mState != STATE_CONNECTING_TO_API && mState != STATE_API_CONNECTION_ SUSPENDED) { 182 if (mState != STATE_CONNECTING_TO_API && mState != STATE_API_CONNECTION_ SUSPENDED) {
179 throwInvalidState(); 183 throwInvalidState();
180 } 184 }
181 185
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 // See https://crbug.com/522478 226 // See https://crbug.com/522478
223 @Override 227 @Override
224 public void onConnectionFailed(ConnectionResult result) { 228 public void onConnectionFailed(ConnectionResult result) {
225 if (mState != STATE_CONNECTING_TO_API) throwInvalidState(); 229 if (mState != STATE_CONNECTING_TO_API) throwInvalidState();
226 230
227 Log.e(TAG, "GoogleApiClient connection failed: %d, %b", 231 Log.e(TAG, "GoogleApiClient connection failed: %d, %b",
228 result.getErrorCode(), result.hasResolution()); 232 result.getErrorCode(), result.hasResolution());
229 reportError(); 233 reportError();
230 } 234 }
231 235
232 private GoogleApiClient createApiClient(Cast.Listener listener) { 236 private GoogleApiClient createApiClient(Cast.Listener listener, Context cont ext) {
233 Cast.CastOptions.Builder apiOptionsBuilder = 237 Cast.CastOptions.Builder apiOptionsBuilder =
234 new Cast.CastOptions.Builder(mSink.getDevice(), listener) 238 new Cast.CastOptions.Builder(mSink.getDevice(), listener)
235 // TODO(avayvod): hide this behind the flag or remove 239 // TODO(avayvod): hide this behind the flag or remove
236 .setVerboseLoggingEnabled(true); 240 .setVerboseLoggingEnabled(true);
237 241
238 return new GoogleApiClient.Builder(ContextUtils.getApplicationContext()) 242 return new GoogleApiClient.Builder(context)
239 .addApi(Cast.API, apiOptionsBuilder.build()) 243 .addApi(Cast.API, apiOptionsBuilder.build())
240 .addConnectionCallbacks(this) 244 .addConnectionCallbacks(this)
241 .addOnConnectionFailedListener(this) 245 .addOnConnectionFailedListener(this)
242 .build(); 246 .build();
243 } 247 }
244 248
245 private PendingResult<Cast.ApplicationConnectionResult> launchApplication( 249 private PendingResult<Cast.ApplicationConnectionResult> launchApplication(
246 GoogleApiClient apiClient, 250 GoogleApiClient apiClient,
247 String appId, 251 String appId,
248 boolean relaunchIfRunning) { 252 boolean relaunchIfRunning) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 290
287 terminate(); 291 terminate();
288 } 292 }
289 293
290 private void terminate() { 294 private void terminate() {
291 mApiClient.unregisterConnectionCallbacks(this); 295 mApiClient.unregisterConnectionCallbacks(this);
292 mApiClient.unregisterConnectionFailedListener(this); 296 mApiClient.unregisterConnectionFailedListener(this);
293 mState = STATE_TERMINATED; 297 mState = STATE_TERMINATED;
294 } 298 }
295 } 299 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698