| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/offline_pages/downloads/offline_page_download_b
ridge.h" | 5 #include "chrome/browser/android/offline_pages/downloads/offline_page_download_b
ridge.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 const DownloadUIItem& item) { | 62 const DownloadUIItem& item) { |
| 63 return Java_OfflinePageDownloadBridge_createDownloadItem( | 63 return Java_OfflinePageDownloadBridge_createDownloadItem( |
| 64 env, ConvertUTF8ToJavaString(env, item.guid), | 64 env, ConvertUTF8ToJavaString(env, item.guid), |
| 65 ConvertUTF8ToJavaString(env, item.url.spec()), | 65 ConvertUTF8ToJavaString(env, item.url.spec()), |
| 66 ConvertUTF16ToJavaString(env, item.title), | 66 ConvertUTF16ToJavaString(env, item.title), |
| 67 ConvertUTF8ToJavaString(env, item.target_path.value()), | 67 ConvertUTF8ToJavaString(env, item.target_path.value()), |
| 68 item.start_time.ToJavaTime(), item.total_bytes); | 68 item.start_time.ToJavaTime(), item.total_bytes); |
| 69 } | 69 } |
| 70 | 70 |
| 71 std::vector<int64_t> FilterRequestsByGuid( | 71 std::vector<int64_t> FilterRequestsByGuid( |
| 72 const std::vector<SavePageRequest>& requests, | 72 std::vector<std::unique_ptr<SavePageRequest>> requests, |
| 73 const std::string& guid) { | 73 const std::string& guid) { |
| 74 std::vector<int64_t> request_ids; | 74 std::vector<int64_t> request_ids; |
| 75 for (const SavePageRequest& request : requests) { | 75 for (const auto& request : requests) { |
| 76 if (request.client_id().id == guid && | 76 if (request->client_id().id == guid && |
| 77 (request.client_id().name_space == kDownloadNamespace || | 77 (request->client_id().name_space == kDownloadNamespace || |
| 78 request.client_id().name_space == kAsyncNamespace)) { | 78 request->client_id().name_space == kAsyncNamespace)) { |
| 79 request_ids.push_back(request.request_id()); | 79 request_ids.push_back(request->request_id()); |
| 80 } | 80 } |
| 81 } | 81 } |
| 82 return request_ids; | 82 return request_ids; |
| 83 } | 83 } |
| 84 | 84 |
| 85 void CancelRequestCallback(const RequestQueue::UpdateMultipleRequestResults&) { | 85 void CancelRequestCallback(const RequestQueue::UpdateMultipleRequestResults&) { |
| 86 // Results ignored here, as UI uses observer to update itself. | 86 // Results ignored here, as UI uses observer to update itself. |
| 87 } | 87 } |
| 88 | 88 |
| 89 void CancelRequestsContinuation(content::BrowserContext* browser_context, | 89 void CancelRequestsContinuation( |
| 90 const std::string& guid, | 90 content::BrowserContext* browser_context, |
| 91 const std::vector<SavePageRequest>& requests) { | 91 const std::string& guid, |
| 92 std::vector<std::unique_ptr<SavePageRequest>> requests) { |
| 92 RequestCoordinator* coordinator = | 93 RequestCoordinator* coordinator = |
| 93 RequestCoordinatorFactory::GetForBrowserContext(browser_context); | 94 RequestCoordinatorFactory::GetForBrowserContext(browser_context); |
| 94 if (coordinator) { | 95 if (coordinator) { |
| 95 std::vector<int64_t> request_ids = FilterRequestsByGuid(requests, guid); | 96 std::vector<int64_t> request_ids = |
| 97 FilterRequestsByGuid(std::move(requests), guid); |
| 96 coordinator->RemoveRequests(request_ids, | 98 coordinator->RemoveRequests(request_ids, |
| 97 base::Bind(&CancelRequestCallback)); | 99 base::Bind(&CancelRequestCallback)); |
| 98 } else { | 100 } else { |
| 99 LOG(WARNING) << "CancelRequestsContinuation has no valid coordinator."; | 101 LOG(WARNING) << "CancelRequestsContinuation has no valid coordinator."; |
| 100 } | 102 } |
| 101 } | 103 } |
| 102 | 104 |
| 103 void PauseRequestsContinuation(content::BrowserContext* browser_context, | 105 void PauseRequestsContinuation( |
| 104 const std::string& guid, | 106 content::BrowserContext* browser_context, |
| 105 const std::vector<SavePageRequest>& requests) { | 107 const std::string& guid, |
| 108 std::vector<std::unique_ptr<SavePageRequest>> requests) { |
| 106 RequestCoordinator* coordinator = | 109 RequestCoordinator* coordinator = |
| 107 RequestCoordinatorFactory::GetForBrowserContext(browser_context); | 110 RequestCoordinatorFactory::GetForBrowserContext(browser_context); |
| 108 if (coordinator) | 111 if (coordinator) |
| 109 coordinator->PauseRequests(FilterRequestsByGuid(requests, guid)); | 112 coordinator->PauseRequests(FilterRequestsByGuid(std::move(requests), guid)); |
| 110 else | 113 else |
| 111 LOG(WARNING) << "PauseRequestsContinuation has no valid coordinator."; | 114 LOG(WARNING) << "PauseRequestsContinuation has no valid coordinator."; |
| 112 } | 115 } |
| 113 | 116 |
| 114 void ResumeRequestsContinuation(content::BrowserContext* browser_context, | 117 void ResumeRequestsContinuation( |
| 115 const std::string& guid, | 118 content::BrowserContext* browser_context, |
| 116 const std::vector<SavePageRequest>& requests) { | 119 const std::string& guid, |
| 120 std::vector<std::unique_ptr<SavePageRequest>> requests) { |
| 117 RequestCoordinator* coordinator = | 121 RequestCoordinator* coordinator = |
| 118 RequestCoordinatorFactory::GetForBrowserContext(browser_context); | 122 RequestCoordinatorFactory::GetForBrowserContext(browser_context); |
| 119 if (coordinator) | 123 if (coordinator) |
| 120 coordinator->ResumeRequests(FilterRequestsByGuid(requests, guid)); | 124 coordinator->ResumeRequests( |
| 125 FilterRequestsByGuid(std::move(requests), guid)); |
| 121 else | 126 else |
| 122 LOG(WARNING) << "ResumeRequestsContinuation has no valid coordinator."; | 127 LOG(WARNING) << "ResumeRequestsContinuation has no valid coordinator."; |
| 123 } | 128 } |
| 124 | 129 |
| 125 } // namespace | 130 } // namespace |
| 126 | 131 |
| 127 OfflinePageDownloadBridge::OfflinePageDownloadBridge( | 132 OfflinePageDownloadBridge::OfflinePageDownloadBridge( |
| 128 JNIEnv* env, | 133 JNIEnv* env, |
| 129 const JavaParamRef<jobject>& obj, | 134 const JavaParamRef<jobject>& obj, |
| 130 DownloadUIAdapter* download_ui_adapter, | 135 DownloadUIAdapter* download_ui_adapter, |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 | 357 |
| 353 DownloadUIAdapter* adapter = | 358 DownloadUIAdapter* adapter = |
| 354 DownloadUIAdapter::FromOfflinePageModel(offline_page_model); | 359 DownloadUIAdapter::FromOfflinePageModel(offline_page_model); |
| 355 | 360 |
| 356 return reinterpret_cast<jlong>( | 361 return reinterpret_cast<jlong>( |
| 357 new OfflinePageDownloadBridge(env, obj, adapter, browser_context)); | 362 new OfflinePageDownloadBridge(env, obj, adapter, browser_context)); |
| 358 } | 363 } |
| 359 | 364 |
| 360 } // namespace android | 365 } // namespace android |
| 361 } // namespace offline_pages | 366 } // namespace offline_pages |
| OLD | NEW |