Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(730)

Side by Side Diff: chrome/browser/ui/webui/offline/offline_internals_ui_message_handler.cc

Issue 2328973003: Adds a delete button to chrome:offline-internals (Closed)
Patch Set: CR feedback per BauerB Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/webui/offline/offline_internals_ui_message_handler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 29 matching lines...) Expand all
40 return "Device failure"; 40 return "Device failure";
41 case offline_pages::DeletePageResult::NOT_FOUND: 41 case offline_pages::DeletePageResult::NOT_FOUND:
42 return "Not found"; 42 return "Not found";
43 case offline_pages::DeletePageResult::RESULT_COUNT: 43 case offline_pages::DeletePageResult::RESULT_COUNT:
44 break; 44 break;
45 } 45 }
46 NOTREACHED(); 46 NOTREACHED();
47 return "Unknown"; 47 return "Unknown";
48 } 48 }
49 49
50 std::string OfflineInternalsUIMessageHandler::GetStringFromDeleteRequestResults(
51 const offline_pages::RequestQueue::UpdateMultipleRequestResults& results) {
52 // If any requests failed, return "failure", else "success".
53 for (const auto& result : results) {
54 if (result.second ==
55 offline_pages::RequestQueue::UpdateRequestResult::STORE_FAILURE) {
56 return "Store failure, could not delete one or more requests";
57 }
58 }
59
60 return "Success";
61 }
62
50 std::string OfflineInternalsUIMessageHandler::GetStringFromSavePageStatus() { 63 std::string OfflineInternalsUIMessageHandler::GetStringFromSavePageStatus() {
51 return "Available"; 64 return "Available";
52 } 65 }
53 66
54 void OfflineInternalsUIMessageHandler::HandleDeleteAllPages( 67 void OfflineInternalsUIMessageHandler::HandleDeleteAllPages(
55 const base::ListValue* args) { 68 const base::ListValue* args) {
56 std::string callback_id; 69 std::string callback_id;
57 CHECK(args->GetString(0, &callback_id)); 70 CHECK(args->GetString(0, &callback_id));
58 71
59 // Pass back success because ClearAll doesn't return a status. 72 // Pass back success because ClearAll doesn't return a status.
(...skipping 19 matching lines...) Expand all
79 base::StringToInt64(value, &int_value); 92 base::StringToInt64(value, &int_value);
80 offline_ids.push_back(int_value); 93 offline_ids.push_back(int_value);
81 } 94 }
82 95
83 offline_page_model_->DeletePagesByOfflineId( 96 offline_page_model_->DeletePagesByOfflineId(
84 offline_ids, 97 offline_ids,
85 base::Bind(&OfflineInternalsUIMessageHandler::HandleDeletedPagesCallback, 98 base::Bind(&OfflineInternalsUIMessageHandler::HandleDeletedPagesCallback,
86 weak_ptr_factory_.GetWeakPtr(), callback_id)); 99 weak_ptr_factory_.GetWeakPtr(), callback_id));
87 } 100 }
88 101
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(
117 const base::ListValue* args) {
118 std::string callback_id;
119 CHECK(args->GetString(0, &callback_id));
120
121 std::vector<int64_t> offline_ids;
122 const base::ListValue* offline_ids_from_arg = nullptr;
123 args->GetList(1, &offline_ids_from_arg);
124
125 for (size_t i = 0; i < offline_ids_from_arg->GetSize(); i++) {
126 std::string value;
127 offline_ids_from_arg->GetString(i, &value);
128 int64_t int_value;
129 base::StringToInt64(value, &int_value);
130 offline_ids.push_back(int_value);
131 }
132
133 // Call RequestCoordinator to delete them
134 if (request_coordinator_) {
135 request_coordinator_->RemoveRequests(
136 offline_ids,
137 base::Bind(
138 &OfflineInternalsUIMessageHandler::HandleDeletedRequestsCallback,
139 weak_ptr_factory_.GetWeakPtr(), callback_id));
140 }
141 }
142
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
89 void OfflineInternalsUIMessageHandler::HandleDeletedPagesCallback( 162 void OfflineInternalsUIMessageHandler::HandleDeletedPagesCallback(
90 std::string callback_id, 163 std::string callback_id,
91 offline_pages::DeletePageResult result) { 164 offline_pages::DeletePageResult result) {
92 ResolveJavascriptCallback( 165 ResolveJavascriptCallback(
93 base::StringValue(callback_id), 166 base::StringValue(callback_id),
94 base::StringValue(GetStringFromDeletePageResult(result))); 167 base::StringValue(GetStringFromDeletePageResult(result)));
95 } 168 }
96 169
170 void OfflineInternalsUIMessageHandler::HandleDeletedRequestsCallback(
171 std::string callback_id,
172 const offline_pages::RequestQueue::UpdateMultipleRequestResults& results) {
173 ResolveJavascriptCallback(
174 base::StringValue(callback_id),
175 base::StringValue(GetStringFromDeleteRequestResults(results)));
176 }
177
97 void OfflineInternalsUIMessageHandler::HandleStoredPagesCallback( 178 void OfflineInternalsUIMessageHandler::HandleStoredPagesCallback(
98 std::string callback_id, 179 std::string callback_id,
99 const offline_pages::MultipleOfflinePageItemResult& pages) { 180 const offline_pages::MultipleOfflinePageItemResult& pages) {
100 base::ListValue results; 181 base::ListValue results;
101 182
102 for (const auto& page : pages) { 183 for (const auto& page : pages) {
103 base::DictionaryValue* offline_page = new base::DictionaryValue(); 184 base::DictionaryValue* offline_page = new base::DictionaryValue();
104 results.Append(offline_page); 185 results.Append(offline_page);
105 offline_page->SetString("onlineUrl", page.url.spec()); 186 offline_page->SetString("onlineUrl", page.url.spec());
106 offline_page->SetString("namespace", page.client_id.name_space); 187 offline_page->SetString("namespace", page.client_id.name_space);
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 void OfflineInternalsUIMessageHandler::RegisterMessages() { 343 void OfflineInternalsUIMessageHandler::RegisterMessages() {
263 web_ui()->RegisterMessageCallback( 344 web_ui()->RegisterMessageCallback(
264 "deleteAllPages", 345 "deleteAllPages",
265 base::Bind(&OfflineInternalsUIMessageHandler::HandleDeleteAllPages, 346 base::Bind(&OfflineInternalsUIMessageHandler::HandleDeleteAllPages,
266 weak_ptr_factory_.GetWeakPtr())); 347 weak_ptr_factory_.GetWeakPtr()));
267 web_ui()->RegisterMessageCallback( 348 web_ui()->RegisterMessageCallback(
268 "deleteSelectedPages", 349 "deleteSelectedPages",
269 base::Bind(&OfflineInternalsUIMessageHandler::HandleDeleteSelectedPages, 350 base::Bind(&OfflineInternalsUIMessageHandler::HandleDeleteSelectedPages,
270 weak_ptr_factory_.GetWeakPtr())); 351 weak_ptr_factory_.GetWeakPtr()));
271 web_ui()->RegisterMessageCallback( 352 web_ui()->RegisterMessageCallback(
353 "deleteAllRequests",
354 base::Bind(&OfflineInternalsUIMessageHandler::HandleDeleteAllRequests,
355 weak_ptr_factory_.GetWeakPtr()));
356 web_ui()->RegisterMessageCallback(
357 "deleteSelectedRequests",
358 base::Bind(
359 &OfflineInternalsUIMessageHandler::HandleDeleteSelectedRequests,
360 weak_ptr_factory_.GetWeakPtr()));
361 web_ui()->RegisterMessageCallback(
272 "getRequestQueue", 362 "getRequestQueue",
273 base::Bind(&OfflineInternalsUIMessageHandler::HandleGetRequestQueue, 363 base::Bind(&OfflineInternalsUIMessageHandler::HandleGetRequestQueue,
274 weak_ptr_factory_.GetWeakPtr())); 364 weak_ptr_factory_.GetWeakPtr()));
275 web_ui()->RegisterMessageCallback( 365 web_ui()->RegisterMessageCallback(
276 "getStoredPages", 366 "getStoredPages",
277 base::Bind(&OfflineInternalsUIMessageHandler::HandleGetStoredPages, 367 base::Bind(&OfflineInternalsUIMessageHandler::HandleGetStoredPages,
278 weak_ptr_factory_.GetWeakPtr())); 368 weak_ptr_factory_.GetWeakPtr()));
279 web_ui()->RegisterMessageCallback( 369 web_ui()->RegisterMessageCallback(
280 "getEventLogs", 370 "getEventLogs",
281 base::Bind(&OfflineInternalsUIMessageHandler::HandleGetEventLogs, 371 base::Bind(&OfflineInternalsUIMessageHandler::HandleGetEventLogs,
(...skipping 21 matching lines...) Expand all
303 393
304 // Get the offline page model associated with this web ui. 394 // Get the offline page model associated with this web ui.
305 Profile* profile = Profile::FromWebUI(web_ui()); 395 Profile* profile = Profile::FromWebUI(web_ui());
306 offline_page_model_ = 396 offline_page_model_ =
307 offline_pages::OfflinePageModelFactory::GetForBrowserContext(profile); 397 offline_pages::OfflinePageModelFactory::GetForBrowserContext(profile);
308 request_coordinator_ = 398 request_coordinator_ =
309 offline_pages::RequestCoordinatorFactory::GetForBrowserContext(profile); 399 offline_pages::RequestCoordinatorFactory::GetForBrowserContext(profile);
310 } 400 }
311 401
312 } // namespace offline_internals 402 } // namespace offline_internals
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/offline/offline_internals_ui_message_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698