Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
|
no sievers
2016/02/03 22:46:52
nit: 2016
qinmin
2016/02/03 23:37:36
Done.
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package org.chromium.content.app; | |
| 6 | |
| 7 import android.annotation.SuppressLint; | |
| 8 import android.app.Notification; | |
| 9 import android.content.Intent; | |
| 10 import android.os.Build; | |
| 11 import android.os.Bundle; | |
| 12 import android.os.IBinder; | |
| 13 import android.os.RemoteException; | |
| 14 | |
| 15 import org.chromium.base.Log; | |
| 16 import org.chromium.base.annotations.JNINamespace; | |
| 17 import org.chromium.content.browser.ChildProcessConstants; | |
| 18 import org.chromium.content.common.IChildProcessCallback; | |
| 19 | |
| 20 /** | |
| 21 * Background download process for handling all transferable downloads. | |
| 22 */ | |
| 23 @JNINamespace("content") | |
| 24 public class DownloadProcessService extends ChildProcessService { | |
| 25 private static final String TAG = "DownloadProcess"; | |
| 26 private long mClientContext; | |
| 27 private IChildProcessCallback mCallback; | |
| 28 private int mDownloadCount; | |
| 29 | |
| 30 @Override | |
| 31 public void onCreate() { | |
| 32 super.onCreate(); | |
| 33 // TODO(qinmin): Use the first pending download as notification, or | |
| 34 // get a more proper notification for this. | |
| 35 startForeground(ChildProcessConstants.DOWNLOAD_PROCESS_NOTIFICATION_ID, new Notification()); | |
| 36 } | |
| 37 | |
| 38 @Override | |
| 39 @SuppressLint("NewApi") | |
| 40 public int onStartCommand(Intent intent, int flags, int startId) { | |
| 41 assert Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2; | |
| 42 initializeParams(intent); | |
| 43 Bundle bundle = intent.getExtras(); | |
| 44 if (bundle != null) { | |
| 45 IBinder binder = bundle.getBinder(ChildProcessConstants.EXTRA_CHILD_ PROCESS_CALLBACK); | |
| 46 mCallback = IChildProcessCallback.Stub.asInterface(binder); | |
| 47 getServiceInfo(bundle); | |
| 48 } | |
| 49 return START_STICKY; | |
| 50 } | |
| 51 | |
| 52 /** | |
| 53 * Will be called by the native side when a download starts or is rejected. | |
| 54 */ | |
|
no sievers
2016/02/03 22:46:52
@CalledByNative
qinmin
2016/02/03 23:37:36
added @CalledByNative in the comments. This is not
| |
| 55 private void onDownloadStarted(boolean started, int downloadId) { | |
| 56 if (mCallback != null) { | |
| 57 try { | |
| 58 mCallback.onDownloadStarted(started, downloadId); | |
| 59 } catch (RemoteException e) { | |
| 60 Log.e(TAG, "Unable to callback the browser process.", e); | |
| 61 } | |
| 62 } | |
| 63 if (started) mDownloadCount++; | |
| 64 } | |
| 65 | |
| 66 /** | |
| 67 * Will be called by the native side when a download completes. | |
| 68 */ | |
| 69 private void onDownloadCompleted(boolean success) { | |
|
no sievers
2016/02/03 22:46:52
@CalledByNative
qinmin
2016/02/03 23:37:36
same as above
| |
| 70 mDownloadCount--; | |
| 71 if (mDownloadCount == 0) stopSelf(); | |
| 72 } | |
| 73 } | |
| OLD | NEW |