OLD | NEW |
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.customtabs; | 5 package org.chromium.chrome.browser.customtabs; |
6 | 6 |
7 import android.content.Intent; | 7 import android.content.Intent; |
8 import android.net.Uri; | 8 import android.net.Uri; |
9 import android.os.Bundle; | 9 import android.os.Bundle; |
10 import android.os.IBinder; | 10 import android.os.IBinder; |
11 import android.support.customtabs.CustomTabsService; | 11 import android.support.customtabs.CustomTabsService; |
12 import android.support.customtabs.CustomTabsSessionToken; | 12 import android.support.customtabs.CustomTabsSessionToken; |
13 | 13 |
14 import org.chromium.chrome.browser.firstrun.FirstRunFlowSequencer; | 14 import org.chromium.chrome.browser.firstrun.FirstRunFlowSequencer; |
15 | 15 |
16 import java.util.List; | 16 import java.util.List; |
17 | 17 |
18 /** | 18 /** |
19 * Custom tabs connection service, used by the embedded Chrome activities. | 19 * Custom tabs connection service, used by the embedded Chrome activities. |
20 */ | 20 */ |
21 public class CustomTabsConnectionService extends CustomTabsService { | 21 public class CustomTabsConnectionService extends CustomTabsService { |
22 private CustomTabsConnection mConnection; | 22 private CustomTabsConnection mConnection; |
| 23 private Intent mBindIntent; |
23 | 24 |
24 @Override | 25 @Override |
25 public IBinder onBind(Intent intent) { | 26 public IBinder onBind(Intent intent) { |
26 boolean firstRunNecessary = FirstRunFlowSequencer | 27 mBindIntent = intent; |
27 .checkIfFirstRunIsNecessary(getApplicationContext(), intent) !=
null; | |
28 if (firstRunNecessary) return null; | |
29 mConnection = CustomTabsConnection.getInstance(getApplication()); | 28 mConnection = CustomTabsConnection.getInstance(getApplication()); |
30 mConnection.logCall("Service#onBind()", true); | 29 mConnection.logCall("Service#onBind()", true); |
31 return super.onBind(intent); | 30 return super.onBind(intent); |
32 } | 31 } |
33 | 32 |
34 @Override | 33 @Override |
35 public boolean onUnbind(Intent intent) { | 34 public boolean onUnbind(Intent intent) { |
36 super.onUnbind(intent); | 35 super.onUnbind(intent); |
37 if (mConnection != null) mConnection.logCall("Service#onUnbind()", true)
; | 36 if (mConnection != null) mConnection.logCall("Service#onUnbind()", true)
; |
38 return false; // No support for onRebind(). | 37 return false; // No support for onRebind(). |
39 } | 38 } |
40 | 39 |
41 @Override | 40 @Override |
42 protected boolean warmup(long flags) { | 41 protected boolean warmup(long flags) { |
| 42 if (!isFirstRunDone()) return false; |
43 return mConnection.warmup(flags); | 43 return mConnection.warmup(flags); |
44 } | 44 } |
45 | 45 |
46 @Override | 46 @Override |
47 protected boolean newSession(CustomTabsSessionToken sessionToken) { | 47 protected boolean newSession(CustomTabsSessionToken sessionToken) { |
48 return mConnection.newSession(sessionToken); | 48 return mConnection.newSession(sessionToken); |
49 } | 49 } |
50 | 50 |
51 @Override | 51 @Override |
52 protected boolean mayLaunchUrl(CustomTabsSessionToken sessionToken, Uri url,
Bundle extras, | 52 protected boolean mayLaunchUrl(CustomTabsSessionToken sessionToken, Uri url,
Bundle extras, |
53 List<Bundle> otherLikelyBundles) { | 53 List<Bundle> otherLikelyBundles) { |
| 54 if (!isFirstRunDone()) return false; |
54 return mConnection.mayLaunchUrl(sessionToken, url, extras, otherLikelyBu
ndles); | 55 return mConnection.mayLaunchUrl(sessionToken, url, extras, otherLikelyBu
ndles); |
55 } | 56 } |
56 | 57 |
57 @Override | 58 @Override |
58 protected Bundle extraCommand(String commandName, Bundle args) { | 59 protected Bundle extraCommand(String commandName, Bundle args) { |
59 return mConnection.extraCommand(commandName, args); | 60 return mConnection.extraCommand(commandName, args); |
60 } | 61 } |
61 | 62 |
62 @Override | 63 @Override |
63 protected boolean updateVisuals(CustomTabsSessionToken sessionToken, Bundle
bundle) { | 64 protected boolean updateVisuals(CustomTabsSessionToken sessionToken, Bundle
bundle) { |
| 65 if (!isFirstRunDone()) return false; |
64 return mConnection.updateVisuals(sessionToken, bundle); | 66 return mConnection.updateVisuals(sessionToken, bundle); |
65 } | 67 } |
66 | 68 |
67 @Override | 69 @Override |
68 protected boolean cleanUpSession(CustomTabsSessionToken sessionToken) { | 70 protected boolean cleanUpSession(CustomTabsSessionToken sessionToken) { |
69 mConnection.cleanUpSession(sessionToken); | 71 mConnection.cleanUpSession(sessionToken); |
70 return super.cleanUpSession(sessionToken); | 72 return super.cleanUpSession(sessionToken); |
71 } | 73 } |
| 74 |
| 75 private boolean isFirstRunDone() { |
| 76 if (mBindIntent == null) return true; |
| 77 boolean firstRunNecessary = FirstRunFlowSequencer |
| 78 .checkIfFirstRunIsNecessary(getApplicationContext(), mBindIntent
) != null; |
| 79 if (!firstRunNecessary) { |
| 80 mBindIntent = null; |
| 81 return true; |
| 82 } |
| 83 return false; |
| 84 } |
72 } | 85 } |
OLD | NEW |