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/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "chrome/browser/profiles/profile_manager.h" | 10 #include "chrome/browser/profiles/profile_manager.h" |
11 #include "chrome/grit/generated_resources.h" | |
11 #include "content/public/browser/android/download_controller_android.h" | 12 #include "content/public/browser/android/download_controller_android.h" |
12 #include "content/public/browser/browser_context.h" | 13 #include "content/public/browser/browser_context.h" |
13 #include "content/public/browser/download_item.h" | 14 #include "content/public/browser/download_item.h" |
14 #include "jni/DownloadManagerService_jni.h" | 15 #include "jni/DownloadManagerService_jni.h" |
16 #include "ui/base/l10n/l10n_util.h" | |
15 | 17 |
16 using base::android::JavaParamRef; | 18 using base::android::JavaParamRef; |
17 using base::android::ConvertJavaStringToUTF8; | 19 using base::android::ConvertJavaStringToUTF8; |
18 using base::android::ConvertUTF8ToJavaString; | 20 using base::android::ConvertUTF8ToJavaString; |
19 | 21 |
20 namespace { | 22 namespace { |
21 // The retry interval when resuming/canceling a download. This is needed because | 23 // The retry interval when resuming/canceling a download. This is needed because |
22 // when the browser process is launched, we have to wait until the download | 24 // when the browser process is launched, we have to wait until the download |
23 // history get loaded before a download can be resumed/cancelled. However, | 25 // history get loaded before a download can be resumed/cancelled. However, |
24 // we don't want to retry after a long period of time as the same download Id | 26 // we don't want to retry after a long period of time as the same download Id |
(...skipping 13 matching lines...) Expand all Loading... | |
38 DownloadManagerService* service = | 40 DownloadManagerService* service = |
39 new DownloadManagerService(env, jobj, manager); | 41 new DownloadManagerService(env, jobj, manager); |
40 return reinterpret_cast<intptr_t>(service); | 42 return reinterpret_cast<intptr_t>(service); |
41 } | 43 } |
42 | 44 |
43 DownloadManagerService::DownloadManagerService( | 45 DownloadManagerService::DownloadManagerService( |
44 JNIEnv* env, | 46 JNIEnv* env, |
45 jobject obj, | 47 jobject obj, |
46 content::DownloadManager* manager) | 48 content::DownloadManager* manager) |
47 : java_ref_(env, obj), manager_(manager) { | 49 : java_ref_(env, obj), manager_(manager) { |
50 content::DownloadControllerAndroid::Get()->SetDefaultDownloadFileName( | |
51 l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME)); | |
asanka
2016/02/24 20:04:44
Why can't DownloadControllerAndroid do this on its
qinmin
2016/02/24 21:56:06
2 reasons:
1. IDS_DEFAULT_DOWNLOAD_FILENAME is in
asanka
2016/02/24 22:08:03
Ah. I overlooked the fact that DownloadControllerA
| |
48 manager_->AddObserver(this); | 52 manager_->AddObserver(this); |
49 } | 53 } |
50 | 54 |
51 DownloadManagerService::~DownloadManagerService() { | 55 DownloadManagerService::~DownloadManagerService() { |
52 if (manager_) | 56 if (manager_) |
53 manager_->RemoveObserver(this); | 57 manager_->RemoveObserver(this); |
54 } | 58 } |
55 | 59 |
56 void DownloadManagerService::ResumeDownload(JNIEnv* env, | 60 void DownloadManagerService::ResumeDownload(JNIEnv* env, |
57 jobject obj, | 61 jobject obj, |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 const std::string& fileName) { | 147 const std::string& fileName) { |
144 if (!java_ref_.is_null()) { | 148 if (!java_ref_.is_null()) { |
145 JNIEnv* env = base::android::AttachCurrentThread(); | 149 JNIEnv* env = base::android::AttachCurrentThread(); |
146 Java_DownloadManagerService_onResumptionFailed( | 150 Java_DownloadManagerService_onResumptionFailed( |
147 env, java_ref_.obj(), download_id, | 151 env, java_ref_.obj(), download_id, |
148 ConvertUTF8ToJavaString(env, fileName).obj()); | 152 ConvertUTF8ToJavaString(env, fileName).obj()); |
149 } | 153 } |
150 if (!resume_callback_for_testing_.is_null()) | 154 if (!resume_callback_for_testing_.is_null()) |
151 resume_callback_for_testing_.Run(false); | 155 resume_callback_for_testing_.Run(false); |
152 } | 156 } |
OLD | NEW |