Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: chrome/browser/android/download/download_manager_service.cc

Issue 2720613002: Downloads: Added transient flag to download item and download database (Closed)
Patch Set: fix tests Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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->IsVisible();
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->IsVisible());
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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 298
298 // Respond to any requests to get all downloads. 299 // Respond to any requests to get all downloads.
299 if (pending_get_downloads_actions_ & REGULAR) 300 if (pending_get_downloads_actions_ & REGULAR)
300 GetAllDownloadsInternal(false); 301 GetAllDownloadsInternal(false);
301 if (pending_get_downloads_actions_ & OFF_THE_RECORD) 302 if (pending_get_downloads_actions_ & OFF_THE_RECORD)
302 GetAllDownloadsInternal(true); 303 GetAllDownloadsInternal(true);
303 } 304 }
304 305
305 void DownloadManagerService::OnDownloadCreated( 306 void DownloadManagerService::OnDownloadCreated(
306 content::DownloadManager* manager, content::DownloadItem* item) { 307 content::DownloadManager* manager, content::DownloadItem* item) {
308 if (!item->IsVisible())
309 return;
307 310
308 JNIEnv* env = base::android::AttachCurrentThread(); 311 JNIEnv* env = base::android::AttachCurrentThread();
309 ScopedJavaLocalRef<jobject> j_item = CreateJavaDownloadItem(env, item); 312 ScopedJavaLocalRef<jobject> j_item = CreateJavaDownloadItem(env, item);
310 Java_DownloadManagerService_onDownloadItemCreated( 313 Java_DownloadManagerService_onDownloadItemCreated(
311 env, java_ref_.obj(), j_item); 314 env, java_ref_.obj(), j_item);
312 } 315 }
313 316
314 void DownloadManagerService::OnDownloadUpdated( 317 void DownloadManagerService::OnDownloadUpdated(
315 content::DownloadManager* manager, content::DownloadItem* item) { 318 content::DownloadManager* manager, content::DownloadItem* item) {
316 if (java_ref_.is_null()) 319 if (java_ref_.is_null())
317 return; 320 return;
318 321
319 if (item->IsTemporary()) 322 if (item->IsTemporary() || !item->IsVisible())
320 return; 323 return;
321 324
322 JNIEnv* env = base::android::AttachCurrentThread(); 325 JNIEnv* env = base::android::AttachCurrentThread();
323 ScopedJavaLocalRef<jobject> j_item = CreateJavaDownloadItem(env, item); 326 ScopedJavaLocalRef<jobject> j_item = CreateJavaDownloadItem(env, item);
324 Java_DownloadManagerService_onDownloadItemUpdated( 327 Java_DownloadManagerService_onDownloadItemUpdated(
325 env, java_ref_.obj(), j_item); 328 env, java_ref_.obj(), j_item);
326 } 329 }
327 330
328 void DownloadManagerService::OnDownloadRemoved( 331 void DownloadManagerService::OnDownloadRemoved(
329 content::DownloadManager* manager, content::DownloadItem* item) { 332 content::DownloadManager* manager, content::DownloadItem* item) {
330 if (java_ref_.is_null()) 333 if (java_ref_.is_null() || !item->IsVisible())
331 return; 334 return;
332 335
333 JNIEnv* env = base::android::AttachCurrentThread(); 336 JNIEnv* env = base::android::AttachCurrentThread();
334 Java_DownloadManagerService_onDownloadItemRemoved( 337 Java_DownloadManagerService_onDownloadItemRemoved(
335 env, 338 env,
336 java_ref_.obj(), 339 java_ref_.obj(),
337 ConvertUTF8ToJavaString(env, item->GetGuid()), 340 ConvertUTF8ToJavaString(env, item->GetGuid()),
338 item->GetBrowserContext()->IsOffTheRecord()); 341 item->GetBrowserContext()->IsOffTheRecord());
339 } 342 }
340 343
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 chrome::android::kDownloadAutoResumptionThrottling, 480 chrome::android::kDownloadAutoResumptionThrottling,
478 kAutoResumptionLimitVariation); 481 kAutoResumptionLimitVariation);
479 int auto_resumption_limit; 482 int auto_resumption_limit;
480 if (!variation.empty() && 483 if (!variation.empty() &&
481 base::StringToInt(variation, &auto_resumption_limit)) { 484 base::StringToInt(variation, &auto_resumption_limit)) {
482 return auto_resumption_limit; 485 return auto_resumption_limit;
483 } 486 }
484 487
485 return kDefaultAutoResumptionLimit; 488 return kDefaultAutoResumptionLimit;
486 } 489 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698