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> |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 jobject obj, | 60 jobject obj, |
61 const JavaParamRef<jstring>& jdownload_guid, | 61 const JavaParamRef<jstring>& jdownload_guid, |
62 bool is_off_the_record); | 62 bool is_off_the_record); |
63 | 63 |
64 // Called to remove a download item that has GUID equal to |jdownload_guid|. | 64 // Called to remove a download item that has GUID equal to |jdownload_guid|. |
65 void RemoveDownload(JNIEnv* env, | 65 void RemoveDownload(JNIEnv* env, |
66 jobject obj, | 66 jobject obj, |
67 const JavaParamRef<jstring>& jdownload_guid, | 67 const JavaParamRef<jstring>& jdownload_guid, |
68 bool is_off_the_record); | 68 bool is_off_the_record); |
69 | 69 |
70 // Returns information about the item that has GUID equal to |jdownload_guid|. | |
71 void GetDownloadInfoFor(JNIEnv* env, | |
72 jobject obj, | |
73 const JavaParamRef<jstring>& jdownload_guid, | |
74 bool is_off_the_record); | |
75 | |
76 // Called to request that the DownloadManagerService return data about all | 70 // Called to request that the DownloadManagerService return data about all |
77 // downloads in the user's history. | 71 // downloads in the user's history. |
78 void GetAllDownloads(JNIEnv* env, const JavaParamRef<jobject>& obj); | 72 void GetAllDownloads(JNIEnv* env, |
| 73 const JavaParamRef<jobject>& obj, |
| 74 bool is_off_the_record); |
79 | 75 |
80 // DownloadHistory::Observer methods. | 76 // DownloadHistory::Observer methods. |
81 void OnHistoryQueryComplete() override; | 77 void OnHistoryQueryComplete() override; |
82 | 78 |
83 // AllDownloadItemNotifier::Observer methods. | 79 // AllDownloadItemNotifier::Observer methods. |
84 void OnDownloadRemoved( | 80 void OnDownloadUpdated(content::DownloadManager* manager, |
85 content::DownloadManager* manager, content::DownloadItem* item) override; | 81 content::DownloadItem* item) override; |
| 82 void OnDownloadRemoved(content::DownloadManager* manager, |
| 83 content::DownloadItem* item) override; |
86 | 84 |
87 protected: | 85 protected: |
88 // Called to get the content::DownloadManager instance. | 86 // Called to get the content::DownloadManager instance. |
89 virtual content::DownloadManager* GetDownloadManager(bool is_off_the_record); | 87 virtual content::DownloadManager* GetDownloadManager(bool is_off_the_record); |
90 | 88 |
91 private: | 89 private: |
92 // For testing. | 90 // For testing. |
93 friend class DownloadManagerServiceTest; | 91 friend class DownloadManagerServiceTest; |
94 | 92 |
95 // Helper function to start the download resumption. | 93 // Helper function to start the download resumption. |
96 void ResumeDownloadInternal(const std::string& download_guid, | 94 void ResumeDownloadInternal(const std::string& download_guid, |
97 bool is_off_the_record); | 95 bool is_off_the_record); |
98 | 96 |
99 // Helper function to cancel a download. | 97 // Helper function to cancel a download. |
100 void CancelDownloadInternal(const std::string& download_guid, | 98 void CancelDownloadInternal(const std::string& download_guid, |
101 bool is_off_the_record); | 99 bool is_off_the_record); |
102 | 100 |
103 // Helper function to pause a download. | 101 // Helper function to pause a download. |
104 void PauseDownloadInternal(const std::string& download_guid, | 102 void PauseDownloadInternal(const std::string& download_guid, |
105 bool is_off_the_record); | 103 bool is_off_the_record); |
106 | 104 |
107 // Helper function to remove a download. | 105 // Helper function to remove a download. |
108 void RemoveDownloadInternal(const std::string& download_guid, | 106 void RemoveDownloadInternal(const std::string& download_guid, |
109 bool is_off_the_record); | 107 bool is_off_the_record); |
110 | 108 |
111 // Helper function to send info about all downloads to the Java-side. | 109 // Helper function to send info about all downloads to the Java-side. |
112 void GetAllDownloadsInternal(); | 110 void GetAllDownloadsInternal(bool is_off_the_record); |
113 | 111 |
114 // Called to notify the java side that download resumption failed. | 112 // Called to notify the java side that download resumption failed. |
115 void OnResumptionFailed(const std::string& download_guid); | 113 void OnResumptionFailed(const std::string& download_guid); |
116 | 114 |
117 void OnResumptionFailedInternal(const std::string& download_guid); | 115 void OnResumptionFailedInternal(const std::string& download_guid); |
118 | 116 |
119 typedef base::Callback<void(bool)> ResumeCallback; | 117 typedef base::Callback<void(bool)> ResumeCallback; |
120 void set_resume_callback_for_testing(const ResumeCallback& resume_cb) { | 118 void set_resume_callback_for_testing(const ResumeCallback& resume_cb) { |
121 resume_callback_for_testing_ = resume_cb; | 119 resume_callback_for_testing_ = resume_cb; |
122 } | 120 } |
123 | 121 |
124 // Reference to the Java object. | 122 // Reference to the Java object. |
125 base::android::ScopedJavaGlobalRef<jobject> java_ref_; | 123 base::android::ScopedJavaGlobalRef<jobject> java_ref_; |
126 | 124 |
127 bool is_history_query_complete_; | 125 bool is_history_query_complete_; |
128 | 126 |
129 enum DownloadAction { RESUME, PAUSE, CANCEL, REMOVE, INITIALIZE_UI, UNKNOWN }; | 127 enum DownloadAction { |
| 128 RESUME, |
| 129 PAUSE, |
| 130 CANCEL, |
| 131 REMOVE, |
| 132 INITIALIZE_UI, |
| 133 INITIALIZE_OFF_THE_RECORD_UI, |
| 134 UNKNOWN }; |
130 | 135 |
131 using PendingDownloadActions = std::map<std::string, DownloadAction>; | 136 using PendingDownloadActions = std::map<std::string, DownloadAction>; |
132 PendingDownloadActions pending_actions_; | 137 PendingDownloadActions pending_actions_; |
133 | 138 |
134 void EnqueueDownloadAction(const std::string& download_guid, | 139 void EnqueueDownloadAction(const std::string& download_guid, |
135 DownloadAction action); | 140 DownloadAction action); |
136 | 141 |
137 ResumeCallback resume_callback_for_testing_; | 142 ResumeCallback resume_callback_for_testing_; |
138 | 143 |
139 std::unique_ptr<AllDownloadItemNotifier> original_notifier_; | 144 std::unique_ptr<AllDownloadItemNotifier> original_notifier_; |
| 145 std::unique_ptr<AllDownloadItemNotifier> off_the_record_notifier_; |
140 | 146 |
141 DISALLOW_COPY_AND_ASSIGN(DownloadManagerService); | 147 DISALLOW_COPY_AND_ASSIGN(DownloadManagerService); |
142 }; | 148 }; |
143 | 149 |
144 #endif // CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_MANAGER_SERVICE_H_ | 150 #endif // CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_MANAGER_SERVICE_H_ |
OLD | NEW |