Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Unified Diff: content/public/android/java/src/org/chromium/content/app/DownloadProcessService.java

Issue 1622743005: Introduce background Download process to android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moving away from ChildProcessLauncher Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/public/android/java/src/org/chromium/content/app/DownloadProcessService.java
diff --git a/content/public/android/java/src/org/chromium/content/app/DownloadProcessService.java b/content/public/android/java/src/org/chromium/content/app/DownloadProcessService.java
new file mode 100644
index 0000000000000000000000000000000000000000..f0ed7f0a1c13b88bec1cb4c60381bb2e7be5f609
--- /dev/null
+++ b/content/public/android/java/src/org/chromium/content/app/DownloadProcessService.java
@@ -0,0 +1,72 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.content.app;
+
+import android.annotation.SuppressLint;
+import android.app.Notification;
+import android.content.Intent;
+import android.os.Build;
+import android.os.Bundle;
+import android.os.IBinder;
+import android.os.RemoteException;
+
+import org.chromium.base.Log;
+import org.chromium.base.annotations.JNINamespace;
+import org.chromium.content.browser.ChildProcessConstants;
+import org.chromium.content.common.IChildProcessCallback;
+
+/**
+ * Background download process for handling all transferable downloads.
+ */
+@JNINamespace("content")
+public class DownloadProcessService extends ChildProcessService {
+ private static final String TAG = "DownloadProcess";
+ private long mClientContext;
+ private IChildProcessCallback mCallback;
+ private int mDownloadCount;
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ // TODO(qinmin): Use the first pending download as notification, or
+ // get a more proper notification for this.
+ startForeground(ChildProcessConstants.DOWNLOAD_PROCESS_NOTIFICATION_ID, new Notification());
+ }
+
+ @Override
+ @SuppressLint("NewApi")
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ assert Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2;
+ initializeParams(intent);
+ Bundle bundle = intent.getExtras();
+ if (bundle != null) {
+ IBinder binder = bundle.getBinder(ChildProcessConstants.EXTRA_CHILD_PROCESS_CALLBACK);
+ mCallback = IChildProcessCallback.Stub.asInterface(binder);
+ }
+ return START_STICKY;
+ }
+
+ /**
+ * Will be called by the native side when a download starts or is rejected.
+ */
+ private void onDownloadStarted(boolean started, int downloadId) {
+ if (mCallback != null) {
+ try {
+ mCallback.onDownloadStarted(started, downloadId);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Unable to callback the browser process.", e);
+ }
+ }
+ if (started) mDownloadCount++;
+ }
+
+ /**
+ * Will be called by the native side when a download completes.
+ */
+ private void onDownloadCompleted(boolean success) {
+ mDownloadCount--;
+ if (mDownloadCount == 0) stopSelf();
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698