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/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 ConvertUTF8ToJavaString(env, item->GetFileNameToReportUser().value()), | 114 ConvertUTF8ToJavaString(env, item->GetFileNameToReportUser().value()), |
115 ConvertUTF8ToJavaString(env, item->GetTargetFilePath().value()), | 115 ConvertUTF8ToJavaString(env, item->GetTargetFilePath().value()), |
116 ConvertUTF8ToJavaString(env, item->GetTabUrl().spec()), | 116 ConvertUTF8ToJavaString(env, item->GetTabUrl().spec()), |
117 ConvertUTF8ToJavaString(env, item->GetMimeType()), | 117 ConvertUTF8ToJavaString(env, item->GetMimeType()), |
118 item->GetReceivedBytes(), item->GetBrowserContext()->IsOffTheRecord(), | 118 item->GetReceivedBytes(), item->GetBrowserContext()->IsOffTheRecord(), |
119 item->GetState(), item->PercentComplete(), item->IsPaused(), | 119 item->GetState(), item->PercentComplete(), item->IsPaused(), |
120 has_user_gesture, item->CanResume(), | 120 has_user_gesture, item->CanResume(), |
121 ConvertUTF8ToJavaString(env, original_url), | 121 ConvertUTF8ToJavaString(env, original_url), |
122 ConvertUTF8ToJavaString(env, item->GetReferrerUrl().spec()), | 122 ConvertUTF8ToJavaString(env, item->GetReferrerUrl().spec()), |
123 time_remaining_known ? time_delta.InMilliseconds() | 123 time_remaining_known ? time_delta.InMilliseconds() |
124 : kUnknownRemainingTime); | 124 : kUnknownRemainingTime, |
| 125 item->GetLastAccessTime().ToJavaTime()); |
125 } | 126 } |
126 | 127 |
127 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& jobj) { | 128 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& jobj) { |
128 Profile* profile = ProfileManager::GetActiveUserProfile(); | 129 Profile* profile = ProfileManager::GetActiveUserProfile(); |
129 DownloadManagerService* service = DownloadManagerService::GetInstance(); | 130 DownloadManagerService* service = DownloadManagerService::GetInstance(); |
130 service->Init(env, jobj); | 131 service->Init(env, jobj); |
131 DownloadService* download_service = | 132 DownloadService* download_service = |
132 DownloadServiceFactory::GetForBrowserContext(profile); | 133 DownloadServiceFactory::GetForBrowserContext(profile); |
133 DownloadHistory* history = download_service->GetDownloadHistory(); | 134 DownloadHistory* history = download_service->GetDownloadHistory(); |
134 if (history) | 135 if (history) |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 // requests to check for externally removed downloads. | 233 // requests to check for externally removed downloads. |
233 if (!is_history_query_complete_) | 234 if (!is_history_query_complete_) |
234 return; | 235 return; |
235 | 236 |
236 content::DownloadManager* manager = GetDownloadManager(is_off_the_record); | 237 content::DownloadManager* manager = GetDownloadManager(is_off_the_record); |
237 if (!manager) | 238 if (!manager) |
238 return; | 239 return; |
239 manager->CheckForHistoryFilesRemoval(); | 240 manager->CheckForHistoryFilesRemoval(); |
240 } | 241 } |
241 | 242 |
| 243 void DownloadManagerService::UpdateLastAccessTime( |
| 244 JNIEnv* env, |
| 245 const JavaParamRef<jobject>& obj, |
| 246 const JavaParamRef<jstring>& jdownload_guid, |
| 247 bool is_off_the_record) { |
| 248 std::string download_guid = ConvertJavaStringToUTF8(env, jdownload_guid); |
| 249 content::DownloadManager* manager = GetDownloadManager(is_off_the_record); |
| 250 if (!manager) |
| 251 return; |
| 252 |
| 253 content::DownloadItem* item = manager->GetDownloadByGuid(download_guid); |
| 254 if (item) |
| 255 item->SetLastAccessTime(base::Time::Now()); |
| 256 } |
| 257 |
242 void DownloadManagerService::CancelDownload( | 258 void DownloadManagerService::CancelDownload( |
243 JNIEnv* env, | 259 JNIEnv* env, |
244 jobject obj, | 260 jobject obj, |
245 const JavaParamRef<jstring>& jdownload_guid, | 261 const JavaParamRef<jstring>& jdownload_guid, |
246 bool is_off_the_record, | 262 bool is_off_the_record, |
247 bool is_notification_dismissed) { | 263 bool is_notification_dismissed) { |
248 std::string download_guid = ConvertJavaStringToUTF8(env, jdownload_guid); | 264 std::string download_guid = ConvertJavaStringToUTF8(env, jdownload_guid); |
249 DownloadController::RecordDownloadCancelReason( | 265 DownloadController::RecordDownloadCancelReason( |
250 is_notification_dismissed ? | 266 is_notification_dismissed ? |
251 DownloadController::CANCEL_REASON_NOTIFICATION_DISMISSED : | 267 DownloadController::CANCEL_REASON_NOTIFICATION_DISMISSED : |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 chrome::android::kDownloadAutoResumptionThrottling, | 477 chrome::android::kDownloadAutoResumptionThrottling, |
462 kAutoResumptionLimitVariation); | 478 kAutoResumptionLimitVariation); |
463 int auto_resumption_limit; | 479 int auto_resumption_limit; |
464 if (!variation.empty() && | 480 if (!variation.empty() && |
465 base::StringToInt(variation, &auto_resumption_limit)) { | 481 base::StringToInt(variation, &auto_resumption_limit)) { |
466 return auto_resumption_limit; | 482 return auto_resumption_limit; |
467 } | 483 } |
468 | 484 |
469 return kDefaultAutoResumptionLimit; | 485 return kDefaultAutoResumptionLimit; |
470 } | 486 } |
OLD | NEW |