| 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" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "chrome/browser/android/download/download_controller_base.h" |
| 12 #include "chrome/browser/download/download_service.h" | 13 #include "chrome/browser/download/download_service.h" |
| 13 #include "chrome/browser/download/download_service_factory.h" | 14 #include "chrome/browser/download/download_service_factory.h" |
| 14 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
| 15 #include "chrome/grit/generated_resources.h" | 16 #include "chrome/grit/generated_resources.h" |
| 16 #include "content/public/browser/android/download_controller_android.h" | |
| 17 #include "content/public/browser/browser_context.h" | 17 #include "content/public/browser/browser_context.h" |
| 18 #include "content/public/browser/download_item.h" | 18 #include "content/public/browser/download_item.h" |
| 19 #include "jni/DownloadManagerService_jni.h" | 19 #include "jni/DownloadManagerService_jni.h" |
| 20 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 21 | 21 |
| 22 using base::android::JavaParamRef; | 22 using base::android::JavaParamRef; |
| 23 using base::android::ConvertJavaStringToUTF8; | 23 using base::android::ConvertJavaStringToUTF8; |
| 24 using base::android::ConvertUTF8ToJavaString; | 24 using base::android::ConvertUTF8ToJavaString; |
| 25 | 25 |
| 26 // static | 26 // static |
| (...skipping 11 matching lines...) Expand all Loading... |
| 38 if (history) | 38 if (history) |
| 39 history->AddObserver(service); | 39 history->AddObserver(service); |
| 40 return reinterpret_cast<intptr_t>(service); | 40 return reinterpret_cast<intptr_t>(service); |
| 41 } | 41 } |
| 42 | 42 |
| 43 DownloadManagerService::DownloadManagerService( | 43 DownloadManagerService::DownloadManagerService( |
| 44 JNIEnv* env, | 44 JNIEnv* env, |
| 45 jobject obj) | 45 jobject obj) |
| 46 : java_ref_(env, obj), | 46 : java_ref_(env, obj), |
| 47 is_history_query_complete_(false) { | 47 is_history_query_complete_(false) { |
| 48 content::DownloadControllerAndroid::Get()->SetDefaultDownloadFileName( | 48 DownloadControllerBase::Get()->SetDefaultDownloadFileName( |
| 49 l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME)); | 49 l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME)); |
| 50 } | 50 } |
| 51 | 51 |
| 52 DownloadManagerService::~DownloadManagerService() {} | 52 DownloadManagerService::~DownloadManagerService() {} |
| 53 | 53 |
| 54 void DownloadManagerService::ResumeDownload( | 54 void DownloadManagerService::ResumeDownload( |
| 55 JNIEnv* env, | 55 JNIEnv* env, |
| 56 jobject obj, | 56 jobject obj, |
| 57 const JavaParamRef<jstring>& jdownload_guid) { | 57 const JavaParamRef<jstring>& jdownload_guid) { |
| 58 std::string download_guid = ConvertJavaStringToUTF8(env, jdownload_guid); | 58 std::string download_guid = ConvertJavaStringToUTF8(env, jdownload_guid); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 } | 125 } |
| 126 content::DownloadItem* item = manager->GetDownloadByGuid(download_guid); | 126 content::DownloadItem* item = manager->GetDownloadByGuid(download_guid); |
| 127 if (!item) { | 127 if (!item) { |
| 128 OnResumptionFailed(download_guid); | 128 OnResumptionFailed(download_guid); |
| 129 return; | 129 return; |
| 130 } | 130 } |
| 131 if (!item->CanResume()) { | 131 if (!item->CanResume()) { |
| 132 OnResumptionFailed(download_guid); | 132 OnResumptionFailed(download_guid); |
| 133 return; | 133 return; |
| 134 } | 134 } |
| 135 item->AddObserver(content::DownloadControllerAndroid::Get()); | 135 item->AddObserver(DownloadControllerBase::Get()); |
| 136 item->Resume(); | 136 item->Resume(); |
| 137 if (!resume_callback_for_testing_.is_null()) | 137 if (!resume_callback_for_testing_.is_null()) |
| 138 resume_callback_for_testing_.Run(true); | 138 resume_callback_for_testing_.Run(true); |
| 139 } | 139 } |
| 140 | 140 |
| 141 void DownloadManagerService::CancelDownloadInternal( | 141 void DownloadManagerService::CancelDownloadInternal( |
| 142 const std::string& download_guid, bool is_off_the_record) { | 142 const std::string& download_guid, bool is_off_the_record) { |
| 143 content::DownloadManager* manager = GetDownloadManager(is_off_the_record); | 143 content::DownloadManager* manager = GetDownloadManager(is_off_the_record); |
| 144 if (!manager) | 144 if (!manager) |
| 145 return; | 145 return; |
| 146 content::DownloadItem* item = manager->GetDownloadByGuid(download_guid); | 146 content::DownloadItem* item = manager->GetDownloadByGuid(download_guid); |
| 147 if (item) { | 147 if (item) { |
| 148 item->Cancel(true); | 148 item->Cancel(true); |
| 149 item->RemoveObserver(content::DownloadControllerAndroid::Get()); | 149 item->RemoveObserver(DownloadControllerBase::Get()); |
| 150 } | 150 } |
| 151 } | 151 } |
| 152 | 152 |
| 153 void DownloadManagerService::PauseDownloadInternal( | 153 void DownloadManagerService::PauseDownloadInternal( |
| 154 const std::string& download_guid) { | 154 const std::string& download_guid) { |
| 155 content::DownloadManager* manager = GetDownloadManager(false); | 155 content::DownloadManager* manager = GetDownloadManager(false); |
| 156 if (!manager) | 156 if (!manager) |
| 157 return; | 157 return; |
| 158 content::DownloadItem* item = manager->GetDownloadByGuid(download_guid); | 158 content::DownloadItem* item = manager->GetDownloadByGuid(download_guid); |
| 159 if (item) { | 159 if (item) { |
| 160 item->Pause(); | 160 item->Pause(); |
| 161 item->RemoveObserver(content::DownloadControllerAndroid::Get()); | 161 item->RemoveObserver(DownloadControllerBase::Get()); |
| 162 } | 162 } |
| 163 } | 163 } |
| 164 | 164 |
| 165 void DownloadManagerService::EnqueueDownloadAction( | 165 void DownloadManagerService::EnqueueDownloadAction( |
| 166 const std::string& download_guid, | 166 const std::string& download_guid, |
| 167 DownloadAction action) { | 167 DownloadAction action) { |
| 168 auto iter = pending_actions_.find(download_guid); | 168 auto iter = pending_actions_.find(download_guid); |
| 169 if (iter == pending_actions_.end()) { | 169 if (iter == pending_actions_.end()) { |
| 170 pending_actions_[download_guid] = action; | 170 pending_actions_[download_guid] = action; |
| 171 return; | 171 return; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 resume_callback_for_testing_.Run(false); | 207 resume_callback_for_testing_.Run(false); |
| 208 } | 208 } |
| 209 | 209 |
| 210 content::DownloadManager* DownloadManagerService::GetDownloadManager( | 210 content::DownloadManager* DownloadManagerService::GetDownloadManager( |
| 211 bool is_off_the_record) { | 211 bool is_off_the_record) { |
| 212 Profile* profile = ProfileManager::GetActiveUserProfile(); | 212 Profile* profile = ProfileManager::GetActiveUserProfile(); |
| 213 if (is_off_the_record) | 213 if (is_off_the_record) |
| 214 profile = profile->GetOffTheRecordProfile(); | 214 profile = profile->GetOffTheRecordProfile(); |
| 215 return content::BrowserContext::GetDownloadManager(profile); | 215 return content::BrowserContext::GetDownloadManager(profile); |
| 216 } | 216 } |
| OLD | NEW |