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 CrashFileManager crashFileManager = | 169 final CrashFileManager crashFileManager = |
167 new CrashFileManager(appContext.getCacheDir()); | 170 new CrashFileManager(appContext.getCacheDir()); |
168 final File[] minidumpFiles = | 171 final File[] minidumpFiles = |
169 crashFileManager.getAllMinidumpFiles(MAX_MINIDUMP_UPLOAD _TRIES); | 172 crashFileManager.getAllMinidumpFiles(MAX_MINIDUMP_UPLOAD _TRIES); |
170 if (minidumpFiles.length == 0) return null; | 173 if (minidumpFiles.length == 0) return null; |
171 | 174 |
175 // Delete the minidumps if the user doesn't allow crash data upl oading. | |
176 if (!userApproved) { | |
gsennton
2017/01/13 19:01:54
TODO also read enableForTesting flag (to have it o
gsennton
2017/01/23 17:50:39
Done (in WebViewFactoryProvider).
| |
177 for (File minidump : minidumpFiles) { | |
178 if (!minidump.delete()) { | |
179 Log.w(TAG, "Couldn't delete file " + minidump.getAbs olutePath()); | |
180 } | |
181 } | |
182 return null; | |
183 } | |
184 | |
172 final Intent intent = new Intent(); | 185 final Intent intent = new Intent(); |
173 intent.setClassName(webViewPackageName, CrashReceiverService.cla ss.getName()); | 186 intent.setClassName(webViewPackageName, CrashReceiverService.cla ss.getName()); |
174 | 187 |
175 ServiceConnection connection = new ServiceConnection() { | 188 ServiceConnection connection = new ServiceConnection() { |
176 @Override | 189 @Override |
177 public void onServiceConnected(ComponentName className, IBin der service) { | 190 public void onServiceConnected(ComponentName className, IBin der service) { |
178 // Pass file descriptors, pointing to our minidumps, to the minidump-copying | 191 // Pass file descriptors, pointing to our minidumps, to the minidump-copying |
179 // service so that the contents of the minidumps will be copied to WebView's | 192 // service so that the contents of the minidumps will be copied to WebView's |
180 // data directory. Delete our direct File-references to the minidumps after | 193 // data directory. Delete our direct File-references to the minidumps after |
181 // creating the file-descriptors to resign from retrying to copy the | 194 // creating the file-descriptors to resign from retrying to copy the |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 public void onServiceDisconnected(ComponentName className) { } | 233 public void onServiceDisconnected(ComponentName className) { } |
221 }; | 234 }; |
222 if (!appContext.bindService(intent, connection, Context.BIND_AUT O_CREATE)) { | 235 if (!appContext.bindService(intent, connection, Context.BIND_AUT O_CREATE)) { |
223 Log.w(TAG, "Could not bind to Minidump-copying Service " + i ntent); | 236 Log.w(TAG, "Could not bind to Minidump-copying Service " + i ntent); |
224 } | 237 } |
225 return null; | 238 return null; |
226 } | 239 } |
227 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); | 240 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
228 } | 241 } |
229 } | 242 } |
OLD | NEW |