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

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

Issue 2344483003: Ask download manager to remove a download if it is overwritten by another (Closed)
Patch Set: Created 4 years, 3 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/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 bool has_no_external_storage = 58 bool has_no_external_storage =
59 (reason == DownloadController::CANCEL_REASON_NO_EXTERNAL_STORAGE); 59 (reason == DownloadController::CANCEL_REASON_NO_EXTERNAL_STORAGE);
60 JNIEnv* env = base::android::AttachCurrentThread(); 60 JNIEnv* env = base::android::AttachCurrentThread();
61 ScopedJavaLocalRef<jstring> jname = 61 ScopedJavaLocalRef<jstring> jname =
62 ConvertUTF8ToJavaString(env, download->GetURL().ExtractFileName()); 62 ConvertUTF8ToJavaString(env, download->GetURL().ExtractFileName());
63 Java_DownloadManagerService_onDownloadItemCanceled(env, jname, 63 Java_DownloadManagerService_onDownloadItemCanceled(env, jname,
64 has_no_external_storage); 64 has_no_external_storage);
65 DownloadController::RecordDownloadCancelReason(reason); 65 DownloadController::RecordDownloadCancelReason(reason);
66 } 66 }
67 67
68 // static
69 DownloadManagerService* DownloadManagerService::GetInstance() {
70 return base::Singleton<DownloadManagerService>::get();
71 }
68 72
69 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& jobj) { 73 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& jobj) {
70 Profile* profile = ProfileManager::GetActiveUserProfile(); 74 Profile* profile = ProfileManager::GetActiveUserProfile();
71 DownloadManagerService* service = 75 DownloadManagerService* service = DownloadManagerService::GetInstance();
72 new DownloadManagerService(env, jobj); 76 service->Init(env, jobj);
73 DownloadService* download_service = 77 DownloadService* download_service =
74 DownloadServiceFactory::GetForBrowserContext(profile); 78 DownloadServiceFactory::GetForBrowserContext(profile);
75 DownloadHistory* history = download_service->GetDownloadHistory(); 79 DownloadHistory* history = download_service->GetDownloadHistory();
76 if (history) 80 if (history)
77 history->AddObserver(service); 81 history->AddObserver(service);
78 return reinterpret_cast<intptr_t>(service); 82 return reinterpret_cast<intptr_t>(service);
79 } 83 }
80 84
81 DownloadManagerService::DownloadManagerService( 85 DownloadManagerService::DownloadManagerService()
86 : is_history_query_complete_(false) {
87 }
88
89 DownloadManagerService::~DownloadManagerService() {}
90
91 void DownloadManagerService::Init(
82 JNIEnv* env, 92 JNIEnv* env,
83 jobject obj) 93 jobject obj) {
84 : java_ref_(env, obj), 94 java_ref_.Reset(env, obj);
85 is_history_query_complete_(false) {
86 DownloadControllerBase::Get()->SetDefaultDownloadFileName( 95 DownloadControllerBase::Get()->SetDefaultDownloadFileName(
87 l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME)); 96 l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME));
88 } 97 }
89 98
90 DownloadManagerService::~DownloadManagerService() {}
91
92 void DownloadManagerService::ResumeDownload( 99 void DownloadManagerService::ResumeDownload(
93 JNIEnv* env, 100 JNIEnv* env,
94 jobject obj, 101 jobject obj,
95 const JavaParamRef<jstring>& jdownload_guid, 102 const JavaParamRef<jstring>& jdownload_guid,
96 bool is_off_the_record) { 103 bool is_off_the_record) {
97 std::string download_guid = ConvertJavaStringToUTF8(env, jdownload_guid); 104 std::string download_guid = ConvertJavaStringToUTF8(env, jdownload_guid);
98 if (is_history_query_complete_ || is_off_the_record) 105 if (is_history_query_complete_ || is_off_the_record)
99 ResumeDownloadInternal(download_guid, is_off_the_record); 106 ResumeDownloadInternal(download_guid, is_off_the_record);
100 else 107 else
101 EnqueueDownloadAction(download_guid, RESUME); 108 EnqueueDownloadAction(download_guid, RESUME);
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 content::DownloadManager* manager = 396 content::DownloadManager* manager =
390 content::BrowserContext::GetDownloadManager(profile); 397 content::BrowserContext::GetDownloadManager(profile);
391 398
392 // Update notifiers to monitor any newly created DownloadManagers. 399 // Update notifiers to monitor any newly created DownloadManagers.
393 updateNotifier( 400 updateNotifier(
394 this, manager, 401 this, manager,
395 is_off_the_record ? off_the_record_notifier_ : original_notifier_); 402 is_off_the_record ? off_the_record_notifier_ : original_notifier_);
396 403
397 return manager; 404 return manager;
398 } 405 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698