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

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

Issue 2237943002: Remove now-unnecessary .obj() in Java method calls. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@switch-context
Patch Set: Rebase *again* :( Created 4 years, 4 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 // static 43 // static
44 void DownloadManagerService::OnDownloadCanceled( 44 void DownloadManagerService::OnDownloadCanceled(
45 content::DownloadItem* download, 45 content::DownloadItem* download,
46 DownloadController::DownloadCancelReason reason) { 46 DownloadController::DownloadCancelReason reason) {
47 bool has_no_external_storage = 47 bool has_no_external_storage =
48 (reason == DownloadController::CANCEL_REASON_NO_EXTERNAL_STORAGE); 48 (reason == DownloadController::CANCEL_REASON_NO_EXTERNAL_STORAGE);
49 JNIEnv* env = base::android::AttachCurrentThread(); 49 JNIEnv* env = base::android::AttachCurrentThread();
50 ScopedJavaLocalRef<jstring> jname = 50 ScopedJavaLocalRef<jstring> jname =
51 ConvertUTF8ToJavaString(env, download->GetURL().ExtractFileName()); 51 ConvertUTF8ToJavaString(env, download->GetURL().ExtractFileName());
52 Java_DownloadManagerService_onDownloadItemCanceled( 52 Java_DownloadManagerService_onDownloadItemCanceled(env, jname,
53 env, jname.obj(), has_no_external_storage); 53 has_no_external_storage);
54 DownloadController::RecordDownloadCancelReason(reason); 54 DownloadController::RecordDownloadCancelReason(reason);
55 } 55 }
56 56
57 57
58 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& jobj) { 58 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& jobj) {
59 Profile* profile = ProfileManager::GetActiveUserProfile(); 59 Profile* profile = ProfileManager::GetActiveUserProfile();
60 DownloadManagerService* service = 60 DownloadManagerService* service =
61 new DownloadManagerService(env, jobj); 61 new DownloadManagerService(env, jobj);
62 DownloadService* download_service = 62 DownloadService* download_service =
63 DownloadServiceFactory::GetForBrowserContext(profile); 63 DownloadServiceFactory::GetForBrowserContext(profile);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 137
138 // Search through the downloads for the entry with the given GUID. 138 // Search through the downloads for the entry with the given GUID.
139 content::DownloadManager::DownloadVector all_items; 139 content::DownloadManager::DownloadVector all_items;
140 manager->GetAllDownloads(&all_items); 140 manager->GetAllDownloads(&all_items);
141 std::string download_guid = ConvertJavaStringToUTF8(env, jdownload_guid); 141 std::string download_guid = ConvertJavaStringToUTF8(env, jdownload_guid);
142 for (auto item : all_items) { 142 for (auto item : all_items) {
143 if (item->GetGuid() != download_guid) 143 if (item->GetGuid() != download_guid)
144 continue; 144 continue;
145 145
146 Java_DownloadManagerService_onDownloadItemUpdated( 146 Java_DownloadManagerService_onDownloadItemUpdated(
147 env, 147 env, java_ref_, ConvertUTF8ToJavaString(env, item->GetGuid()),
148 java_ref_.obj(), 148 ConvertUTF8ToJavaString(env, item->GetFileNameToReportUser().value()),
149 ConvertUTF8ToJavaString(env, item->GetGuid()).obj(), 149 ConvertUTF8ToJavaString(env, item->GetTargetFilePath().value()),
150 ConvertUTF8ToJavaString( 150 ConvertUTF8ToJavaString(env, item->GetTabUrl().spec()),
151 env, item->GetFileNameToReportUser().value()).obj(), 151 ConvertUTF8ToJavaString(env, item->GetMimeType()),
152 ConvertUTF8ToJavaString( 152 item->GetStartTime().ToJavaTime(), item->GetTotalBytes());
153 env, item->GetTargetFilePath().value()).obj(),
154 ConvertUTF8ToJavaString(env, item->GetTabUrl().spec()).obj(),
155 ConvertUTF8ToJavaString(env, item->GetMimeType()).obj(),
156 item->GetStartTime().ToJavaTime(),
157 item->GetTotalBytes());
158 break; 153 break;
159 } 154 }
160 } 155 }
161 156
162 void DownloadManagerService::GetAllDownloadsInternal() { 157 void DownloadManagerService::GetAllDownloadsInternal() {
163 content::DownloadManager* manager = GetDownloadManager(false); 158 content::DownloadManager* manager = GetDownloadManager(false);
164 if (java_ref_.is_null() || !manager) 159 if (java_ref_.is_null() || !manager)
165 return; 160 return;
166 161
167 content::DownloadManager::DownloadVector all_items; 162 content::DownloadManager::DownloadVector all_items;
168 manager->GetAllDownloads(&all_items); 163 manager->GetAllDownloads(&all_items);
169 164
170 // Create a Java array of all of the visible DownloadItems. 165 // Create a Java array of all of the visible DownloadItems.
171 JNIEnv* env = base::android::AttachCurrentThread(); 166 JNIEnv* env = base::android::AttachCurrentThread();
172 ScopedJavaLocalRef<jobject> j_download_item_list = 167 ScopedJavaLocalRef<jobject> j_download_item_list =
173 Java_DownloadManagerService_createDownloadItemList(env, java_ref_.obj()); 168 Java_DownloadManagerService_createDownloadItemList(env, java_ref_);
174 169
175 for (size_t i = 0; i < all_items.size(); i++) { 170 for (size_t i = 0; i < all_items.size(); i++) {
176 content::DownloadItem* item = all_items[i]; 171 content::DownloadItem* item = all_items[i];
177 if (!ShouldShowDownloadItem(item)) 172 if (!ShouldShowDownloadItem(item))
178 continue; 173 continue;
179 174
180 Java_DownloadManagerService_addDownloadItemToList( 175 Java_DownloadManagerService_addDownloadItemToList(
181 env, 176 env, java_ref_, j_download_item_list,
182 java_ref_.obj(), 177 ConvertUTF8ToJavaString(env, item->GetGuid()),
183 j_download_item_list.obj(), 178 ConvertUTF8ToJavaString(env, item->GetFileNameToReportUser().value()),
184 ConvertUTF8ToJavaString(env, item->GetGuid()).obj(), 179 ConvertUTF8ToJavaString(env, item->GetTargetFilePath().value()),
185 ConvertUTF8ToJavaString( 180 ConvertUTF8ToJavaString(env, item->GetTabUrl().spec()),
186 env, item->GetFileNameToReportUser().value()).obj(), 181 ConvertUTF8ToJavaString(env, item->GetMimeType()),
187 ConvertUTF8ToJavaString( 182 item->GetStartTime().ToJavaTime(), item->GetTotalBytes());
188 env, item->GetTargetFilePath().value()).obj(),
189 ConvertUTF8ToJavaString(env, item->GetTabUrl().spec()).obj(),
190 ConvertUTF8ToJavaString(env, item->GetMimeType()).obj(),
191 item->GetStartTime().ToJavaTime(),
192 item->GetTotalBytes());
193 } 183 }
194 184
195 Java_DownloadManagerService_onAllDownloadsRetrieved( 185 Java_DownloadManagerService_onAllDownloadsRetrieved(env, java_ref_,
196 env, java_ref_.obj(), j_download_item_list.obj()); 186 j_download_item_list);
197 } 187 }
198 188
199 189
200 void DownloadManagerService::CancelDownload( 190 void DownloadManagerService::CancelDownload(
201 JNIEnv* env, 191 JNIEnv* env,
202 jobject obj, 192 jobject obj,
203 const JavaParamRef<jstring>& jdownload_guid, 193 const JavaParamRef<jstring>& jdownload_guid,
204 bool is_off_the_record, 194 bool is_off_the_record,
205 bool is_notification_dismissed) { 195 bool is_notification_dismissed) {
206 std::string download_guid = ConvertJavaStringToUTF8(env, jdownload_guid); 196 std::string download_guid = ConvertJavaStringToUTF8(env, jdownload_guid);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 // Monitor all DownloadItems for changes. 233 // Monitor all DownloadItems for changes.
244 content::DownloadManager* manager = GetDownloadManager(false); 234 content::DownloadManager* manager = GetDownloadManager(false);
245 if (manager) 235 if (manager)
246 original_notifier_.reset(new AllDownloadItemNotifier(manager, this)); 236 original_notifier_.reset(new AllDownloadItemNotifier(manager, this));
247 } 237 }
248 238
249 void DownloadManagerService::OnDownloadRemoved( 239 void DownloadManagerService::OnDownloadRemoved(
250 content::DownloadManager* manager, content::DownloadItem* item) { 240 content::DownloadManager* manager, content::DownloadItem* item) {
251 JNIEnv* env = base::android::AttachCurrentThread(); 241 JNIEnv* env = base::android::AttachCurrentThread();
252 Java_DownloadManagerService_onDownloadItemRemoved( 242 Java_DownloadManagerService_onDownloadItemRemoved(
253 env, 243 env, java_ref_, ConvertUTF8ToJavaString(env, item->GetGuid()));
254 java_ref_.obj(),
255 ConvertUTF8ToJavaString(env, item->GetGuid()).obj());
256 } 244 }
257 245
258 void DownloadManagerService::ResumeDownloadInternal( 246 void DownloadManagerService::ResumeDownloadInternal(
259 const std::string& download_guid, bool is_off_the_record) { 247 const std::string& download_guid, bool is_off_the_record) {
260 content::DownloadManager* manager = GetDownloadManager(is_off_the_record); 248 content::DownloadManager* manager = GetDownloadManager(is_off_the_record);
261 if (!manager) { 249 if (!manager) {
262 OnResumptionFailed(download_guid); 250 OnResumptionFailed(download_guid);
263 return; 251 return;
264 } 252 }
265 content::DownloadItem* item = manager->GetDownloadByGuid(download_guid); 253 content::DownloadItem* item = manager->GetDownloadByGuid(download_guid);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 base::Unretained(this), download_guid)); 338 base::Unretained(this), download_guid));
351 DownloadController::RecordDownloadCancelReason( 339 DownloadController::RecordDownloadCancelReason(
352 DownloadController::CANCEL_REASON_NOT_CANCELED); 340 DownloadController::CANCEL_REASON_NOT_CANCELED);
353 } 341 }
354 342
355 void DownloadManagerService::OnResumptionFailedInternal( 343 void DownloadManagerService::OnResumptionFailedInternal(
356 const std::string& download_guid) { 344 const std::string& download_guid) {
357 if (!java_ref_.is_null()) { 345 if (!java_ref_.is_null()) {
358 JNIEnv* env = base::android::AttachCurrentThread(); 346 JNIEnv* env = base::android::AttachCurrentThread();
359 Java_DownloadManagerService_onResumptionFailed( 347 Java_DownloadManagerService_onResumptionFailed(
360 env, java_ref_.obj(), 348 env, java_ref_, ConvertUTF8ToJavaString(env, download_guid));
361 ConvertUTF8ToJavaString(env, download_guid).obj());
362 } 349 }
363 if (!resume_callback_for_testing_.is_null()) 350 if (!resume_callback_for_testing_.is_null())
364 resume_callback_for_testing_.Run(false); 351 resume_callback_for_testing_.Run(false);
365 } 352 }
366 353
367 content::DownloadManager* DownloadManagerService::GetDownloadManager( 354 content::DownloadManager* DownloadManagerService::GetDownloadManager(
368 bool is_off_the_record) { 355 bool is_off_the_record) {
369 Profile* profile = ProfileManager::GetActiveUserProfile(); 356 Profile* profile = ProfileManager::GetActiveUserProfile();
370 if (is_off_the_record) 357 if (is_off_the_record)
371 profile = profile->GetOffTheRecordProfile(); 358 profile = profile->GetOffTheRecordProfile();
372 return content::BrowserContext::GetDownloadManager(profile); 359 return content::BrowserContext::GetDownloadManager(profile);
373 } 360 }
OLDNEW
« no previous file with comments | « chrome/browser/android/download/download_controller.cc ('k') | chrome/browser/android/favicon_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698