| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 // This class pairs with DownloadController on Java side to forward requests | 5 // This class pairs with DownloadController on Java side to forward requests |
| 6 // for GET downloads to the current DownloadListener. POST downloads are | 6 // for GET downloads to the current DownloadListener. POST downloads are |
| 7 // handled on the native side. | 7 // handled on the native side. |
| 8 // | 8 // |
| 9 // Both classes are Singleton classes. C++ object owns Java object. | 9 // Both classes are Singleton classes. C++ object owns Java object. |
| 10 // | 10 // |
| 11 // Call sequence | 11 // Call sequence |
| 12 // GET downloads: | 12 // GET downloads: |
| 13 // DownloadController::CreateGETDownload() => | 13 // DownloadController::CreateGETDownload() => |
| 14 // DownloadController.newHttpGetDownload() => | 14 // DownloadController.newHttpGetDownload() => |
| 15 // DownloadListener.onDownloadStart() / | 15 // DownloadListener.onDownloadStart() / |
| 16 // DownloadListener2.requestHttpGetDownload() | 16 // DownloadListener2.requestHttpGetDownload() |
| 17 // | 17 // |
| 18 | 18 |
| 19 #ifndef CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_CONTROLLER_H_ | 19 #ifndef CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_CONTROLLER_H_ |
| 20 #define CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_CONTROLLER_H_ | 20 #define CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_CONTROLLER_H_ |
| 21 | 21 |
| 22 #include "base/android/scoped_java_ref.h" | 22 #include "base/android/scoped_java_ref.h" |
| 23 #include "base/memory/singleton.h" | 23 #include "base/memory/singleton.h" |
| 24 #include "chrome/browser/android/download/download_controller_base.h" | 24 #include "chrome/browser/android/download/download_controller_base.h" |
| 25 | 25 |
| 26 namespace ui { | |
| 27 class WindowAndroid; | |
| 28 } | |
| 29 | |
| 30 namespace content { | 26 namespace content { |
| 31 class WebContents; | 27 class WebContents; |
| 32 } | 28 } |
| 33 | 29 |
| 34 class DownloadController : public DownloadControllerBase { | 30 class DownloadController : public DownloadControllerBase { |
| 35 public: | 31 public: |
| 36 static DownloadController* GetInstance(); | 32 static DownloadController* GetInstance(); |
| 37 | 33 |
| 38 static bool RegisterDownloadController(JNIEnv* env); | 34 static bool RegisterDownloadController(JNIEnv* env); |
| 39 | 35 |
| 40 // Called when DownloadController Java object is instantiated. | 36 // Called when DownloadController Java object is instantiated. |
| 41 void Init(JNIEnv* env, jobject obj); | 37 void Init(JNIEnv* env, jobject obj); |
| 42 | 38 |
| 43 // DownloadControllerBase implementation. | 39 // DownloadControllerBase implementation. |
| 44 void AcquireFileAccessPermission( | 40 void AcquireFileAccessPermission( |
| 45 content::WebContents* web_contents, | 41 const content::ResourceRequestInfo::WebContentsGetter& wc_getter, |
| 46 const AcquireFileAccessPermissionCallback& callback) override; | 42 const AcquireFileAccessPermissionCallback& callback) override; |
| 47 void CreateAndroidDownload( | 43 void CreateAndroidDownload( |
| 48 const content::ResourceRequestInfo::WebContentsGetter& wc_getter, | 44 const content::ResourceRequestInfo::WebContentsGetter& wc_getter, |
| 49 const DownloadInfo& info) override; | 45 const DownloadInfo& info) override; |
| 50 | 46 |
| 51 // UMA histogram enum for download cancellation reasons. Keep this | 47 // UMA histogram enum for download cancellation reasons. Keep this |
| 52 // in sync with MobileDownloadCancelReason in histograms.xml. This should be | 48 // in sync with MobileDownloadCancelReason in histograms.xml. This should be |
| 53 // append only. | 49 // append only. |
| 54 enum DownloadCancelReason { | 50 enum DownloadCancelReason { |
| 55 CANCEL_REASON_NOT_CANCELED = 0, | 51 CANCEL_REASON_NOT_CANCELED = 0, |
| 56 CANCEL_REASON_ACTION_BUTTON, | 52 CANCEL_REASON_ACTION_BUTTON, |
| 57 CANCEL_REASON_NOTIFICATION_DISMISSED, | 53 CANCEL_REASON_NOTIFICATION_DISMISSED, |
| 58 CANCEL_REASON_OVERWRITE_INFOBAR_DISMISSED, | 54 CANCEL_REASON_OVERWRITE_INFOBAR_DISMISSED, |
| 59 CANCEL_REASON_NO_STORAGE_PERMISSION, | 55 CANCEL_REASON_NO_STORAGE_PERMISSION, |
| 60 CANCEL_REASON_DANGEROUS_DOWNLOAD_INFOBAR_DISMISSED, | 56 CANCEL_REASON_DANGEROUS_DOWNLOAD_INFOBAR_DISMISSED, |
| 61 CANCEL_REASON_NO_EXTERNAL_STORAGE, | 57 CANCEL_REASON_NO_EXTERNAL_STORAGE, |
| 62 CANCEL_REASON_CANNOT_DETERMINE_DOWNLOAD_TARGET, | 58 CANCEL_REASON_CANNOT_DETERMINE_DOWNLOAD_TARGET, |
| 63 CANCEL_REASON_OTHER_NATIVE_RESONS, | 59 CANCEL_REASON_OTHER_NATIVE_RESONS, |
| 64 CANCEL_REASON_MAX | 60 CANCEL_REASON_MAX |
| 65 }; | 61 }; |
| 66 static void RecordDownloadCancelReason(DownloadCancelReason reason); | 62 static void RecordDownloadCancelReason(DownloadCancelReason reason); |
| 67 | 63 |
| 64 // Callback when user permission prompt finishes. Args: whether file access |
| 65 // permission is acquired, which permission to update. |
| 66 typedef base::Callback<void(bool, const std::string&)> |
| 67 AcquirePermissionCallback; |
| 68 |
| 68 private: | 69 private: |
| 69 struct JavaObject; | 70 struct JavaObject; |
| 70 friend struct base::DefaultSingletonTraits<DownloadController>; | 71 friend struct base::DefaultSingletonTraits<DownloadController>; |
| 71 DownloadController(); | 72 DownloadController(); |
| 72 ~DownloadController() override; | 73 ~DownloadController() override; |
| 73 | 74 |
| 74 // Helper method for implementing AcquireFileAccessPermission(). | 75 // Helper method for implementing AcquireFileAccessPermission(). |
| 75 bool HasFileAccessPermission(ui::WindowAndroid* window_android); | 76 bool HasFileAccessPermission(); |
| 76 | 77 |
| 77 // DownloadControllerBase implementation. | 78 // DownloadControllerBase implementation. |
| 78 void OnDownloadStarted(content::DownloadItem* download_item) override; | 79 void OnDownloadStarted(content::DownloadItem* download_item) override; |
| 79 void StartContextMenuDownload(const content::ContextMenuParams& params, | 80 void StartContextMenuDownload(const content::ContextMenuParams& params, |
| 80 content::WebContents* web_contents, | 81 content::WebContents* web_contents, |
| 81 bool is_link, | 82 bool is_link, |
| 82 const std::string& extra_headers) override; | 83 const std::string& extra_headers) override; |
| 83 | 84 |
| 84 // DownloadItem::Observer interface. | 85 // DownloadItem::Observer interface. |
| 85 void OnDownloadUpdated(content::DownloadItem* item) override; | 86 void OnDownloadUpdated(content::DownloadItem* item) override; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 102 JavaObject* GetJavaObject(); | 103 JavaObject* GetJavaObject(); |
| 103 | 104 |
| 104 JavaObject* java_object_; | 105 JavaObject* java_object_; |
| 105 | 106 |
| 106 std::string default_file_name_; | 107 std::string default_file_name_; |
| 107 | 108 |
| 108 DISALLOW_COPY_AND_ASSIGN(DownloadController); | 109 DISALLOW_COPY_AND_ASSIGN(DownloadController); |
| 109 }; | 110 }; |
| 110 | 111 |
| 111 #endif // CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_CONTROLLER_H_ | 112 #endif // CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_CONTROLLER_H_ |
| OLD | NEW |