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.gsa; | 5 package org.chromium.chrome.browser.gsa; |
6 | 6 |
7 import android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
8 import android.app.ActivityManager; | 8 import android.app.ActivityManager; |
9 import android.content.ComponentName; | 9 import android.content.ComponentName; |
10 import android.content.Context; | 10 import android.content.Context; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 public static final int REQUEST_REGISTER_CLIENT = 2; | 46 public static final int REQUEST_REGISTER_CLIENT = 2; |
47 public static final int RESPONSE_UPDATE_SSB = 3; | 47 public static final int RESPONSE_UPDATE_SSB = 3; |
48 | 48 |
49 public static final String KEY_GSA_STATE = "ssb_service:ssb_state"; | 49 public static final String KEY_GSA_STATE = "ssb_service:ssb_state"; |
50 public static final String KEY_GSA_CONTEXT = "ssb_service:ssb_context"; | 50 public static final String KEY_GSA_CONTEXT = "ssb_service:ssb_context"; |
51 public static final String KEY_GSA_PACKAGE_NAME = "ssb_service:ssb_package_n
ame"; | 51 public static final String KEY_GSA_PACKAGE_NAME = "ssb_service:ssb_package_n
ame"; |
52 | 52 |
53 @VisibleForTesting | 53 @VisibleForTesting |
54 static final int INVALID_PSS = -1; | 54 static final int INVALID_PSS = -1; |
55 | 55 |
| 56 static final String ACCOUNT_CHANGE_HISTOGRAM = "Search.GsaAccountChangeNotif
icationSource"; |
| 57 // For the histogram above. Append-only. |
| 58 static final int ACCOUNT_CHANGE_SOURCE_SERVICE = 0; |
| 59 static final int ACCOUNT_CHANGE_SOURCE_BROADCAST = 1; |
| 60 static final int ACCOUNT_CHANGE_SOURCE_COUNT = 2; |
| 61 |
56 private static boolean sHasRecordedPss; | 62 private static boolean sHasRecordedPss; |
57 /** Messenger to handle incoming messages from the service */ | 63 /** Messenger to handle incoming messages from the service */ |
58 private final Messenger mMessenger; | 64 private final Messenger mMessenger; |
59 private final IncomingHandler mHandler; | 65 private final IncomingHandler mHandler; |
60 private final GSAServiceConnection mConnection; | 66 private final GSAServiceConnection mConnection; |
61 private final GSAHelper mGsaHelper; | 67 private final GSAHelper mGsaHelper; |
62 private Context mContext; | 68 private Context mContext; |
63 private Callback<Bundle> mOnMessageReceived; | 69 private Callback<Bundle> mOnMessageReceived; |
64 | 70 |
65 /** Messenger for communicating with service. */ | 71 /** Messenger for communicating with service. */ |
66 private Messenger mService; | 72 private Messenger mService; |
67 private ComponentName mComponentName; | 73 private ComponentName mComponentName; |
68 | 74 |
69 /** | 75 /** |
70 * Handler of incoming messages from service. | 76 * Handler of incoming messages from service. |
71 */ | 77 */ |
72 @SuppressFBWarnings("BC_IMPOSSIBLE_CAST") | 78 @SuppressFBWarnings("BC_IMPOSSIBLE_CAST") |
73 @SuppressLint("HandlerLeak") | 79 @SuppressLint("HandlerLeak") |
74 private class IncomingHandler extends Handler { | 80 private class IncomingHandler extends Handler { |
75 @Override | 81 @Override |
76 public void handleMessage(Message msg) { | 82 public void handleMessage(Message msg) { |
77 if (msg.what != RESPONSE_UPDATE_SSB) { | 83 if (msg.what != RESPONSE_UPDATE_SSB) { |
78 super.handleMessage(msg); | 84 super.handleMessage(msg); |
79 return; | 85 return; |
80 } | 86 } |
81 | 87 |
82 if (mService == null) return; | 88 if (mService == null) return; |
83 final Bundle bundle = (Bundle) msg.obj; | 89 final Bundle bundle = (Bundle) msg.obj; |
84 String account = mGsaHelper.getGSAAccountFromState(bundle.getByteArr
ay(KEY_GSA_STATE)); | 90 String account = mGsaHelper.getGSAAccountFromState(bundle.getByteArr
ay(KEY_GSA_STATE)); |
| 91 RecordHistogram.recordEnumeratedHistogram(ACCOUNT_CHANGE_HISTOGRAM, |
| 92 ACCOUNT_CHANGE_SOURCE_SERVICE, ACCOUNT_CHANGE_SOURCE_COUNT); |
85 GSAState.getInstance(mContext.getApplicationContext()).setGsaAccount
(account); | 93 GSAState.getInstance(mContext.getApplicationContext()).setGsaAccount
(account); |
86 if (sHasRecordedPss) { | 94 if (sHasRecordedPss) { |
87 if (mOnMessageReceived != null) mOnMessageReceived.onResult(bund
le); | 95 if (mOnMessageReceived != null) mOnMessageReceived.onResult(bund
le); |
88 return; | 96 return; |
89 } | 97 } |
90 | 98 |
91 // Getting the PSS for the GSA service process can be long, don't bl
ock the UI thread on | 99 // Getting the PSS for the GSA service process can be long, don't bl
ock the UI thread on |
92 // that. Also, don't process the callback before the PSS is known, s
ince the callback | 100 // that. Also, don't process the callback before the PSS is known, s
ince the callback |
93 // can lead to a service disconnect, which can lead to the framework
killing the | 101 // can lead to a service disconnect, which can lead to the framework
killing the |
94 // process. Hence an AsyncTask (long operation), and processing the
callback in | 102 // process. Hence an AsyncTask (long operation), and processing the
callback in |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 registerClientMessage.getData().putString( | 245 registerClientMessage.getData().putString( |
238 KEY_GSA_PACKAGE_NAME, mContext.getPackageName()); | 246 KEY_GSA_PACKAGE_NAME, mContext.getPackageName()); |
239 mService.send(registerClientMessage); | 247 mService.send(registerClientMessage); |
240 // Send prepare overlay message if there is a pending GSA contex
t. | 248 // Send prepare overlay message if there is a pending GSA contex
t. |
241 } catch (RemoteException e) { | 249 } catch (RemoteException e) { |
242 Log.w(SERVICE_CONNECTION_TAG, "GSAServiceConnection - remote cal
l failed", e); | 250 Log.w(SERVICE_CONNECTION_TAG, "GSAServiceConnection - remote cal
l failed", e); |
243 } | 251 } |
244 } | 252 } |
245 } | 253 } |
246 } | 254 } |
OLD | NEW |