| 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 10 matching lines...) Expand all Loading... |
| 21 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 22 | 22 |
| 23 using base::android::JavaParamRef; | 23 using base::android::JavaParamRef; |
| 24 using base::android::ConvertJavaStringToUTF8; | 24 using base::android::ConvertJavaStringToUTF8; |
| 25 using base::android::ConvertUTF8ToJavaString; | 25 using base::android::ConvertUTF8ToJavaString; |
| 26 using base::android::ScopedJavaLocalRef; | 26 using base::android::ScopedJavaLocalRef; |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 bool ShouldShowDownloadItem(content::DownloadItem* item) { | 30 bool ShouldShowDownloadItem(content::DownloadItem* item) { |
| 31 return !item->IsTemporary() && | 31 return !item->IsTemporary(); |
| 32 !item->GetFileNameToReportUser().empty() && | |
| 33 !item->GetTargetFilePath().empty() && | |
| 34 item->GetState() != content::DownloadItem::CANCELLED; | |
| 35 } | 32 } |
| 36 | 33 |
| 37 void updateNotifier(DownloadManagerService* service, | 34 void UpdateNotifier(DownloadManagerService* service, |
| 38 content::DownloadManager* manager, | 35 content::DownloadManager* manager, |
| 39 std::unique_ptr<AllDownloadItemNotifier>& notifier) { | 36 std::unique_ptr<AllDownloadItemNotifier>& notifier) { |
| 40 if (manager) { | 37 if (manager) { |
| 41 if (!notifier || notifier->GetManager() != manager) | 38 if (!notifier || notifier->GetManager() != manager) |
| 42 notifier.reset(new AllDownloadItemNotifier(manager, service)); | 39 notifier.reset(new AllDownloadItemNotifier(manager, service)); |
| 43 } else { | 40 } else { |
| 44 notifier.reset(nullptr); | 41 notifier.reset(nullptr); |
| 45 } | 42 } |
| 46 } | 43 } |
| 47 | 44 |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 } | 266 } |
| 270 pending_actions_.clear(); | 267 pending_actions_.clear(); |
| 271 | 268 |
| 272 // Respond to any requests to get all downloads. | 269 // Respond to any requests to get all downloads. |
| 273 if (pending_get_downloads_actions_ & REGULAR) | 270 if (pending_get_downloads_actions_ & REGULAR) |
| 274 GetAllDownloadsInternal(false); | 271 GetAllDownloadsInternal(false); |
| 275 if (pending_get_downloads_actions_ & OFF_THE_RECORD) | 272 if (pending_get_downloads_actions_ & OFF_THE_RECORD) |
| 276 GetAllDownloadsInternal(true); | 273 GetAllDownloadsInternal(true); |
| 277 | 274 |
| 278 // Monitor all DownloadItems for changes. | 275 // Monitor all DownloadItems for changes. |
| 279 updateNotifier(this, GetDownloadManager(false), original_notifier_); | 276 UpdateNotifier(this, GetDownloadManager(false), original_notifier_); |
| 280 updateNotifier(this, GetDownloadManager(true), off_the_record_notifier_); | 277 UpdateNotifier(this, GetDownloadManager(true), off_the_record_notifier_); |
| 278 } |
| 279 |
| 280 void DownloadManagerService::OnDownloadCreated( |
| 281 content::DownloadManager* manager, content::DownloadItem* item) { |
| 282 |
| 283 JNIEnv* env = base::android::AttachCurrentThread(); |
| 284 ScopedJavaLocalRef<jobject> j_item = CreateJavaDownloadItem(env, item); |
| 285 Java_DownloadManagerService_onDownloadItemCreated( |
| 286 env, java_ref_.obj(), j_item); |
| 281 } | 287 } |
| 282 | 288 |
| 283 void DownloadManagerService::OnDownloadUpdated( | 289 void DownloadManagerService::OnDownloadUpdated( |
| 284 content::DownloadManager* manager, content::DownloadItem* item) { | 290 content::DownloadManager* manager, content::DownloadItem* item) { |
| 285 if (java_ref_.is_null()) | 291 if (java_ref_.is_null()) |
| 286 return; | 292 return; |
| 287 | 293 |
| 294 if (item->IsTemporary()) |
| 295 return; |
| 296 |
| 288 JNIEnv* env = base::android::AttachCurrentThread(); | 297 JNIEnv* env = base::android::AttachCurrentThread(); |
| 289 ScopedJavaLocalRef<jobject> j_item = CreateJavaDownloadItem(env, item); | 298 ScopedJavaLocalRef<jobject> j_item = CreateJavaDownloadItem(env, item); |
| 290 Java_DownloadManagerService_onDownloadItemUpdated( | 299 Java_DownloadManagerService_onDownloadItemUpdated( |
| 291 env, java_ref_.obj(), j_item); | 300 env, java_ref_.obj(), j_item); |
| 292 } | 301 } |
| 293 | 302 |
| 294 void DownloadManagerService::OnDownloadRemoved( | 303 void DownloadManagerService::OnDownloadRemoved( |
| 295 content::DownloadManager* manager, content::DownloadItem* item) { | 304 content::DownloadManager* manager, content::DownloadItem* item) { |
| 296 if (java_ref_.is_null()) | 305 if (java_ref_.is_null()) |
| 297 return; | 306 return; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 | 422 |
| 414 content::DownloadManager* DownloadManagerService::GetDownloadManager( | 423 content::DownloadManager* DownloadManagerService::GetDownloadManager( |
| 415 bool is_off_the_record) { | 424 bool is_off_the_record) { |
| 416 Profile* profile = ProfileManager::GetActiveUserProfile(); | 425 Profile* profile = ProfileManager::GetActiveUserProfile(); |
| 417 if (is_off_the_record) | 426 if (is_off_the_record) |
| 418 profile = profile->GetOffTheRecordProfile(); | 427 profile = profile->GetOffTheRecordProfile(); |
| 419 content::DownloadManager* manager = | 428 content::DownloadManager* manager = |
| 420 content::BrowserContext::GetDownloadManager(profile); | 429 content::BrowserContext::GetDownloadManager(profile); |
| 421 | 430 |
| 422 // Update notifiers to monitor any newly created DownloadManagers. | 431 // Update notifiers to monitor any newly created DownloadManagers. |
| 423 updateNotifier( | 432 UpdateNotifier( |
| 424 this, manager, | 433 this, manager, |
| 425 is_off_the_record ? off_the_record_notifier_ : original_notifier_); | 434 is_off_the_record ? off_the_record_notifier_ : original_notifier_); |
| 426 | 435 |
| 427 return manager; | 436 return manager; |
| 428 } | 437 } |
| 429 | 438 |
| 430 // static | 439 // static |
| 431 jboolean IsSupportedMimeType( | 440 jboolean IsSupportedMimeType( |
| 432 JNIEnv* env, | 441 JNIEnv* env, |
| 433 const JavaParamRef<jclass>& clazz, | 442 const JavaParamRef<jclass>& clazz, |
| 434 const JavaParamRef<jstring>& jmime_type) { | 443 const JavaParamRef<jstring>& jmime_type) { |
| 435 std::string mime_type = ConvertJavaStringToUTF8(env, jmime_type); | 444 std::string mime_type = ConvertJavaStringToUTF8(env, jmime_type); |
| 436 return mime_util::IsSupportedMimeType(mime_type); | 445 return mime_util::IsSupportedMimeType(mime_type); |
| 437 } | 446 } |
| OLD | NEW |