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

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

Issue 2342603004: [Offline pages] Clean up unnecessary DeleteAll calls in offline internals (Closed)
Patch Set: update id in js and remove references to deleted methods 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 GURL(url), offline_pages::ClientId(offline_pages::kAsyncNamespace, 290 GURL(url), offline_pages::ClientId(offline_pages::kAsyncNamespace,
336 id_stream.str()), 291 id_stream.str()),
337 true))); 292 true)));
338 } else { 293 } else {
339 ResolveJavascriptCallback(*callback_id, base::FundamentalValue(false)); 294 ResolveJavascriptCallback(*callback_id, base::FundamentalValue(false));
340 } 295 }
341 } 296 }
342 297
343 void OfflineInternalsUIMessageHandler::RegisterMessages() { 298 void OfflineInternalsUIMessageHandler::RegisterMessages() {
344 web_ui()->RegisterMessageCallback( 299 web_ui()->RegisterMessageCallback(
345 "deleteAllPages",
346 base::Bind(&OfflineInternalsUIMessageHandler::HandleDeleteAllPages,
347 weak_ptr_factory_.GetWeakPtr()));
348 web_ui()->RegisterMessageCallback(
349 "deleteSelectedPages", 300 "deleteSelectedPages",
350 base::Bind(&OfflineInternalsUIMessageHandler::HandleDeleteSelectedPages, 301 base::Bind(&OfflineInternalsUIMessageHandler::HandleDeleteSelectedPages,
351 weak_ptr_factory_.GetWeakPtr())); 302 weak_ptr_factory_.GetWeakPtr()));
352 web_ui()->RegisterMessageCallback( 303 web_ui()->RegisterMessageCallback(
353 "deleteAllRequests",
354 base::Bind(&OfflineInternalsUIMessageHandler::HandleDeleteAllRequests,
355 weak_ptr_factory_.GetWeakPtr()));
356 web_ui()->RegisterMessageCallback(
357 "deleteSelectedRequests", 304 "deleteSelectedRequests",
358 base::Bind( 305 base::Bind(
359 &OfflineInternalsUIMessageHandler::HandleDeleteSelectedRequests, 306 &OfflineInternalsUIMessageHandler::HandleDeleteSelectedRequests,
360 weak_ptr_factory_.GetWeakPtr())); 307 weak_ptr_factory_.GetWeakPtr()));
361 web_ui()->RegisterMessageCallback( 308 web_ui()->RegisterMessageCallback(
362 "getRequestQueue", 309 "getRequestQueue",
363 base::Bind(&OfflineInternalsUIMessageHandler::HandleGetRequestQueue, 310 base::Bind(&OfflineInternalsUIMessageHandler::HandleGetRequestQueue,
364 weak_ptr_factory_.GetWeakPtr())); 311 weak_ptr_factory_.GetWeakPtr()));
365 web_ui()->RegisterMessageCallback( 312 web_ui()->RegisterMessageCallback(
366 "getStoredPages", 313 "getStoredPages",
(...skipping 26 matching lines...) Expand all
393 340
394 // Get the offline page model associated with this web ui. 341 // Get the offline page model associated with this web ui.
395 Profile* profile = Profile::FromWebUI(web_ui()); 342 Profile* profile = Profile::FromWebUI(web_ui());
396 offline_page_model_ = 343 offline_page_model_ =
397 offline_pages::OfflinePageModelFactory::GetForBrowserContext(profile); 344 offline_pages::OfflinePageModelFactory::GetForBrowserContext(profile);
398 request_coordinator_ = 345 request_coordinator_ =
399 offline_pages::RequestCoordinatorFactory::GetForBrowserContext(profile); 346 offline_pages::RequestCoordinatorFactory::GetForBrowserContext(profile);
400 } 347 }
401 348
402 } // namespace offline_internals 349 } // 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