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/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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 DownloadHistory* history = download_service->GetDownloadHistory(); | 75 DownloadHistory* history = download_service->GetDownloadHistory(); |
76 if (history) | 76 if (history) |
77 history->AddObserver(service); | 77 history->AddObserver(service); |
78 return reinterpret_cast<intptr_t>(service); | 78 return reinterpret_cast<intptr_t>(service); |
79 } | 79 } |
80 | 80 |
81 DownloadManagerService::DownloadManagerService( | 81 DownloadManagerService::DownloadManagerService( |
82 JNIEnv* env, | 82 JNIEnv* env, |
83 jobject obj) | 83 jobject obj) |
84 : java_ref_(env, obj), | 84 : java_ref_(env, obj), |
85 is_history_query_complete_(false) { | 85 is_history_query_complete_(false), |
| 86 pending_get_downloads_actions_(NONE) { |
86 DownloadControllerBase::Get()->SetDefaultDownloadFileName( | 87 DownloadControllerBase::Get()->SetDefaultDownloadFileName( |
87 l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME)); | 88 l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME)); |
88 } | 89 } |
89 | 90 |
90 DownloadManagerService::~DownloadManagerService() {} | 91 DownloadManagerService::~DownloadManagerService() {} |
91 | 92 |
92 void DownloadManagerService::ResumeDownload( | 93 void DownloadManagerService::ResumeDownload( |
93 JNIEnv* env, | 94 JNIEnv* env, |
94 jobject obj, | 95 jobject obj, |
95 const JavaParamRef<jstring>& jdownload_guid, | 96 const JavaParamRef<jstring>& jdownload_guid, |
(...skipping 28 matching lines...) Expand all Loading... |
124 else | 125 else |
125 EnqueueDownloadAction(download_guid, REMOVE); | 126 EnqueueDownloadAction(download_guid, REMOVE); |
126 } | 127 } |
127 | 128 |
128 void DownloadManagerService::GetAllDownloads(JNIEnv* env, | 129 void DownloadManagerService::GetAllDownloads(JNIEnv* env, |
129 const JavaParamRef<jobject>& obj, | 130 const JavaParamRef<jobject>& obj, |
130 bool is_off_the_record) { | 131 bool is_off_the_record) { |
131 if (is_history_query_complete_) | 132 if (is_history_query_complete_) |
132 GetAllDownloadsInternal(is_off_the_record); | 133 GetAllDownloadsInternal(is_off_the_record); |
133 else if (is_off_the_record) | 134 else if (is_off_the_record) |
134 EnqueueDownloadAction(std::string(), INITIALIZE_OFF_THE_RECORD_UI); | 135 pending_get_downloads_actions_ |= OFF_THE_RECORD; |
135 else | 136 else |
136 EnqueueDownloadAction(std::string(), INITIALIZE_UI); | 137 pending_get_downloads_actions_ |= REGULAR; |
137 } | 138 } |
138 | 139 |
139 void DownloadManagerService::GetAllDownloadsInternal(bool is_off_the_record) { | 140 void DownloadManagerService::GetAllDownloadsInternal(bool is_off_the_record) { |
140 content::DownloadManager* manager = GetDownloadManager(is_off_the_record); | 141 content::DownloadManager* manager = GetDownloadManager(is_off_the_record); |
141 if (java_ref_.is_null() || !manager) | 142 if (java_ref_.is_null() || !manager) |
142 return; | 143 return; |
143 | 144 |
144 content::DownloadManager::DownloadVector all_items; | 145 content::DownloadManager::DownloadVector all_items; |
145 manager->GetAllDownloads(&all_items); | 146 manager->GetAllDownloads(&all_items); |
146 | 147 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 switch (action) { | 212 switch (action) { |
212 case RESUME: | 213 case RESUME: |
213 ResumeDownloadInternal(download_guid, false); | 214 ResumeDownloadInternal(download_guid, false); |
214 break; | 215 break; |
215 case PAUSE: | 216 case PAUSE: |
216 PauseDownloadInternal(download_guid, false); | 217 PauseDownloadInternal(download_guid, false); |
217 break; | 218 break; |
218 case CANCEL: | 219 case CANCEL: |
219 CancelDownloadInternal(download_guid, false); | 220 CancelDownloadInternal(download_guid, false); |
220 break; | 221 break; |
221 case INITIALIZE_UI: | |
222 GetAllDownloadsInternal(false); | |
223 break; | |
224 case INITIALIZE_OFF_THE_RECORD_UI: | |
225 GetAllDownloadsInternal(true); | |
226 break; | |
227 default: | 222 default: |
228 NOTREACHED(); | 223 NOTREACHED(); |
229 break; | 224 break; |
230 } | 225 } |
231 } | 226 } |
232 pending_actions_.clear(); | 227 pending_actions_.clear(); |
233 | 228 |
| 229 // Respond to any requests to get all downloads. |
| 230 if (pending_get_downloads_actions_ & REGULAR) |
| 231 GetAllDownloadsInternal(false); |
| 232 if (pending_get_downloads_actions_ & OFF_THE_RECORD) |
| 233 GetAllDownloadsInternal(true); |
| 234 |
234 // Monitor all DownloadItems for changes. | 235 // Monitor all DownloadItems for changes. |
235 updateNotifier(this, GetDownloadManager(false), original_notifier_); | 236 updateNotifier(this, GetDownloadManager(false), original_notifier_); |
236 updateNotifier(this, GetDownloadManager(true), off_the_record_notifier_); | 237 updateNotifier(this, GetDownloadManager(true), off_the_record_notifier_); |
237 } | 238 } |
238 | 239 |
239 void DownloadManagerService::OnDownloadUpdated( | 240 void DownloadManagerService::OnDownloadUpdated( |
240 content::DownloadManager* manager, content::DownloadItem* item) { | 241 content::DownloadManager* manager, content::DownloadItem* item) { |
241 if (java_ref_.is_null()) | 242 if (java_ref_.is_null()) |
242 return; | 243 return; |
243 | 244 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 case PAUSE: | 345 case PAUSE: |
345 if (iter->second == RESUME) | 346 if (iter->second == RESUME) |
346 iter->second = action; | 347 iter->second = action; |
347 break; | 348 break; |
348 case CANCEL: | 349 case CANCEL: |
349 iter->second = action; | 350 iter->second = action; |
350 break; | 351 break; |
351 case REMOVE: | 352 case REMOVE: |
352 iter->second = action; | 353 iter->second = action; |
353 break; | 354 break; |
354 case INITIALIZE_UI: | |
355 case INITIALIZE_OFF_THE_RECORD_UI: | |
356 iter->second = action; | |
357 break; | |
358 default: | 355 default: |
359 NOTREACHED(); | 356 NOTREACHED(); |
360 break; | 357 break; |
361 } | 358 } |
362 } | 359 } |
363 | 360 |
364 void DownloadManagerService::OnResumptionFailed( | 361 void DownloadManagerService::OnResumptionFailed( |
365 const std::string& download_guid) { | 362 const std::string& download_guid) { |
366 base::ThreadTaskRunnerHandle::Get()->PostTask( | 363 base::ThreadTaskRunnerHandle::Get()->PostTask( |
367 FROM_HERE, base::Bind(&DownloadManagerService::OnResumptionFailedInternal, | 364 FROM_HERE, base::Bind(&DownloadManagerService::OnResumptionFailedInternal, |
(...skipping 21 matching lines...) Expand all Loading... |
389 content::DownloadManager* manager = | 386 content::DownloadManager* manager = |
390 content::BrowserContext::GetDownloadManager(profile); | 387 content::BrowserContext::GetDownloadManager(profile); |
391 | 388 |
392 // Update notifiers to monitor any newly created DownloadManagers. | 389 // Update notifiers to monitor any newly created DownloadManagers. |
393 updateNotifier( | 390 updateNotifier( |
394 this, manager, | 391 this, manager, |
395 is_off_the_record ? off_the_record_notifier_ : original_notifier_); | 392 is_off_the_record ? off_the_record_notifier_ : original_notifier_); |
396 | 393 |
397 return manager; | 394 return manager; |
398 } | 395 } |
OLD | NEW |