| 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; |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 } | 150 } |
| 151 } finally { | 151 } finally { |
| 152 StrictMode.setThreadPolicy(oldPolicy); | 152 StrictMode.setThreadPolicy(oldPolicy); |
| 153 } | 153 } |
| 154 } | 154 } |
| 155 | 155 |
| 156 /** | 156 /** |
| 157 * Pass Minidumps to a separate Service declared in the WebView provider pac
kage. | 157 * Pass Minidumps to a separate Service declared in the WebView provider pac
kage. |
| 158 * That Service will copy the Minidumps to its own data directory - at which
point we can delete | 158 * That Service will copy the Minidumps to its own data directory - at which
point we can delete |
| 159 * our copies in the app directory. | 159 * our copies in the app directory. |
| 160 * @param userConsent whether we have user consent to upload crash data - if
we do, copy the |
| 161 * minidumps, if we don't, delete them. |
| 160 */ | 162 */ |
| 161 public static void handleMinidumps(final String webViewPackageName) { | 163 public static void handleMinidumps( |
| 164 final String webViewPackageName, final boolean userApproved) { |
| 162 new AsyncTask<Void, Void, Void>() { | 165 new AsyncTask<Void, Void, Void>() { |
| 163 @Override | 166 @Override |
| 164 protected Void doInBackground(Void... params) { | 167 protected Void doInBackground(Void... params) { |
| 165 final Context appContext = ContextUtils.getApplicationContext(); | 168 final Context appContext = ContextUtils.getApplicationContext(); |
| 166 final File crashSpoolDir = new File(appContext.getCacheDir().get
Path(), "WebView"); | 169 final File crashSpoolDir = new File(appContext.getCacheDir().get
Path(), "WebView"); |
| 167 if (!crashSpoolDir.isDirectory()) return null; | 170 if (!crashSpoolDir.isDirectory()) return null; |
| 168 final CrashFileManager crashFileManager = new CrashFileManager(c
rashSpoolDir); | 171 final CrashFileManager crashFileManager = new CrashFileManager(c
rashSpoolDir); |
| 169 final File[] minidumpFiles = | 172 final File[] minidumpFiles = |
| 170 crashFileManager.getAllMinidumpFiles(MAX_MINIDUMP_UPLOAD
_TRIES); | 173 crashFileManager.getAllMinidumpFiles(MAX_MINIDUMP_UPLOAD
_TRIES); |
| 171 if (minidumpFiles.length == 0) return null; | 174 if (minidumpFiles.length == 0) return null; |
| 172 | 175 |
| 176 // Delete the minidumps if the user doesn't allow crash data upl
oading. |
| 177 if (!userApproved) { |
| 178 for (File minidump : minidumpFiles) { |
| 179 if (!minidump.delete()) { |
| 180 Log.w(TAG, "Couldn't delete file " + minidump.getAbs
olutePath()); |
| 181 } |
| 182 } |
| 183 return null; |
| 184 } |
| 185 |
| 173 final Intent intent = new Intent(); | 186 final Intent intent = new Intent(); |
| 174 intent.setClassName(webViewPackageName, CrashReceiverService.cla
ss.getName()); | 187 intent.setClassName(webViewPackageName, CrashReceiverService.cla
ss.getName()); |
| 175 | 188 |
| 176 ServiceConnection connection = new ServiceConnection() { | 189 ServiceConnection connection = new ServiceConnection() { |
| 177 @Override | 190 @Override |
| 178 public void onServiceConnected(ComponentName className, IBin
der service) { | 191 public void onServiceConnected(ComponentName className, IBin
der service) { |
| 179 // Pass file descriptors, pointing to our minidumps, to
the minidump-copying | 192 // Pass file descriptors, pointing to our minidumps, to
the minidump-copying |
| 180 // service so that the contents of the minidumps will be
copied to WebView's | 193 // service so that the contents of the minidumps will be
copied to WebView's |
| 181 // data directory. Delete our direct File-references to
the minidumps after | 194 // data directory. Delete our direct File-references to
the minidumps after |
| 182 // creating the file-descriptors to resign from retrying
to copy the | 195 // creating the file-descriptors to resign from retrying
to copy the |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 public void onServiceDisconnected(ComponentName className) {
} | 234 public void onServiceDisconnected(ComponentName className) {
} |
| 222 }; | 235 }; |
| 223 if (!appContext.bindService(intent, connection, Context.BIND_AUT
O_CREATE)) { | 236 if (!appContext.bindService(intent, connection, Context.BIND_AUT
O_CREATE)) { |
| 224 Log.w(TAG, "Could not bind to Minidump-copying Service " + i
ntent); | 237 Log.w(TAG, "Could not bind to Minidump-copying Service " + i
ntent); |
| 225 } | 238 } |
| 226 return null; | 239 return null; |
| 227 } | 240 } |
| 228 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); | 241 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
| 229 } | 242 } |
| 230 } | 243 } |
| OLD | NEW |