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/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 23 matching lines...) Expand all Loading... | |
34 namespace { | 34 namespace { |
35 | 35 |
36 // The remaining time for a download item if it cannot be calculated. | 36 // The remaining time for a download item if it cannot be calculated. |
37 long kUnknownRemainingTime = -1; | 37 long kUnknownRemainingTime = -1; |
38 | 38 |
39 // Finch flag for controlling auto resumption limit. | 39 // Finch flag for controlling auto resumption limit. |
40 int kDefaultAutoResumptionLimit = 5; | 40 int kDefaultAutoResumptionLimit = 5; |
41 const char kAutoResumptionLimitVariation[] = "AutoResumptionLimit"; | 41 const char kAutoResumptionLimitVariation[] = "AutoResumptionLimit"; |
42 | 42 |
43 bool ShouldShowDownloadItem(content::DownloadItem* item) { | 43 bool ShouldShowDownloadItem(content::DownloadItem* item) { |
44 return !item->IsTemporary(); | 44 return !item->IsTemporary() && item->IsTransient(); |
45 } | 45 } |
46 | 46 |
47 void UpdateNotifier(DownloadManagerService* service, | 47 void UpdateNotifier(DownloadManagerService* service, |
48 content::DownloadManager* manager, | 48 content::DownloadManager* manager, |
49 std::unique_ptr<AllDownloadItemNotifier>& notifier) { | 49 std::unique_ptr<AllDownloadItemNotifier>& notifier) { |
50 if (manager) { | 50 if (manager) { |
51 if (!notifier || notifier->GetManager() != manager) | 51 if (!notifier || notifier->GetManager() != manager) |
52 notifier.reset(new AllDownloadItemNotifier(manager, service)); | 52 notifier.reset(new AllDownloadItemNotifier(manager, service)); |
53 } else { | 53 } else { |
54 notifier.reset(nullptr); | 54 notifier.reset(nullptr); |
55 } | 55 } |
56 } | 56 } |
57 | 57 |
58 ScopedJavaLocalRef<jobject> CreateJavaDownloadItem( | 58 ScopedJavaLocalRef<jobject> CreateJavaDownloadItem( |
59 JNIEnv* env, content::DownloadItem* item) { | 59 JNIEnv* env, content::DownloadItem* item) { |
60 DCHECK(item->IsTransient()); | |
brettw
2017/03/29 22:54:13
I don't follow this check, if we're creating java
shaktisahu
2017/03/29 23:46:47
Corrected now.
| |
60 return Java_DownloadItem_createDownloadItem( | 61 return Java_DownloadItem_createDownloadItem( |
61 env, DownloadManagerService::CreateJavaDownloadInfo(env, item), | 62 env, DownloadManagerService::CreateJavaDownloadInfo(env, item), |
62 item->GetStartTime().ToJavaTime(), item->GetFileExternallyRemoved()); | 63 item->GetStartTime().ToJavaTime(), item->GetFileExternallyRemoved()); |
63 } | 64 } |
64 | 65 |
65 } // namespace | 66 } // namespace |
66 | 67 |
67 // static | 68 // static |
68 bool DownloadManagerService::RegisterDownloadManagerService(JNIEnv* env) { | 69 bool DownloadManagerService::RegisterDownloadManagerService(JNIEnv* env) { |
69 return RegisterNativesImpl(env); | 70 return RegisterNativesImpl(env); |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
294 | 295 |
295 // Respond to any requests to get all downloads. | 296 // Respond to any requests to get all downloads. |
296 if (pending_get_downloads_actions_ & REGULAR) | 297 if (pending_get_downloads_actions_ & REGULAR) |
297 GetAllDownloadsInternal(false); | 298 GetAllDownloadsInternal(false); |
298 if (pending_get_downloads_actions_ & OFF_THE_RECORD) | 299 if (pending_get_downloads_actions_ & OFF_THE_RECORD) |
299 GetAllDownloadsInternal(true); | 300 GetAllDownloadsInternal(true); |
300 } | 301 } |
301 | 302 |
302 void DownloadManagerService::OnDownloadCreated( | 303 void DownloadManagerService::OnDownloadCreated( |
303 content::DownloadManager* manager, content::DownloadItem* item) { | 304 content::DownloadManager* manager, content::DownloadItem* item) { |
305 if (!item->IsTransient()) | |
306 return; | |
304 | 307 |
305 JNIEnv* env = base::android::AttachCurrentThread(); | 308 JNIEnv* env = base::android::AttachCurrentThread(); |
306 ScopedJavaLocalRef<jobject> j_item = CreateJavaDownloadItem(env, item); | 309 ScopedJavaLocalRef<jobject> j_item = CreateJavaDownloadItem(env, item); |
307 Java_DownloadManagerService_onDownloadItemCreated( | 310 Java_DownloadManagerService_onDownloadItemCreated( |
308 env, java_ref_.obj(), j_item); | 311 env, java_ref_.obj(), j_item); |
309 } | 312 } |
310 | 313 |
311 void DownloadManagerService::OnDownloadUpdated( | 314 void DownloadManagerService::OnDownloadUpdated( |
312 content::DownloadManager* manager, content::DownloadItem* item) { | 315 content::DownloadManager* manager, content::DownloadItem* item) { |
313 if (java_ref_.is_null()) | 316 if (java_ref_.is_null()) |
314 return; | 317 return; |
315 | 318 |
316 if (item->IsTemporary()) | 319 if (item->IsTemporary() || !item->IsTransient()) |
317 return; | 320 return; |
318 | 321 |
319 JNIEnv* env = base::android::AttachCurrentThread(); | 322 JNIEnv* env = base::android::AttachCurrentThread(); |
320 ScopedJavaLocalRef<jobject> j_item = CreateJavaDownloadItem(env, item); | 323 ScopedJavaLocalRef<jobject> j_item = CreateJavaDownloadItem(env, item); |
321 Java_DownloadManagerService_onDownloadItemUpdated( | 324 Java_DownloadManagerService_onDownloadItemUpdated( |
322 env, java_ref_.obj(), j_item); | 325 env, java_ref_.obj(), j_item); |
323 } | 326 } |
324 | 327 |
325 void DownloadManagerService::OnDownloadRemoved( | 328 void DownloadManagerService::OnDownloadRemoved( |
326 content::DownloadManager* manager, content::DownloadItem* item) { | 329 content::DownloadManager* manager, content::DownloadItem* item) { |
327 if (java_ref_.is_null()) | 330 if (java_ref_.is_null() || !item->IsTransient()) |
328 return; | 331 return; |
329 | 332 |
330 JNIEnv* env = base::android::AttachCurrentThread(); | 333 JNIEnv* env = base::android::AttachCurrentThread(); |
331 Java_DownloadManagerService_onDownloadItemRemoved( | 334 Java_DownloadManagerService_onDownloadItemRemoved( |
332 env, | 335 env, |
333 java_ref_.obj(), | 336 java_ref_.obj(), |
334 ConvertUTF8ToJavaString(env, item->GetGuid()), | 337 ConvertUTF8ToJavaString(env, item->GetGuid()), |
335 item->GetBrowserContext()->IsOffTheRecord()); | 338 item->GetBrowserContext()->IsOffTheRecord()); |
336 } | 339 } |
337 | 340 |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
474 chrome::android::kDownloadAutoResumptionThrottling, | 477 chrome::android::kDownloadAutoResumptionThrottling, |
475 kAutoResumptionLimitVariation); | 478 kAutoResumptionLimitVariation); |
476 int auto_resumption_limit; | 479 int auto_resumption_limit; |
477 if (!variation.empty() && | 480 if (!variation.empty() && |
478 base::StringToInt(variation, &auto_resumption_limit)) { | 481 base::StringToInt(variation, &auto_resumption_limit)) { |
479 return auto_resumption_limit; | 482 return auto_resumption_limit; |
480 } | 483 } |
481 | 484 |
482 return kDefaultAutoResumptionLimit; | 485 return kDefaultAutoResumptionLimit; |
483 } | 486 } |
OLD | NEW |