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

Unified Diff: chrome/browser/android/download/download_controller.h

Issue 2014803002: Move DownloadControllerAndroid from content/ to chrome/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix failing tests/bugs Created 4 years, 6 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: chrome/browser/android/download/download_controller.h
diff --git a/chrome/browser/android/download/download_controller.h b/chrome/browser/android/download/download_controller.h
new file mode 100644
index 0000000000000000000000000000000000000000..f7d07fda51e802e8939dc4905b117c6b3ec7a628
--- /dev/null
+++ b/chrome/browser/android/download/download_controller.h
@@ -0,0 +1,118 @@
+// Copyright 2016 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.
+
+// This class pairs with DownloadController on Java side to forward requests
+// for GET downloads to the current DownloadListener. POST downloads are
+// handled on the native side.
+//
+// Both classes are Singleton classes. C++ object owns Java object.
+//
+// Call sequence
+// GET downloads:
+// DownloadController::CreateGETDownload() =>
+// DownloadController.newHttpGetDownload() =>
+// DownloadListener.onDownloadStart() /
+// DownloadListener2.requestHttpGetDownload()
+//
+
+#ifndef CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_CONTROLLER_H_
+#define CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_CONTROLLER_H_
+
+#include "base/android/scoped_java_ref.h"
+#include "base/memory/singleton.h"
+#include "chrome/browser/android/download/download_controller_base.h"
+
+namespace net {
+class URLRequest;
+}
+
+namespace ui {
+class WindowAndroid;
+}
+
+namespace content {
+class WebContents;
+}
+
+class DownloadController : public DownloadControllerBase {
+ public:
+ static DownloadController* GetInstance();
+
+ static bool RegisterDownloadController(JNIEnv* env);
+
+ // Called when DownloadController Java object is instantiated.
+ void Init(JNIEnv* env, jobject obj);
+
+ // DownloadControllerBase implementation.
+ void AcquireFileAccessPermission(
+ content::WebContents* web_contents,
+ const AcquireFileAccessPermissionCallback& callback) override;
+ void SetDefaultDownloadFileName(const std::string& file_name) override;
+
+ // UMA histogram enum for download cancellation reasons. Keep this
+ // in sync with MobileDownloadCancelReason in histograms.xml. This should be
+ // append only.
+ enum DownloadCancelReason {
+ CANCEL_REASON_NOT_CANCELED = 0,
+ CANCEL_REASON_ACTION_BUTTON,
+ CANCEL_REASON_NOTIFICATION_DISMISSED,
+ CANCEL_REASON_OVERWRITE_INFOBAR_DISMISSED,
+ CANCEL_REASON_NO_STORAGE_PERMISSION,
+ CANCEL_REASON_MAX
+ };
+ static void RecordDownloadCancelReason(DownloadCancelReason reason);
+
+ private:
+ struct JavaObject;
+ friend struct base::DefaultSingletonTraits<DownloadController>;
+ DownloadController();
+ ~DownloadController() override;
+
+ // Helper method for implementing AcquireFileAccessPermission().
+ bool HasFileAccessPermission(ui::WindowAndroid* window_android);
+
+ // DownloadControllerBase implementation.
+ void CreateGETDownload(int render_process_id,
+ int render_view_id,
+ bool must_download,
+ const DownloadInfo& info) override;
+ void OnDownloadStarted(content::DownloadItem* download_item) override;
+ void StartContextMenuDownload(const content::ContextMenuParams& params,
+ content::WebContents* web_contents,
+ bool is_link,
+ const std::string& extra_headers) override;
+ void DangerousDownloadValidated(content::WebContents* web_contents,
+ const std::string& download_guid,
+ bool accept) override;
+
+ // DownloadItem::Observer interface.
+ void OnDownloadUpdated(content::DownloadItem* item) override;
+
+ void StartAndroidDownload(int render_process_id,
+ int render_view_id,
+ bool must_download,
+ const DownloadInfo& info);
+ void StartAndroidDownloadInternal(int render_process_id,
+ int render_view_id,
+ bool must_download,
+ const DownloadInfo& info,
+ bool allowed);
+
+ // The download item contains dangerous file types.
+ void OnDangerousDownload(content::DownloadItem *item);
+
+ base::android::ScopedJavaLocalRef<jobject> GetContentViewCoreFromWebContents(
+ content::WebContents* web_contents);
+
+ // Creates Java object if it is not created already and returns it.
+ JavaObject* GetJavaObject();
+
+ JavaObject* java_object_;
+
+ std::string default_file_name_;
+
+ DISALLOW_COPY_AND_ASSIGN(DownloadController);
+};
+
+#endif // CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_CONTROLLER_H_

Powered by Google App Engine
This is Rietveld 408576698