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

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

Issue 2117343007: Show download error message if sdcard is not available (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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/context_utils.h"
7 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
8 #include "base/location.h" 9 #include "base/location.h"
9 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
10 #include "base/threading/thread_task_runner_handle.h" 11 #include "base/threading/thread_task_runner_handle.h"
11 #include "base/time/time.h" 12 #include "base/time/time.h"
12 #include "chrome/browser/android/download/download_controller.h" 13 #include "chrome/browser/android/download/download_controller.h"
13 #include "chrome/browser/download/download_service.h" 14 #include "chrome/browser/download/download_service.h"
14 #include "chrome/browser/download/download_service_factory.h" 15 #include "chrome/browser/download/download_service_factory.h"
15 #include "chrome/browser/profiles/profile_manager.h" 16 #include "chrome/browser/profiles/profile_manager.h"
16 #include "chrome/grit/generated_resources.h" 17 #include "chrome/grit/generated_resources.h"
17 #include "content/public/browser/browser_context.h" 18 #include "content/public/browser/browser_context.h"
18 #include "content/public/browser/download_item.h" 19 #include "content/public/browser/download_item.h"
19 #include "jni/DownloadManagerService_jni.h" 20 #include "jni/DownloadManagerService_jni.h"
20 #include "ui/base/l10n/l10n_util.h" 21 #include "ui/base/l10n/l10n_util.h"
21 22
22 using base::android::JavaParamRef; 23 using base::android::JavaParamRef;
23 using base::android::ConvertJavaStringToUTF8; 24 using base::android::ConvertJavaStringToUTF8;
24 using base::android::ConvertUTF8ToJavaString; 25 using base::android::ConvertUTF8ToJavaString;
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
32 // static
33 void DownloadManagerService::OnDownloadCanceled(
34 content::DownloadItem* download,
35 DownloadController::DownloadCancelReason reason) {
36 JNIEnv* env = base::android::AttachCurrentThread();
37 ScopedJavaLocalRef<jobject> download_manager =
38 Java_DownloadManagerService_getDownloadManagerService(
39 env, base::android::GetApplicationContext());
40 ScopedJavaLocalRef<jstring> jname =
41 ConvertUTF8ToJavaString(env, download->GetURL().ExtractFileName());
42 Java_DownloadManagerService_onDownloadCanceled(
43 env, download_manager.obj(), jname.obj(),
44 reason == DownloadController::CANCEL_REASON_NO_EXTERNAL_STORAGE);
45 DownloadController::RecordDownloadCancelReason(reason);
46 }
47
48
31 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& jobj) { 49 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& jobj) {
32 Profile* profile = ProfileManager::GetActiveUserProfile(); 50 Profile* profile = ProfileManager::GetActiveUserProfile();
33 DownloadManagerService* service = 51 DownloadManagerService* service =
34 new DownloadManagerService(env, jobj); 52 new DownloadManagerService(env, jobj);
35 DownloadService* download_service = 53 DownloadService* download_service =
36 DownloadServiceFactory::GetForBrowserContext(profile); 54 DownloadServiceFactory::GetForBrowserContext(profile);
37 DownloadHistory* history = download_service->GetDownloadHistory(); 55 DownloadHistory* history = download_service->GetDownloadHistory();
38 if (history) 56 if (history)
39 history->AddObserver(service); 57 history->AddObserver(service);
40 return reinterpret_cast<intptr_t>(service); 58 return reinterpret_cast<intptr_t>(service);
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 resume_callback_for_testing_.Run(false); 233 resume_callback_for_testing_.Run(false);
216 } 234 }
217 235
218 content::DownloadManager* DownloadManagerService::GetDownloadManager( 236 content::DownloadManager* DownloadManagerService::GetDownloadManager(
219 bool is_off_the_record) { 237 bool is_off_the_record) {
220 Profile* profile = ProfileManager::GetActiveUserProfile(); 238 Profile* profile = ProfileManager::GetActiveUserProfile();
221 if (is_off_the_record) 239 if (is_off_the_record)
222 profile = profile->GetOffTheRecordProfile(); 240 profile = profile->GetOffTheRecordProfile();
223 return content::BrowserContext::GetDownloadManager(profile); 241 return content::BrowserContext::GetDownloadManager(profile);
224 } 242 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698