| 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.h" | 12 #include "chrome/browser/android/download/download_controller.h" |
| 13 #include "chrome/browser/download/download_service.h" | 13 #include "chrome/browser/download/download_service.h" |
| 14 #include "chrome/browser/download/download_service_factory.h" | 14 #include "chrome/browser/download/download_service_factory.h" |
| 15 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
| 16 #include "chrome/grit/generated_resources.h" | 16 #include "chrome/grit/generated_resources.h" |
| 17 #include "components/mime_util/mime_util.h" |
| 17 #include "content/public/browser/browser_context.h" | 18 #include "content/public/browser/browser_context.h" |
| 18 #include "content/public/browser/download_item.h" | 19 #include "content/public/browser/download_item.h" |
| 19 #include "jni/DownloadManagerService_jni.h" | 20 #include "jni/DownloadManagerService_jni.h" |
| 20 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 21 | 22 |
| 22 using base::android::JavaParamRef; | 23 using base::android::JavaParamRef; |
| 23 using base::android::ConvertJavaStringToUTF8; | 24 using base::android::ConvertJavaStringToUTF8; |
| 24 using base::android::ConvertUTF8ToJavaString; | 25 using base::android::ConvertUTF8ToJavaString; |
| 25 using base::android::ScopedJavaLocalRef; | 26 using base::android::ScopedJavaLocalRef; |
| 26 | 27 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 jobject obj, | 120 jobject obj, |
| 120 const JavaParamRef<jstring>& jdownload_guid, | 121 const JavaParamRef<jstring>& jdownload_guid, |
| 121 bool is_off_the_record) { | 122 bool is_off_the_record) { |
| 122 std::string download_guid = ConvertJavaStringToUTF8(env, jdownload_guid); | 123 std::string download_guid = ConvertJavaStringToUTF8(env, jdownload_guid); |
| 123 if (is_history_query_complete_ || is_off_the_record) | 124 if (is_history_query_complete_ || is_off_the_record) |
| 124 RemoveDownloadInternal(download_guid, is_off_the_record); | 125 RemoveDownloadInternal(download_guid, is_off_the_record); |
| 125 else | 126 else |
| 126 EnqueueDownloadAction(download_guid, REMOVE); | 127 EnqueueDownloadAction(download_guid, REMOVE); |
| 127 } | 128 } |
| 128 | 129 |
| 130 bool DownloadManagerService::IsDownloadOpenableInBrowser( |
| 131 JNIEnv* env, |
| 132 jobject obj, |
| 133 const JavaParamRef<jstring>& jdownload_guid, |
| 134 bool is_off_the_record) { |
| 135 std::string download_guid = ConvertJavaStringToUTF8(env, jdownload_guid); |
| 136 content::DownloadManager* manager = GetDownloadManager(is_off_the_record); |
| 137 if (!manager) |
| 138 return false; |
| 139 |
| 140 content::DownloadItem* item = manager->GetDownloadByGuid(download_guid); |
| 141 if (!item) |
| 142 return false; |
| 143 |
| 144 return mime_util::IsSupportedMimeType(item->GetMimeType()); |
| 145 } |
| 146 |
| 129 void DownloadManagerService::GetAllDownloads(JNIEnv* env, | 147 void DownloadManagerService::GetAllDownloads(JNIEnv* env, |
| 130 const JavaParamRef<jobject>& obj, | 148 const JavaParamRef<jobject>& obj, |
| 131 bool is_off_the_record) { | 149 bool is_off_the_record) { |
| 132 if (is_history_query_complete_) | 150 if (is_history_query_complete_) |
| 133 GetAllDownloadsInternal(is_off_the_record); | 151 GetAllDownloadsInternal(is_off_the_record); |
| 134 else if (is_off_the_record) | 152 else if (is_off_the_record) |
| 135 pending_get_downloads_actions_ |= OFF_THE_RECORD; | 153 pending_get_downloads_actions_ |= OFF_THE_RECORD; |
| 136 else | 154 else |
| 137 pending_get_downloads_actions_ |= REGULAR; | 155 pending_get_downloads_actions_ |= REGULAR; |
| 138 } | 156 } |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 content::DownloadManager* manager = | 404 content::DownloadManager* manager = |
| 387 content::BrowserContext::GetDownloadManager(profile); | 405 content::BrowserContext::GetDownloadManager(profile); |
| 388 | 406 |
| 389 // Update notifiers to monitor any newly created DownloadManagers. | 407 // Update notifiers to monitor any newly created DownloadManagers. |
| 390 updateNotifier( | 408 updateNotifier( |
| 391 this, manager, | 409 this, manager, |
| 392 is_off_the_record ? off_the_record_notifier_ : original_notifier_); | 410 is_off_the_record ? off_the_record_notifier_ : original_notifier_); |
| 393 | 411 |
| 394 return manager; | 412 return manager; |
| 395 } | 413 } |
| OLD | NEW |