| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_MANAGER_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_MANAGER_SERVICE_H_ |
| 6 #define CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_MANAGER_SERVICE_H_ | 6 #define CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_MANAGER_SERVICE_H_ |
| 7 | 7 |
| 8 #include <jni.h> | 8 #include <jni.h> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/android/scoped_java_ref.h" | 12 #include "base/android/scoped_java_ref.h" |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/files/file_path.h" |
| 14 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/singleton.h" |
| 15 #include "chrome/browser/android/download/download_controller.h" | 17 #include "chrome/browser/android/download/download_controller.h" |
| 16 #include "chrome/browser/download/all_download_item_notifier.h" | 18 #include "chrome/browser/download/all_download_item_notifier.h" |
| 17 #include "chrome/browser/download/download_history.h" | 19 #include "chrome/browser/download/download_history.h" |
| 18 #include "content/public/browser/download_manager.h" | 20 #include "content/public/browser/download_manager.h" |
| 19 | 21 |
| 20 using base::android::JavaParamRef; | 22 using base::android::JavaParamRef; |
| 21 | 23 |
| 22 namespace content { | 24 namespace content { |
| 23 class DownloadItem; | 25 class DownloadItem; |
| 24 } | 26 } |
| 25 | 27 |
| 26 // Native side of DownloadManagerService.java. The native object is owned by its | 28 // Native side of DownloadManagerService.java. The native object is owned by its |
| 27 // Java object. | 29 // Java object. |
| 28 class DownloadManagerService : public AllDownloadItemNotifier::Observer, | 30 class DownloadManagerService : public AllDownloadItemNotifier::Observer, |
| 29 public DownloadHistory::Observer { | 31 public DownloadHistory::Observer { |
| 30 public: | 32 public: |
| 31 // JNI registration. | 33 // JNI registration. |
| 32 static bool RegisterDownloadManagerService(JNIEnv* env); | 34 static bool RegisterDownloadManagerService(JNIEnv* env); |
| 33 | 35 |
| 34 static void OnDownloadCanceled( | 36 static void OnDownloadCanceled( |
| 35 content::DownloadItem* download, | 37 content::DownloadItem* download, |
| 36 DownloadController::DownloadCancelReason reason); | 38 DownloadController::DownloadCancelReason reason); |
| 37 | 39 |
| 38 DownloadManagerService(JNIEnv* env, | 40 static DownloadManagerService* GetInstance(); |
| 39 jobject jobj); | 41 |
| 42 DownloadManagerService(); |
| 40 ~DownloadManagerService() override; | 43 ~DownloadManagerService() override; |
| 41 | 44 |
| 45 // Called to Initialize this object. |
| 46 void Init(JNIEnv* env, jobject obj); |
| 47 |
| 42 // Called to resume downloading the item that has GUID equal to | 48 // Called to resume downloading the item that has GUID equal to |
| 43 // |jdownload_guid|.. | 49 // |jdownload_guid|.. |
| 44 void ResumeDownload(JNIEnv* env, | 50 void ResumeDownload(JNIEnv* env, |
| 45 jobject obj, | 51 jobject obj, |
| 46 const JavaParamRef<jstring>& jdownload_guid, | 52 const JavaParamRef<jstring>& jdownload_guid, |
| 47 bool is_off_the_record); | 53 bool is_off_the_record); |
| 48 | 54 |
| 49 // Called to cancel a download item that has GUID equal to |jdownload_guid|. | 55 // Called to cancel a download item that has GUID equal to |jdownload_guid|. |
| 50 // If the DownloadItem is not yet created, retry after a while. | 56 // If the DownloadItem is not yet created, retry after a while. |
| 51 void CancelDownload(JNIEnv* env, | 57 void CancelDownload(JNIEnv* env, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 72 void GetAllDownloads(JNIEnv* env, | 78 void GetAllDownloads(JNIEnv* env, |
| 73 const JavaParamRef<jobject>& obj, | 79 const JavaParamRef<jobject>& obj, |
| 74 bool is_off_the_record); | 80 bool is_off_the_record); |
| 75 | 81 |
| 76 // Called to check if the files associated with any downloads have been | 82 // Called to check if the files associated with any downloads have been |
| 77 // removed by an external action. | 83 // removed by an external action. |
| 78 void CheckForExternallyRemovedDownloads(JNIEnv* env, | 84 void CheckForExternallyRemovedDownloads(JNIEnv* env, |
| 79 const JavaParamRef<jobject>& obj, | 85 const JavaParamRef<jobject>& obj, |
| 80 bool is_off_the_record); | 86 bool is_off_the_record); |
| 81 | 87 |
| 88 // Remove download items associated with |path| from downloads history. |
| 89 void RemoveDownloadsForPath(const base::FilePath& path); |
| 90 |
| 82 // DownloadHistory::Observer methods. | 91 // DownloadHistory::Observer methods. |
| 83 void OnHistoryQueryComplete() override; | 92 void OnHistoryQueryComplete() override; |
| 84 | 93 |
| 85 // AllDownloadItemNotifier::Observer methods. | 94 // AllDownloadItemNotifier::Observer methods. |
| 86 void OnDownloadUpdated(content::DownloadManager* manager, | 95 void OnDownloadUpdated(content::DownloadManager* manager, |
| 87 content::DownloadItem* item) override; | 96 content::DownloadItem* item) override; |
| 88 void OnDownloadRemoved(content::DownloadManager* manager, | 97 void OnDownloadRemoved(content::DownloadManager* manager, |
| 89 content::DownloadItem* item) override; | 98 content::DownloadItem* item) override; |
| 90 | 99 |
| 91 protected: | 100 protected: |
| 92 // Called to get the content::DownloadManager instance. | 101 // Called to get the content::DownloadManager instance. |
| 93 virtual content::DownloadManager* GetDownloadManager(bool is_off_the_record); | 102 virtual content::DownloadManager* GetDownloadManager(bool is_off_the_record); |
| 94 | 103 |
| 95 private: | 104 private: |
| 96 // For testing. | 105 // For testing. |
| 97 friend class DownloadManagerServiceTest; | 106 friend class DownloadManagerServiceTest; |
| 107 friend struct base::DefaultSingletonTraits<DownloadManagerService>; |
| 98 | 108 |
| 99 // Helper function to start the download resumption. | 109 // Helper function to start the download resumption. |
| 100 void ResumeDownloadInternal(const std::string& download_guid, | 110 void ResumeDownloadInternal(const std::string& download_guid, |
| 101 bool is_off_the_record); | 111 bool is_off_the_record); |
| 102 | 112 |
| 103 // Helper function to cancel a download. | 113 // Helper function to cancel a download. |
| 104 void CancelDownloadInternal(const std::string& download_guid, | 114 void CancelDownloadInternal(const std::string& download_guid, |
| 105 bool is_off_the_record); | 115 bool is_off_the_record); |
| 106 | 116 |
| 107 // Helper function to pause a download. | 117 // Helper function to pause a download. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 | 162 |
| 153 ResumeCallback resume_callback_for_testing_; | 163 ResumeCallback resume_callback_for_testing_; |
| 154 | 164 |
| 155 std::unique_ptr<AllDownloadItemNotifier> original_notifier_; | 165 std::unique_ptr<AllDownloadItemNotifier> original_notifier_; |
| 156 std::unique_ptr<AllDownloadItemNotifier> off_the_record_notifier_; | 166 std::unique_ptr<AllDownloadItemNotifier> off_the_record_notifier_; |
| 157 | 167 |
| 158 DISALLOW_COPY_AND_ASSIGN(DownloadManagerService); | 168 DISALLOW_COPY_AND_ASSIGN(DownloadManagerService); |
| 159 }; | 169 }; |
| 160 | 170 |
| 161 #endif // CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_MANAGER_SERVICE_H_ | 171 #endif // CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_MANAGER_SERVICE_H_ |
| OLD | NEW |