Chromium Code Reviews| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 ui::PAGE_TRANSITION_AUTO_BOOKMARK) || | 88 ui::PAGE_TRANSITION_AUTO_BOOKMARK) || |
| 89 PageTransitionCoreTypeIs(item->GetTransitionType(), | 89 PageTransitionCoreTypeIs(item->GetTransitionType(), |
| 90 ui::PAGE_TRANSITION_GENERATED) || | 90 ui::PAGE_TRANSITION_GENERATED) || |
| 91 PageTransitionCoreTypeIs(item->GetTransitionType(), | 91 PageTransitionCoreTypeIs(item->GetTransitionType(), |
| 92 ui::PAGE_TRANSITION_RELOAD) || | 92 ui::PAGE_TRANSITION_RELOAD) || |
| 93 PageTransitionCoreTypeIs(item->GetTransitionType(), | 93 PageTransitionCoreTypeIs(item->GetTransitionType(), |
| 94 ui::PAGE_TRANSITION_KEYWORD); | 94 ui::PAGE_TRANSITION_KEYWORD); |
| 95 bool has_user_gesture = item->HasUserGesture() || user_initiated; | 95 bool has_user_gesture = item->HasUserGesture() || user_initiated; |
| 96 | 96 |
| 97 base::TimeDelta time_delta; | 97 base::TimeDelta time_delta; |
| 98 item->TimeRemaining(&time_delta); | 98 bool time_remaining_known = item->TimeRemaining(&time_delta); |
| 99 std::string original_url = item->GetOriginalUrl().SchemeIs(url::kDataScheme) | 99 std::string original_url = item->GetOriginalUrl().SchemeIs(url::kDataScheme) |
| 100 ? std::string() : item->GetOriginalUrl().spec(); | 100 ? std::string() : item->GetOriginalUrl().spec(); |
| 101 return Java_DownloadInfo_createDownloadInfo( | 101 return Java_DownloadInfo_createDownloadInfo( |
| 102 env, | 102 env, ConvertUTF8ToJavaString(env, item->GetGuid()), |
| 103 ConvertUTF8ToJavaString(env, item->GetGuid()), | 103 ConvertUTF8ToJavaString(env, item->GetFileNameToReportUser().value()), |
| 104 ConvertUTF8ToJavaString(env, | |
| 105 item->GetFileNameToReportUser().value()), | |
| 106 ConvertUTF8ToJavaString(env, item->GetTargetFilePath().value()), | 104 ConvertUTF8ToJavaString(env, item->GetTargetFilePath().value()), |
| 107 ConvertUTF8ToJavaString(env, item->GetTabUrl().spec()), | 105 ConvertUTF8ToJavaString(env, item->GetTabUrl().spec()), |
| 108 ConvertUTF8ToJavaString(env, item->GetMimeType()), | 106 ConvertUTF8ToJavaString(env, item->GetMimeType()), |
| 109 item->GetReceivedBytes(), | 107 item->GetReceivedBytes(), item->GetBrowserContext()->IsOffTheRecord(), |
| 110 item->GetBrowserContext()->IsOffTheRecord(), | 108 item->GetState(), item->PercentComplete(), item->IsPaused(), |
| 111 item->GetState(), | 109 has_user_gesture, item->CanResume(), |
| 112 item->PercentComplete(), | |
| 113 item->IsPaused(), | |
| 114 has_user_gesture, | |
| 115 item->CanResume(), | |
| 116 ConvertUTF8ToJavaString(env, original_url), | 110 ConvertUTF8ToJavaString(env, original_url), |
| 117 ConvertUTF8ToJavaString(env, item->GetReferrerUrl().spec()), | 111 ConvertUTF8ToJavaString(env, item->GetReferrerUrl().spec()), |
| 118 time_delta.InMilliseconds()); | 112 time_remaining_known ? time_delta.InMilliseconds() : -1); |
|
qinmin
2017/01/25 18:21:51
define a constant here: kUnknownRemainingTime, e.g
shaktisahu
2017/01/25 19:24:56
Done.
| |
| 119 } | 113 } |
| 120 | 114 |
| 121 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& jobj) { | 115 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& jobj) { |
| 122 Profile* profile = ProfileManager::GetActiveUserProfile(); | 116 Profile* profile = ProfileManager::GetActiveUserProfile(); |
| 123 DownloadManagerService* service = DownloadManagerService::GetInstance(); | 117 DownloadManagerService* service = DownloadManagerService::GetInstance(); |
| 124 service->Init(env, jobj); | 118 service->Init(env, jobj); |
| 125 DownloadService* download_service = | 119 DownloadService* download_service = |
| 126 DownloadServiceFactory::GetForBrowserContext(profile); | 120 DownloadServiceFactory::GetForBrowserContext(profile); |
| 127 DownloadHistory* history = download_service->GetDownloadHistory(); | 121 DownloadHistory* history = download_service->GetDownloadHistory(); |
| 128 if (history) | 122 if (history) |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 440 } | 434 } |
| 441 | 435 |
| 442 // static | 436 // static |
| 443 jboolean IsSupportedMimeType( | 437 jboolean IsSupportedMimeType( |
| 444 JNIEnv* env, | 438 JNIEnv* env, |
| 445 const JavaParamRef<jclass>& clazz, | 439 const JavaParamRef<jclass>& clazz, |
| 446 const JavaParamRef<jstring>& jmime_type) { | 440 const JavaParamRef<jstring>& jmime_type) { |
| 447 std::string mime_type = ConvertJavaStringToUTF8(env, jmime_type); | 441 std::string mime_type = ConvertJavaStringToUTF8(env, jmime_type); |
| 448 return mime_util::IsSupportedMimeType(mime_type); | 442 return mime_util::IsSupportedMimeType(mime_type); |
| 449 } | 443 } |
| OLD | NEW |