| 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 // |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 namespace content { | 26 namespace content { |
| 27 class WebContents; | 27 class WebContents; |
| 28 } | 28 } |
| 29 | 29 |
| 30 class DownloadController : public DownloadControllerBase { | 30 class DownloadController : public DownloadControllerBase { |
| 31 public: | 31 public: |
| 32 static DownloadController* GetInstance(); | 32 static DownloadController* GetInstance(); |
| 33 | 33 |
| 34 static bool RegisterDownloadController(JNIEnv* env); | 34 static bool RegisterDownloadController(JNIEnv* env); |
| 35 | 35 |
| 36 // Called when DownloadController Java object is instantiated. | |
| 37 void Init(JNIEnv* env, jobject obj); | |
| 38 | |
| 39 // DownloadControllerBase implementation. | 36 // DownloadControllerBase implementation. |
| 40 void AcquireFileAccessPermission( | 37 void AcquireFileAccessPermission( |
| 41 const content::ResourceRequestInfo::WebContentsGetter& wc_getter, | 38 const content::ResourceRequestInfo::WebContentsGetter& wc_getter, |
| 42 const AcquireFileAccessPermissionCallback& callback) override; | 39 const AcquireFileAccessPermissionCallback& callback) override; |
| 43 void CreateAndroidDownload( | 40 void CreateAndroidDownload( |
| 44 const content::ResourceRequestInfo::WebContentsGetter& wc_getter, | 41 const content::ResourceRequestInfo::WebContentsGetter& wc_getter, |
| 45 const DownloadInfo& info) override; | 42 const DownloadInfo& info) override; |
| 46 | 43 |
| 47 // UMA histogram enum for download cancellation reasons. Keep this | 44 // UMA histogram enum for download cancellation reasons. Keep this |
| 48 // in sync with MobileDownloadCancelReason in histograms.xml. This should be | 45 // in sync with MobileDownloadCancelReason in histograms.xml. This should be |
| (...skipping 11 matching lines...) Expand all Loading... |
| 60 CANCEL_REASON_MAX | 57 CANCEL_REASON_MAX |
| 61 }; | 58 }; |
| 62 static void RecordDownloadCancelReason(DownloadCancelReason reason); | 59 static void RecordDownloadCancelReason(DownloadCancelReason reason); |
| 63 | 60 |
| 64 // Callback when user permission prompt finishes. Args: whether file access | 61 // Callback when user permission prompt finishes. Args: whether file access |
| 65 // permission is acquired, which permission to update. | 62 // permission is acquired, which permission to update. |
| 66 typedef base::Callback<void(bool, const std::string&)> | 63 typedef base::Callback<void(bool, const std::string&)> |
| 67 AcquirePermissionCallback; | 64 AcquirePermissionCallback; |
| 68 | 65 |
| 69 private: | 66 private: |
| 70 struct JavaObject; | |
| 71 friend struct base::DefaultSingletonTraits<DownloadController>; | 67 friend struct base::DefaultSingletonTraits<DownloadController>; |
| 72 DownloadController(); | 68 DownloadController(); |
| 73 ~DownloadController() override; | 69 ~DownloadController() override; |
| 74 | 70 |
| 75 // Helper method for implementing AcquireFileAccessPermission(). | 71 // Helper method for implementing AcquireFileAccessPermission(). |
| 76 bool HasFileAccessPermission(); | 72 bool HasFileAccessPermission(); |
| 77 | 73 |
| 78 // DownloadControllerBase implementation. | 74 // DownloadControllerBase implementation. |
| 79 void OnDownloadStarted(content::DownloadItem* download_item) override; | 75 void OnDownloadStarted(content::DownloadItem* download_item) override; |
| 80 void StartContextMenuDownload(const content::ContextMenuParams& params, | 76 void StartContextMenuDownload(const content::ContextMenuParams& params, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 92 content::WebContents* web_contents); | 88 content::WebContents* web_contents); |
| 93 | 89 |
| 94 // Helper methods to start android download on UI thread. | 90 // Helper methods to start android download on UI thread. |
| 95 void StartAndroidDownload( | 91 void StartAndroidDownload( |
| 96 const content::ResourceRequestInfo::WebContentsGetter& wc_getter, | 92 const content::ResourceRequestInfo::WebContentsGetter& wc_getter, |
| 97 const DownloadInfo& info); | 93 const DownloadInfo& info); |
| 98 void StartAndroidDownloadInternal( | 94 void StartAndroidDownloadInternal( |
| 99 const content::ResourceRequestInfo::WebContentsGetter& wc_getter, | 95 const content::ResourceRequestInfo::WebContentsGetter& wc_getter, |
| 100 const DownloadInfo& info, bool allowed); | 96 const DownloadInfo& info, bool allowed); |
| 101 | 97 |
| 102 // Creates Java object if it is not created already and returns it. | |
| 103 JavaObject* GetJavaObject(); | |
| 104 | |
| 105 JavaObject* java_object_; | |
| 106 | |
| 107 std::string default_file_name_; | 98 std::string default_file_name_; |
| 108 | 99 |
| 109 DISALLOW_COPY_AND_ASSIGN(DownloadController); | 100 DISALLOW_COPY_AND_ASSIGN(DownloadController); |
| 110 }; | 101 }; |
| 111 | 102 |
| 112 #endif // CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_CONTROLLER_H_ | 103 #endif // CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_CONTROLLER_H_ |
| OLD | NEW |