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

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

Issue 2058593002: Add UMA for studying download cancellation reasons (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressing comments Created 4 years, 6 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"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "chrome/browser/download/download_service.h" 12 #include "chrome/browser/download/download_service.h"
13 #include "chrome/browser/download/download_service_factory.h" 13 #include "chrome/browser/download/download_service_factory.h"
14 #include "chrome/browser/profiles/profile_manager.h" 14 #include "chrome/browser/profiles/profile_manager.h"
15 #include "chrome/grit/generated_resources.h" 15 #include "chrome/grit/generated_resources.h"
16 #include "content/public/browser/android/download_controller_android.h" 16 #include "content/public/browser/android/download_controller_android.h"
17 #include "content/public/browser/browser_context.h" 17 #include "content/public/browser/browser_context.h"
18 #include "content/public/browser/download_item.h" 18 #include "content/public/browser/download_item.h"
19 #include "jni/DownloadManagerService_jni.h" 19 #include "jni/DownloadManagerService_jni.h"
20 #include "ui/base/l10n/l10n_util.h" 20 #include "ui/base/l10n/l10n_util.h"
21 21
22 using base::android::JavaParamRef; 22 using base::android::JavaParamRef;
23 using base::android::ConvertJavaStringToUTF8; 23 using base::android::ConvertJavaStringToUTF8;
24 using base::android::ConvertUTF8ToJavaString; 24 using base::android::ConvertUTF8ToJavaString;
25 using content::DownloadControllerAndroid;
25 26
26 // static 27 // static
27 bool DownloadManagerService::RegisterDownloadManagerService(JNIEnv* env) { 28 bool DownloadManagerService::RegisterDownloadManagerService(JNIEnv* env) {
28 return RegisterNativesImpl(env); 29 return RegisterNativesImpl(env);
29 } 30 }
30 31
31 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& jobj) { 32 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& jobj) {
32 Profile* profile = ProfileManager::GetActiveUserProfile(); 33 Profile* profile = ProfileManager::GetActiveUserProfile();
33 DownloadManagerService* service = 34 DownloadManagerService* service =
34 new DownloadManagerService(env, jobj); 35 new DownloadManagerService(env, jobj);
35 DownloadService* download_service = 36 DownloadService* download_service =
36 DownloadServiceFactory::GetForBrowserContext(profile); 37 DownloadServiceFactory::GetForBrowserContext(profile);
37 DownloadHistory* history = download_service->GetDownloadHistory(); 38 DownloadHistory* history = download_service->GetDownloadHistory();
38 if (history) 39 if (history)
39 history->AddObserver(service); 40 history->AddObserver(service);
40 return reinterpret_cast<intptr_t>(service); 41 return reinterpret_cast<intptr_t>(service);
41 } 42 }
42 43
43 DownloadManagerService::DownloadManagerService( 44 DownloadManagerService::DownloadManagerService(
44 JNIEnv* env, 45 JNIEnv* env,
45 jobject obj) 46 jobject obj)
46 : java_ref_(env, obj), 47 : java_ref_(env, obj),
47 is_history_query_complete_(false) { 48 is_history_query_complete_(false) {
48 content::DownloadControllerAndroid::Get()->SetDefaultDownloadFileName( 49 DownloadControllerAndroid::Get()->SetDefaultDownloadFileName(
49 l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME)); 50 l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME));
50 } 51 }
51 52
52 DownloadManagerService::~DownloadManagerService() {} 53 DownloadManagerService::~DownloadManagerService() {}
53 54
54 void DownloadManagerService::ResumeDownload( 55 void DownloadManagerService::ResumeDownload(
55 JNIEnv* env, 56 JNIEnv* env,
56 jobject obj, 57 jobject obj,
57 const JavaParamRef<jstring>& jdownload_guid) { 58 const JavaParamRef<jstring>& jdownload_guid) {
58 std::string download_guid = ConvertJavaStringToUTF8(env, jdownload_guid); 59 std::string download_guid = ConvertJavaStringToUTF8(env, jdownload_guid);
(...skipping 11 matching lines...) Expand all
70 if (is_history_query_complete_) 71 if (is_history_query_complete_)
71 PauseDownloadInternal(download_guid); 72 PauseDownloadInternal(download_guid);
72 else 73 else
73 EnqueueDownloadAction(download_guid, PAUSE); 74 EnqueueDownloadAction(download_guid, PAUSE);
74 } 75 }
75 76
76 void DownloadManagerService::CancelDownload( 77 void DownloadManagerService::CancelDownload(
77 JNIEnv* env, 78 JNIEnv* env,
78 jobject obj, 79 jobject obj,
79 const JavaParamRef<jstring>& jdownload_guid, 80 const JavaParamRef<jstring>& jdownload_guid,
80 bool is_off_the_record) { 81 bool is_off_the_record,
82 bool is_notification_dismissed) {
81 std::string download_guid = ConvertJavaStringToUTF8(env, jdownload_guid); 83 std::string download_guid = ConvertJavaStringToUTF8(env, jdownload_guid);
84
85 DownloadControllerAndroid::RecordDownloadCancelReason(
86 is_notification_dismissed ?
87 DownloadControllerAndroid::CANCEL_REASON_NOTIFICATION_DISMISSED :
88 DownloadControllerAndroid::CANCEL_REASON_ACTION_BUTTON);
82 // Incognito download can only be cancelled in the same browser session, no 89 // Incognito download can only be cancelled in the same browser session, no
83 // need to wait for download history. 90 // need to wait for download history.
84 if (is_off_the_record) { 91 if (is_off_the_record) {
85 CancelDownloadInternal(download_guid, true); 92 CancelDownloadInternal(download_guid, true);
86 return; 93 return;
87 } 94 }
88 95
89 if (is_history_query_complete_) 96 if (is_history_query_complete_)
90 CancelDownloadInternal(download_guid, false); 97 CancelDownloadInternal(download_guid, false);
91 else 98 else
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 NOTREACHED(); 193 NOTREACHED();
187 break; 194 break;
188 } 195 }
189 } 196 }
190 197
191 void DownloadManagerService::OnResumptionFailed( 198 void DownloadManagerService::OnResumptionFailed(
192 const std::string& download_guid) { 199 const std::string& download_guid) {
193 base::ThreadTaskRunnerHandle::Get()->PostTask( 200 base::ThreadTaskRunnerHandle::Get()->PostTask(
194 FROM_HERE, base::Bind(&DownloadManagerService::OnResumptionFailedInternal, 201 FROM_HERE, base::Bind(&DownloadManagerService::OnResumptionFailedInternal,
195 base::Unretained(this), download_guid)); 202 base::Unretained(this), download_guid));
203 DownloadControllerAndroid::RecordDownloadCancelReason(
204 DownloadControllerAndroid::CANCEL_REASON_NOT_CANCELED);
196 } 205 }
197 206
198 void DownloadManagerService::OnResumptionFailedInternal( 207 void DownloadManagerService::OnResumptionFailedInternal(
199 const std::string& download_guid) { 208 const std::string& download_guid) {
200 if (!java_ref_.is_null()) { 209 if (!java_ref_.is_null()) {
201 JNIEnv* env = base::android::AttachCurrentThread(); 210 JNIEnv* env = base::android::AttachCurrentThread();
202 Java_DownloadManagerService_onResumptionFailed( 211 Java_DownloadManagerService_onResumptionFailed(
203 env, java_ref_.obj(), 212 env, java_ref_.obj(),
204 ConvertUTF8ToJavaString(env, download_guid).obj()); 213 ConvertUTF8ToJavaString(env, download_guid).obj());
205 } 214 }
206 if (!resume_callback_for_testing_.is_null()) 215 if (!resume_callback_for_testing_.is_null())
207 resume_callback_for_testing_.Run(false); 216 resume_callback_for_testing_.Run(false);
208 } 217 }
209 218
210 content::DownloadManager* DownloadManagerService::GetDownloadManager( 219 content::DownloadManager* DownloadManagerService::GetDownloadManager(
211 bool is_off_the_record) { 220 bool is_off_the_record) {
212 Profile* profile = ProfileManager::GetActiveUserProfile(); 221 Profile* profile = ProfileManager::GetActiveUserProfile();
213 if (is_off_the_record) 222 if (is_off_the_record)
214 profile = profile->GetOffTheRecordProfile(); 223 profile = profile->GetOffTheRecordProfile();
215 return content::BrowserContext::GetDownloadManager(profile); 224 return content::BrowserContext::GetDownloadManager(profile);
216 } 225 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698