| 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 #include "chrome/browser/android/download/download_manager_service.h" | 5 #include "chrome/browser/android/download/download_manager_service.h" |
| 6 | 6 |
| 7 #include "base/android/jni_string.h" | 7 #include "base/android/jni_string.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 is_history_query_complete_(false) { | 72 is_history_query_complete_(false) { |
| 73 DownloadControllerBase::Get()->SetDefaultDownloadFileName( | 73 DownloadControllerBase::Get()->SetDefaultDownloadFileName( |
| 74 l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME)); | 74 l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME)); |
| 75 } | 75 } |
| 76 | 76 |
| 77 DownloadManagerService::~DownloadManagerService() {} | 77 DownloadManagerService::~DownloadManagerService() {} |
| 78 | 78 |
| 79 void DownloadManagerService::ResumeDownload( | 79 void DownloadManagerService::ResumeDownload( |
| 80 JNIEnv* env, | 80 JNIEnv* env, |
| 81 jobject obj, | 81 jobject obj, |
| 82 const JavaParamRef<jstring>& jdownload_guid) { | 82 const JavaParamRef<jstring>& jdownload_guid, |
| 83 bool is_off_the_record) { |
| 83 std::string download_guid = ConvertJavaStringToUTF8(env, jdownload_guid); | 84 std::string download_guid = ConvertJavaStringToUTF8(env, jdownload_guid); |
| 84 if (is_history_query_complete_) | 85 if (is_history_query_complete_ || is_off_the_record) |
| 85 ResumeDownloadInternal(download_guid); | 86 ResumeDownloadInternal(download_guid, is_off_the_record); |
| 86 else | 87 else |
| 87 EnqueueDownloadAction(download_guid, RESUME); | 88 EnqueueDownloadAction(download_guid, RESUME); |
| 88 } | 89 } |
| 89 | 90 |
| 90 void DownloadManagerService::PauseDownload( | 91 void DownloadManagerService::PauseDownload( |
| 91 JNIEnv* env, | 92 JNIEnv* env, |
| 92 jobject obj, | 93 jobject obj, |
| 93 const JavaParamRef<jstring>& jdownload_guid) { | 94 const JavaParamRef<jstring>& jdownload_guid, |
| 95 bool is_off_the_record) { |
| 94 std::string download_guid = ConvertJavaStringToUTF8(env, jdownload_guid); | 96 std::string download_guid = ConvertJavaStringToUTF8(env, jdownload_guid); |
| 95 if (is_history_query_complete_) | 97 if (is_history_query_complete_ || is_off_the_record) |
| 96 PauseDownloadInternal(download_guid); | 98 PauseDownloadInternal(download_guid, is_off_the_record); |
| 97 else | 99 else |
| 98 EnqueueDownloadAction(download_guid, PAUSE); | 100 EnqueueDownloadAction(download_guid, PAUSE); |
| 99 } | 101 } |
| 100 | 102 |
| 101 void DownloadManagerService::GetAllDownloads(JNIEnv* env, | 103 void DownloadManagerService::GetAllDownloads(JNIEnv* env, |
| 102 const JavaParamRef<jobject>& obj) { | 104 const JavaParamRef<jobject>& obj) { |
| 103 if (is_history_query_complete_) | 105 if (is_history_query_complete_) |
| 104 GetAllDownloadsInternal(); | 106 GetAllDownloadsInternal(); |
| 105 else | 107 else |
| 106 EnqueueDownloadAction(std::string(), INITIALIZE_UI); | 108 EnqueueDownloadAction(std::string(), INITIALIZE_UI); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 } | 144 } |
| 143 | 145 |
| 144 | 146 |
| 145 void DownloadManagerService::CancelDownload( | 147 void DownloadManagerService::CancelDownload( |
| 146 JNIEnv* env, | 148 JNIEnv* env, |
| 147 jobject obj, | 149 jobject obj, |
| 148 const JavaParamRef<jstring>& jdownload_guid, | 150 const JavaParamRef<jstring>& jdownload_guid, |
| 149 bool is_off_the_record, | 151 bool is_off_the_record, |
| 150 bool is_notification_dismissed) { | 152 bool is_notification_dismissed) { |
| 151 std::string download_guid = ConvertJavaStringToUTF8(env, jdownload_guid); | 153 std::string download_guid = ConvertJavaStringToUTF8(env, jdownload_guid); |
| 152 | |
| 153 DownloadController::RecordDownloadCancelReason( | 154 DownloadController::RecordDownloadCancelReason( |
| 154 is_notification_dismissed ? | 155 is_notification_dismissed ? |
| 155 DownloadController::CANCEL_REASON_NOTIFICATION_DISMISSED : | 156 DownloadController::CANCEL_REASON_NOTIFICATION_DISMISSED : |
| 156 DownloadController::CANCEL_REASON_ACTION_BUTTON); | 157 DownloadController::CANCEL_REASON_ACTION_BUTTON); |
| 157 // Incognito download can only be cancelled in the same browser session, no | 158 if (is_history_query_complete_ || is_off_the_record) |
| 158 // need to wait for download history. | 159 CancelDownloadInternal(download_guid, is_off_the_record); |
| 159 if (is_off_the_record) { | |
| 160 CancelDownloadInternal(download_guid, true); | |
| 161 return; | |
| 162 } | |
| 163 | |
| 164 if (is_history_query_complete_) | |
| 165 CancelDownloadInternal(download_guid, false); | |
| 166 else | 160 else |
| 167 EnqueueDownloadAction(download_guid, CANCEL); | 161 EnqueueDownloadAction(download_guid, CANCEL); |
| 168 } | 162 } |
| 169 | 163 |
| 170 void DownloadManagerService::OnHistoryQueryComplete() { | 164 void DownloadManagerService::OnHistoryQueryComplete() { |
| 171 is_history_query_complete_ = true; | 165 is_history_query_complete_ = true; |
| 172 for (auto iter = pending_actions_.begin(); iter != pending_actions_.end(); | 166 for (auto iter = pending_actions_.begin(); iter != pending_actions_.end(); |
| 173 ++iter) { | 167 ++iter) { |
| 174 DownloadAction action = iter->second; | 168 DownloadAction action = iter->second; |
| 175 std::string download_guid = iter->first; | 169 std::string download_guid = iter->first; |
| 176 switch (action) { | 170 switch (action) { |
| 177 case RESUME: | 171 case RESUME: |
| 178 ResumeDownloadInternal(download_guid); | 172 ResumeDownloadInternal(download_guid, false); |
| 179 break; | 173 break; |
| 180 case PAUSE: | 174 case PAUSE: |
| 181 PauseDownloadInternal(download_guid); | 175 PauseDownloadInternal(download_guid, false); |
| 182 break; | 176 break; |
| 183 case CANCEL: | 177 case CANCEL: |
| 184 CancelDownloadInternal(download_guid, false); | 178 CancelDownloadInternal(download_guid, false); |
| 185 break; | 179 break; |
| 186 case INITIALIZE_UI: | 180 case INITIALIZE_UI: |
| 187 GetAllDownloadsInternal(); | 181 GetAllDownloadsInternal(); |
| 188 break; | 182 break; |
| 189 default: | 183 default: |
| 190 NOTREACHED(); | 184 NOTREACHED(); |
| 191 break; | 185 break; |
| 192 } | 186 } |
| 193 } | 187 } |
| 194 pending_actions_.clear(); | 188 pending_actions_.clear(); |
| 195 } | 189 } |
| 196 | 190 |
| 197 void DownloadManagerService::ResumeDownloadInternal( | 191 void DownloadManagerService::ResumeDownloadInternal( |
| 198 const std::string& download_guid) { | 192 const std::string& download_guid, bool is_off_the_record) { |
| 199 content::DownloadManager* manager = GetDownloadManager(false); | 193 content::DownloadManager* manager = GetDownloadManager(is_off_the_record); |
| 200 if (!manager) { | 194 if (!manager) { |
| 201 OnResumptionFailed(download_guid); | 195 OnResumptionFailed(download_guid); |
| 202 return; | 196 return; |
| 203 } | 197 } |
| 204 content::DownloadItem* item = manager->GetDownloadByGuid(download_guid); | 198 content::DownloadItem* item = manager->GetDownloadByGuid(download_guid); |
| 205 if (!item) { | 199 if (!item) { |
| 206 OnResumptionFailed(download_guid); | 200 OnResumptionFailed(download_guid); |
| 207 return; | 201 return; |
| 208 } | 202 } |
| 209 if (!item->CanResume()) { | 203 if (!item->CanResume()) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 222 if (!manager) | 216 if (!manager) |
| 223 return; | 217 return; |
| 224 content::DownloadItem* item = manager->GetDownloadByGuid(download_guid); | 218 content::DownloadItem* item = manager->GetDownloadByGuid(download_guid); |
| 225 if (item) { | 219 if (item) { |
| 226 item->Cancel(true); | 220 item->Cancel(true); |
| 227 item->RemoveObserver(DownloadControllerBase::Get()); | 221 item->RemoveObserver(DownloadControllerBase::Get()); |
| 228 } | 222 } |
| 229 } | 223 } |
| 230 | 224 |
| 231 void DownloadManagerService::PauseDownloadInternal( | 225 void DownloadManagerService::PauseDownloadInternal( |
| 232 const std::string& download_guid) { | 226 const std::string& download_guid, bool is_off_the_record) { |
| 233 content::DownloadManager* manager = GetDownloadManager(false); | 227 content::DownloadManager* manager = GetDownloadManager(is_off_the_record); |
| 234 if (!manager) | 228 if (!manager) |
| 235 return; | 229 return; |
| 236 content::DownloadItem* item = manager->GetDownloadByGuid(download_guid); | 230 content::DownloadItem* item = manager->GetDownloadByGuid(download_guid); |
| 237 if (item) { | 231 if (item) { |
| 238 item->Pause(); | 232 item->Pause(); |
| 239 item->RemoveObserver(DownloadControllerBase::Get()); | 233 item->RemoveObserver(DownloadControllerBase::Get()); |
| 240 } | 234 } |
| 241 } | 235 } |
| 242 | 236 |
| 243 void DownloadManagerService::EnqueueDownloadAction( | 237 void DownloadManagerService::EnqueueDownloadAction( |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 resume_callback_for_testing_.Run(false); | 284 resume_callback_for_testing_.Run(false); |
| 291 } | 285 } |
| 292 | 286 |
| 293 content::DownloadManager* DownloadManagerService::GetDownloadManager( | 287 content::DownloadManager* DownloadManagerService::GetDownloadManager( |
| 294 bool is_off_the_record) { | 288 bool is_off_the_record) { |
| 295 Profile* profile = ProfileManager::GetActiveUserProfile(); | 289 Profile* profile = ProfileManager::GetActiveUserProfile(); |
| 296 if (is_off_the_record) | 290 if (is_off_the_record) |
| 297 profile = profile->GetOffTheRecordProfile(); | 291 profile = profile->GetOffTheRecordProfile(); |
| 298 return content::BrowserContext::GetDownloadManager(profile); | 292 return content::BrowserContext::GetDownloadManager(profile); |
| 299 } | 293 } |
| OLD | NEW |