OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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.android_webview; | 5 package org.chromium.android_webview; |
6 | 6 |
7 import android.content.ComponentName; | 7 import android.content.ComponentName; |
8 import android.content.Context; | 8 import android.content.Context; |
9 import android.content.Intent; | 9 import android.content.Intent; |
10 import android.content.ServiceConnection; | 10 import android.content.ServiceConnection; |
11 import android.os.AsyncTask; | 11 import android.os.AsyncTask; |
12 import android.os.IBinder; | 12 import android.os.IBinder; |
13 import android.os.ParcelFileDescriptor; | 13 import android.os.ParcelFileDescriptor; |
14 import android.os.RemoteException; | 14 import android.os.RemoteException; |
15 import android.os.StrictMode; | 15 import android.os.StrictMode; |
| 16 import android.webkit.ValueCallback; |
16 | 17 |
| 18 import org.chromium.android_webview.command_line.CommandLineUtil; |
17 import org.chromium.android_webview.crash.CrashReceiverService; | 19 import org.chromium.android_webview.crash.CrashReceiverService; |
18 import org.chromium.android_webview.crash.ICrashReceiverService; | 20 import org.chromium.android_webview.crash.ICrashReceiverService; |
19 import org.chromium.android_webview.policy.AwPolicyProvider; | 21 import org.chromium.android_webview.policy.AwPolicyProvider; |
20 import org.chromium.base.CommandLine; | 22 import org.chromium.base.CommandLine; |
21 import org.chromium.base.ContextUtils; | 23 import org.chromium.base.ContextUtils; |
22 import org.chromium.base.Log; | 24 import org.chromium.base.Log; |
23 import org.chromium.base.PathUtils; | 25 import org.chromium.base.PathUtils; |
24 import org.chromium.base.ThreadUtils; | 26 import org.chromium.base.ThreadUtils; |
| 27 import org.chromium.base.annotations.CalledByNative; |
| 28 import org.chromium.base.annotations.JNINamespace; |
25 import org.chromium.base.library_loader.LibraryLoader; | 29 import org.chromium.base.library_loader.LibraryLoader; |
26 import org.chromium.base.library_loader.LibraryProcessType; | 30 import org.chromium.base.library_loader.LibraryProcessType; |
27 import org.chromium.base.library_loader.ProcessInitException; | 31 import org.chromium.base.library_loader.ProcessInitException; |
28 import org.chromium.base.process_launcher.ChildProcessCreationParams; | 32 import org.chromium.base.process_launcher.ChildProcessCreationParams; |
29 import org.chromium.components.minidump_uploader.CrashFileManager; | 33 import org.chromium.components.minidump_uploader.CrashFileManager; |
30 import org.chromium.content.browser.BrowserStartupController; | 34 import org.chromium.content.browser.BrowserStartupController; |
31 import org.chromium.content.browser.ChildProcessLauncher; | 35 import org.chromium.content.browser.ChildProcessLauncher; |
32 import org.chromium.policy.CombinedPolicyProvider; | 36 import org.chromium.policy.CombinedPolicyProvider; |
33 | 37 |
34 import java.io.File; | 38 import java.io.File; |
35 import java.io.FileNotFoundException; | 39 import java.io.FileNotFoundException; |
36 import java.io.IOException; | 40 import java.io.IOException; |
37 import java.io.RandomAccessFile; | 41 import java.io.RandomAccessFile; |
38 import java.nio.channels.FileLock; | 42 import java.nio.channels.FileLock; |
39 | 43 |
40 /** | 44 /** |
41 * Wrapper for the steps needed to initialize the java and native sides of webvi
ew chromium. | 45 * Wrapper for the steps needed to initialize the java and native sides of webvi
ew chromium. |
42 */ | 46 */ |
| 47 @JNINamespace("android_webview") |
43 public abstract class AwBrowserProcess { | 48 public abstract class AwBrowserProcess { |
44 public static final String PRIVATE_DATA_DIRECTORY_SUFFIX = "webview"; | 49 public static final String PRIVATE_DATA_DIRECTORY_SUFFIX = "webview"; |
45 | 50 |
46 private static final String TAG = "AwBrowserProcess"; | 51 private static final String TAG = "AwBrowserProcess"; |
47 private static final String EXCLUSIVE_LOCK_FILE = "webview_data.lock"; | 52 private static final String EXCLUSIVE_LOCK_FILE = "webview_data.lock"; |
48 private static RandomAccessFile sLockFile; | 53 private static RandomAccessFile sLockFile; |
49 private static FileLock sExclusiveFileLock; | 54 private static FileLock sExclusiveFileLock; |
| 55 private static String sWebViewPackageName; |
50 | 56 |
51 private static final int MAX_MINIDUMP_UPLOAD_TRIES = 3; | 57 private static final int MAX_MINIDUMP_UPLOAD_TRIES = 3; |
52 | 58 |
53 /** | 59 /** |
54 * Loads the native library, and performs basic static construction of objec
ts needed | 60 * Loads the native library, and performs basic static construction of objec
ts needed |
55 * to run webview in this process. Does not create threads; safe to call fro
m zygote. | 61 * to run webview in this process. Does not create threads; safe to call fro
m zygote. |
56 * Note: it is up to the caller to ensure this is only called once. | 62 * Note: it is up to the caller to ensure this is only called once. |
57 */ | 63 */ |
58 public static void loadLibrary() { | 64 public static void loadLibrary() { |
59 PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX); | 65 PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 throw new RuntimeException(error); | 148 throw new RuntimeException(error); |
143 } else { | 149 } else { |
144 Log.w(TAG, error); | 150 Log.w(TAG, error); |
145 } | 151 } |
146 } | 152 } |
147 } finally { | 153 } finally { |
148 StrictMode.setThreadPolicy(oldPolicy); | 154 StrictMode.setThreadPolicy(oldPolicy); |
149 } | 155 } |
150 } | 156 } |
151 | 157 |
| 158 public static void setWebViewPackageName(String webViewPackageName) { |
| 159 assert sWebViewPackageName == null || sWebViewPackageName.equals(webView
PackageName); |
| 160 sWebViewPackageName = webViewPackageName; |
| 161 } |
| 162 |
| 163 /** |
| 164 * Trigger minidump copying, which in turn triggers minidump uploading. |
| 165 */ |
| 166 @CalledByNative |
| 167 private static void triggerMinidumpUploading() { |
| 168 handleMinidumpsAndSetMetricsConsent(sWebViewPackageName, false /* update
MetricsConsent */); |
| 169 } |
| 170 |
| 171 /** |
| 172 * Trigger minidump uploading, and optionaly also update the metrics-consent
value depending on |
| 173 * whether the Android Checkbox is toggled on. |
| 174 * @param updateMetricsConsent whether to update the metrics-consent value t
o represent the |
| 175 * Android Checkbox toggle. |
| 176 */ |
| 177 public static void handleMinidumpsAndSetMetricsConsent( |
| 178 final String webViewPackageName, final boolean updateMetricsConsent)
{ |
| 179 final boolean enableMinidumpUploadingForTesting = CommandLine.getInstanc
e().hasSwitch( |
| 180 CommandLineUtil.CRASH_UPLOADS_ENABLED_FOR_TESTING_SWITCH); |
| 181 if (enableMinidumpUploadingForTesting) { |
| 182 AwBrowserProcess.handleMinidumps(webViewPackageName, true /* enabled
*/); |
| 183 } |
| 184 |
| 185 PlatformServiceBridge.getInstance().queryMetricsSetting(new ValueCallbac
k<Boolean>() { |
| 186 // Actions conditioned on whether the Android Checkbox is toggled on |
| 187 public void onReceiveValue(Boolean enabled) { |
| 188 ThreadUtils.assertOnUiThread(); |
| 189 if (updateMetricsConsent) { |
| 190 AwMetricsServiceClient.setConsentSetting( |
| 191 ContextUtils.getApplicationContext(), enabled); |
| 192 } |
| 193 |
| 194 if (!enableMinidumpUploadingForTesting) { |
| 195 AwBrowserProcess.handleMinidumps(webViewPackageName, enabled
); |
| 196 } |
| 197 } |
| 198 }); |
| 199 } |
| 200 |
152 /** | 201 /** |
153 * Pass Minidumps to a separate Service declared in the WebView provider pac
kage. | 202 * Pass Minidumps to a separate Service declared in the WebView provider pac
kage. |
154 * That Service will copy the Minidumps to its own data directory - at which
point we can delete | 203 * That Service will copy the Minidumps to its own data directory - at which
point we can delete |
155 * our copies in the app directory. | 204 * our copies in the app directory. |
156 * @param userApproved whether we have user consent to upload crash data - i
f we do, copy the | 205 * @param userApproved whether we have user consent to upload crash data - i
f we do, copy the |
157 * minidumps, if we don't, delete them. | 206 * minidumps, if we don't, delete them. |
158 */ | 207 */ |
159 public static void handleMinidumps( | 208 public static void handleMinidumps( |
160 final String webViewPackageName, final boolean userApproved) { | 209 final String webViewPackageName, final boolean userApproved) { |
161 new AsyncTask<Void, Void, Void>() { | 210 new AsyncTask<Void, Void, Void>() { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 } | 276 } |
228 | 277 |
229 @Override | 278 @Override |
230 public void onServiceDisconnected(ComponentName className) {
} | 279 public void onServiceDisconnected(ComponentName className) {
} |
231 }; | 280 }; |
232 if (!appContext.bindService(intent, connection, Context.BIND_AUT
O_CREATE)) { | 281 if (!appContext.bindService(intent, connection, Context.BIND_AUT
O_CREATE)) { |
233 Log.w(TAG, "Could not bind to Minidump-copying Service " + i
ntent); | 282 Log.w(TAG, "Could not bind to Minidump-copying Service " + i
ntent); |
234 } | 283 } |
235 return null; | 284 return null; |
236 } | 285 } |
237 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); | 286 // To avoid any potential synchronization issues we post all minidum
p-copying actions to |
| 287 // the same thread to be run serially. |
| 288 } |
| 289 .executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); |
238 } | 290 } |
239 } | 291 } |
OLD | NEW |