| 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/ui/webui/offline/offline_internals_ui_message_handler.h
" | 5 #include "chrome/browser/ui/webui/offline/offline_internals_ui_message_handler.h
" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 | 59 |
| 60 return "Success"; | 60 return "Success"; |
| 61 } | 61 } |
| 62 | 62 |
| 63 std::string OfflineInternalsUIMessageHandler::GetStringFromSavePageStatus() { | 63 std::string OfflineInternalsUIMessageHandler::GetStringFromSavePageStatus() { |
| 64 return "Available"; | 64 return "Available"; |
| 65 } | 65 } |
| 66 | 66 |
| 67 void OfflineInternalsUIMessageHandler::HandleDeleteAllPages( | |
| 68 const base::ListValue* args) { | |
| 69 std::string callback_id; | |
| 70 CHECK(args->GetString(0, &callback_id)); | |
| 71 | |
| 72 // Pass back success because ClearAll doesn't return a status. | |
| 73 offline_page_model_->ClearAll( | |
| 74 base::Bind(&OfflineInternalsUIMessageHandler::HandleDeletedPagesCallback, | |
| 75 weak_ptr_factory_.GetWeakPtr(), callback_id, | |
| 76 offline_pages::DeletePageResult::SUCCESS)); | |
| 77 } | |
| 78 | |
| 79 void OfflineInternalsUIMessageHandler::HandleDeleteSelectedPages( | 67 void OfflineInternalsUIMessageHandler::HandleDeleteSelectedPages( |
| 80 const base::ListValue* args) { | 68 const base::ListValue* args) { |
| 81 std::string callback_id; | 69 std::string callback_id; |
| 82 CHECK(args->GetString(0, &callback_id)); | 70 CHECK(args->GetString(0, &callback_id)); |
| 83 | 71 |
| 84 std::vector<int64_t> offline_ids; | 72 std::vector<int64_t> offline_ids; |
| 85 const base::ListValue* offline_ids_from_arg; | 73 const base::ListValue* offline_ids_from_arg; |
| 86 args->GetList(1, &offline_ids_from_arg); | 74 args->GetList(1, &offline_ids_from_arg); |
| 87 | 75 |
| 88 for (size_t i = 0; i < offline_ids_from_arg->GetSize(); i++) { | 76 for (size_t i = 0; i < offline_ids_from_arg->GetSize(); i++) { |
| 89 std::string value; | 77 std::string value; |
| 90 offline_ids_from_arg->GetString(i, &value); | 78 offline_ids_from_arg->GetString(i, &value); |
| 91 int64_t int_value; | 79 int64_t int_value; |
| 92 base::StringToInt64(value, &int_value); | 80 base::StringToInt64(value, &int_value); |
| 93 offline_ids.push_back(int_value); | 81 offline_ids.push_back(int_value); |
| 94 } | 82 } |
| 95 | 83 |
| 96 offline_page_model_->DeletePagesByOfflineId( | 84 offline_page_model_->DeletePagesByOfflineId( |
| 97 offline_ids, | 85 offline_ids, |
| 98 base::Bind(&OfflineInternalsUIMessageHandler::HandleDeletedPagesCallback, | 86 base::Bind(&OfflineInternalsUIMessageHandler::HandleDeletedPagesCallback, |
| 99 weak_ptr_factory_.GetWeakPtr(), callback_id)); | 87 weak_ptr_factory_.GetWeakPtr(), callback_id)); |
| 100 } | 88 } |
| 101 | 89 |
| 102 void OfflineInternalsUIMessageHandler::HandleDeleteAllRequests( | |
| 103 const base::ListValue* args) { | |
| 104 std::string callback_id; | |
| 105 CHECK(args->GetString(0, &callback_id)); | |
| 106 // First do a get, then in the callback, build a list of IDs, and | |
| 107 // call RemoveRequests with that list. | |
| 108 if (request_coordinator_) { | |
| 109 request_coordinator_->GetAllRequests( | |
| 110 base::Bind(&OfflineInternalsUIMessageHandler:: | |
| 111 HandleGetAllRequestsForDeleteCallback, | |
| 112 weak_ptr_factory_.GetWeakPtr(), callback_id)); | |
| 113 } | |
| 114 } | |
| 115 | |
| 116 void OfflineInternalsUIMessageHandler::HandleDeleteSelectedRequests( | 90 void OfflineInternalsUIMessageHandler::HandleDeleteSelectedRequests( |
| 117 const base::ListValue* args) { | 91 const base::ListValue* args) { |
| 118 std::string callback_id; | 92 std::string callback_id; |
| 119 CHECK(args->GetString(0, &callback_id)); | 93 CHECK(args->GetString(0, &callback_id)); |
| 120 | 94 |
| 121 std::vector<int64_t> offline_ids; | 95 std::vector<int64_t> offline_ids; |
| 122 const base::ListValue* offline_ids_from_arg = nullptr; | 96 const base::ListValue* offline_ids_from_arg = nullptr; |
| 123 args->GetList(1, &offline_ids_from_arg); | 97 args->GetList(1, &offline_ids_from_arg); |
| 124 | 98 |
| 125 for (size_t i = 0; i < offline_ids_from_arg->GetSize(); i++) { | 99 for (size_t i = 0; i < offline_ids_from_arg->GetSize(); i++) { |
| 126 std::string value; | 100 std::string value; |
| 127 offline_ids_from_arg->GetString(i, &value); | 101 offline_ids_from_arg->GetString(i, &value); |
| 128 int64_t int_value; | 102 int64_t int_value; |
| 129 base::StringToInt64(value, &int_value); | 103 base::StringToInt64(value, &int_value); |
| 130 offline_ids.push_back(int_value); | 104 offline_ids.push_back(int_value); |
| 131 } | 105 } |
| 132 | 106 |
| 133 // Call RequestCoordinator to delete them | 107 // Call RequestCoordinator to delete them |
| 134 if (request_coordinator_) { | 108 if (request_coordinator_) { |
| 135 request_coordinator_->RemoveRequests( | 109 request_coordinator_->RemoveRequests( |
| 136 offline_ids, | 110 offline_ids, |
| 137 base::Bind( | 111 base::Bind( |
| 138 &OfflineInternalsUIMessageHandler::HandleDeletedRequestsCallback, | 112 &OfflineInternalsUIMessageHandler::HandleDeletedRequestsCallback, |
| 139 weak_ptr_factory_.GetWeakPtr(), callback_id)); | 113 weak_ptr_factory_.GetWeakPtr(), callback_id)); |
| 140 } | 114 } |
| 141 } | 115 } |
| 142 | 116 |
| 143 void OfflineInternalsUIMessageHandler::HandleGetAllRequestsForDeleteCallback( | |
| 144 std::string callback_id, | |
| 145 std::vector<std::unique_ptr<offline_pages::SavePageRequest>> requests) { | |
| 146 std::vector<int64_t> offline_ids; | |
| 147 // Build a list of offline_ids from the requests. | |
| 148 for (const auto& request : requests) { | |
| 149 offline_ids.push_back(request->request_id()); | |
| 150 } | |
| 151 | |
| 152 // Call RequestCoordinator to delete them | |
| 153 if (request_coordinator_) { | |
| 154 request_coordinator_->RemoveRequests( | |
| 155 offline_ids, | |
| 156 base::Bind( | |
| 157 &OfflineInternalsUIMessageHandler::HandleDeletedRequestsCallback, | |
| 158 weak_ptr_factory_.GetWeakPtr(), callback_id)); | |
| 159 } | |
| 160 } | |
| 161 | |
| 162 void OfflineInternalsUIMessageHandler::HandleDeletedPagesCallback( | 117 void OfflineInternalsUIMessageHandler::HandleDeletedPagesCallback( |
| 163 std::string callback_id, | 118 std::string callback_id, |
| 164 offline_pages::DeletePageResult result) { | 119 offline_pages::DeletePageResult result) { |
| 165 ResolveJavascriptCallback( | 120 ResolveJavascriptCallback( |
| 166 base::StringValue(callback_id), | 121 base::StringValue(callback_id), |
| 167 base::StringValue(GetStringFromDeletePageResult(result))); | 122 base::StringValue(GetStringFromDeletePageResult(result))); |
| 168 } | 123 } |
| 169 | 124 |
| 170 void OfflineInternalsUIMessageHandler::HandleDeletedRequestsCallback( | 125 void OfflineInternalsUIMessageHandler::HandleDeletedRequestsCallback( |
| 171 std::string callback_id, | 126 std::string callback_id, |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 | 348 |
| 394 // Get the offline page model associated with this web ui. | 349 // Get the offline page model associated with this web ui. |
| 395 Profile* profile = Profile::FromWebUI(web_ui()); | 350 Profile* profile = Profile::FromWebUI(web_ui()); |
| 396 offline_page_model_ = | 351 offline_page_model_ = |
| 397 offline_pages::OfflinePageModelFactory::GetForBrowserContext(profile); | 352 offline_pages::OfflinePageModelFactory::GetForBrowserContext(profile); |
| 398 request_coordinator_ = | 353 request_coordinator_ = |
| 399 offline_pages::RequestCoordinatorFactory::GetForBrowserContext(profile); | 354 offline_pages::RequestCoordinatorFactory::GetForBrowserContext(profile); |
| 400 } | 355 } |
| 401 | 356 |
| 402 } // namespace offline_internals | 357 } // namespace offline_internals |
| OLD | NEW |