| 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 20 matching lines...) Expand all Loading... |
| 31 !item->GetTargetFilePath().empty(); | 31 !item->GetTargetFilePath().empty(); |
| 32 } | 32 } |
| 33 | 33 |
| 34 } // namespace | 34 } // namespace |
| 35 | 35 |
| 36 // static | 36 // static |
| 37 bool DownloadManagerService::RegisterDownloadManagerService(JNIEnv* env) { | 37 bool DownloadManagerService::RegisterDownloadManagerService(JNIEnv* env) { |
| 38 return RegisterNativesImpl(env); | 38 return RegisterNativesImpl(env); |
| 39 } | 39 } |
| 40 | 40 |
| 41 // static |
| 42 void DownloadManagerService::OnDownloadCanceled( |
| 43 content::DownloadItem* download, |
| 44 DownloadController::DownloadCancelReason reason) { |
| 45 bool has_no_external_storage = |
| 46 (reason == DownloadController::CANCEL_REASON_NO_EXTERNAL_STORAGE); |
| 47 JNIEnv* env = base::android::AttachCurrentThread(); |
| 48 ScopedJavaLocalRef<jstring> jname = |
| 49 ConvertUTF8ToJavaString(env, download->GetURL().ExtractFileName()); |
| 50 Java_DownloadManagerService_onDownloadItemCanceled( |
| 51 env, jname.obj(), has_no_external_storage); |
| 52 DownloadController::RecordDownloadCancelReason(reason); |
| 53 } |
| 54 |
| 55 |
| 41 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& jobj) { | 56 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& jobj) { |
| 42 Profile* profile = ProfileManager::GetActiveUserProfile(); | 57 Profile* profile = ProfileManager::GetActiveUserProfile(); |
| 43 DownloadManagerService* service = | 58 DownloadManagerService* service = |
| 44 new DownloadManagerService(env, jobj); | 59 new DownloadManagerService(env, jobj); |
| 45 DownloadService* download_service = | 60 DownloadService* download_service = |
| 46 DownloadServiceFactory::GetForBrowserContext(profile); | 61 DownloadServiceFactory::GetForBrowserContext(profile); |
| 47 DownloadHistory* history = download_service->GetDownloadHistory(); | 62 DownloadHistory* history = download_service->GetDownloadHistory(); |
| 48 if (history) | 63 if (history) |
| 49 history->AddObserver(service); | 64 history->AddObserver(service); |
| 50 return reinterpret_cast<intptr_t>(service); | 65 return reinterpret_cast<intptr_t>(service); |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 resume_callback_for_testing_.Run(false); | 290 resume_callback_for_testing_.Run(false); |
| 276 } | 291 } |
| 277 | 292 |
| 278 content::DownloadManager* DownloadManagerService::GetDownloadManager( | 293 content::DownloadManager* DownloadManagerService::GetDownloadManager( |
| 279 bool is_off_the_record) { | 294 bool is_off_the_record) { |
| 280 Profile* profile = ProfileManager::GetActiveUserProfile(); | 295 Profile* profile = ProfileManager::GetActiveUserProfile(); |
| 281 if (is_off_the_record) | 296 if (is_off_the_record) |
| 282 profile = profile->GetOffTheRecordProfile(); | 297 profile = profile->GetOffTheRecordProfile(); |
| 283 return content::BrowserContext::GetDownloadManager(profile); | 298 return content::BrowserContext::GetDownloadManager(profile); |
| 284 } | 299 } |
| OLD | NEW |