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

Side by Side Diff: chrome/browser/ui/webui/offline_internals_ui.cc

Issue 2089423002: [Offline Pages] Connect the offline page logs to the internals page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@i4
Patch Set: remove unneeded consts Created 4 years, 5 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/resources/offline_pages/offline_internals_browser_proxy.js ('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_internals_ui.h" 5 #include "chrome/browser/ui/webui/offline_internals_ui.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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 43
44 // Delete selected list of page ids from the store. 44 // Delete selected list of page ids from the store.
45 void HandleDeleteSelectedPages(const base::ListValue* args); 45 void HandleDeleteSelectedPages(const base::ListValue* args);
46 46
47 // Load Request Queue info. 47 // Load Request Queue info.
48 void HandleGetRequestQueue(const base::ListValue* args); 48 void HandleGetRequestQueue(const base::ListValue* args);
49 49
50 // Load Stored pages info. 50 // Load Stored pages info.
51 void HandleGetStoredPages(const base::ListValue* args); 51 void HandleGetStoredPages(const base::ListValue* args);
52 52
53 // Set whether to record offline page model events.
54 void HandleSetRecordPageModel(const base::ListValue* args);
55
56 // Set whether to record request queue events.
57 void HandleSetRecordRequestQueue(const base::ListValue* args);
58
59 // Load both Page Model and Request Queue event logs.
60 void HandleGetEventLogs(const base::ListValue* args);
61
62 // Load whether logs are being recorded.
63 void HandleGetLoggingState(const base::ListValue* args);
64
53 // Callback for async GetAllPages calls. 65 // Callback for async GetAllPages calls.
54 void HandleStoredPagesCallback( 66 void HandleStoredPagesCallback(
55 std::string callback_id, 67 std::string callback_id,
56 const offline_pages::MultipleOfflinePageItemResult& pages); 68 const offline_pages::MultipleOfflinePageItemResult& pages);
57 69
58 // Callback for async GetRequests calls. 70 // Callback for async GetRequests calls.
59 void HandleRequestQueueCallback( 71 void HandleRequestQueueCallback(
60 std::string callback_id, 72 std::string callback_id,
61 offline_pages::RequestQueue::GetRequestsResult result, 73 offline_pages::RequestQueue::GetRequestsResult result,
62 const std::vector<offline_pages::SavePageRequest>& requests); 74 const std::vector<offline_pages::SavePageRequest>& requests);
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 if (offline_page_model_) { 255 if (offline_page_model_) {
244 offline_page_model_->GetAllPages( 256 offline_page_model_->GetAllPages(
245 base::Bind(&OfflineInternalsUIMessageHandler::HandleStoredPagesCallback, 257 base::Bind(&OfflineInternalsUIMessageHandler::HandleStoredPagesCallback,
246 weak_ptr_factory_.GetWeakPtr(), callback_id)); 258 weak_ptr_factory_.GetWeakPtr(), callback_id));
247 } else { 259 } else {
248 base::ListValue results; 260 base::ListValue results;
249 ResolveJavascriptCallback(base::StringValue(callback_id), results); 261 ResolveJavascriptCallback(base::StringValue(callback_id), results);
250 } 262 }
251 } 263 }
252 264
265 void OfflineInternalsUIMessageHandler::HandleSetRecordPageModel(
266 const base::ListValue* args) {
267 bool should_record;
268 CHECK(args->GetBoolean(0, &should_record));
269 offline_page_model_->GetLogger()->SetIsLogging(should_record);
270 }
271
272 void OfflineInternalsUIMessageHandler::HandleSetRecordRequestQueue(
273 const base::ListValue* args) {
274 bool should_record;
275 CHECK(args->GetBoolean(0, &should_record));
276 request_coordinator_->GetLogger()->SetIsLogging(should_record);
277 }
278
279 void OfflineInternalsUIMessageHandler::HandleGetLoggingState(
280 const base::ListValue* args) {
281 AllowJavascript();
282 const base::Value* callback_id;
283 CHECK(args->Get(0, &callback_id));
284
285 base::DictionaryValue result;
286 result.SetBoolean("modelIsLogging",
287 offline_page_model_->GetLogger()->GetIsLogging());
288 result.SetBoolean("queueIsLogging",
289 request_coordinator_->GetLogger()->GetIsLogging());
290 ResolveJavascriptCallback(*callback_id, result);
291 }
292
293 void OfflineInternalsUIMessageHandler::HandleGetEventLogs(
294 const base::ListValue* args) {
295 AllowJavascript();
296 const base::Value* callback_id;
297 CHECK(args->Get(0, &callback_id));
298
299 std::vector<std::string> logs;
300 offline_page_model_->GetLogger()->GetLogs(&logs);
301 request_coordinator_->GetLogger()->GetLogs(&logs);
302 std::sort(logs.begin(), logs.end());
303
304 base::ListValue result;
305 result.AppendStrings(logs);
306
307 ResolveJavascriptCallback(*callback_id, result);
308 }
309
253 void OfflineInternalsUIMessageHandler::RegisterMessages() { 310 void OfflineInternalsUIMessageHandler::RegisterMessages() {
254 web_ui()->RegisterMessageCallback( 311 web_ui()->RegisterMessageCallback(
255 "deleteAllPages", 312 "deleteAllPages",
256 base::Bind(&OfflineInternalsUIMessageHandler::HandleDeleteAllPages, 313 base::Bind(&OfflineInternalsUIMessageHandler::HandleDeleteAllPages,
257 weak_ptr_factory_.GetWeakPtr())); 314 weak_ptr_factory_.GetWeakPtr()));
258 web_ui()->RegisterMessageCallback( 315 web_ui()->RegisterMessageCallback(
259 "deleteSelectedPages", 316 "deleteSelectedPages",
260 base::Bind(&OfflineInternalsUIMessageHandler::HandleDeleteSelectedPages, 317 base::Bind(&OfflineInternalsUIMessageHandler::HandleDeleteSelectedPages,
261 weak_ptr_factory_.GetWeakPtr())); 318 weak_ptr_factory_.GetWeakPtr()));
262 web_ui()->RegisterMessageCallback( 319 web_ui()->RegisterMessageCallback(
263 "getRequestQueue", 320 "getRequestQueue",
264 base::Bind(&OfflineInternalsUIMessageHandler::HandleGetRequestQueue, 321 base::Bind(&OfflineInternalsUIMessageHandler::HandleGetRequestQueue,
265 weak_ptr_factory_.GetWeakPtr())); 322 weak_ptr_factory_.GetWeakPtr()));
266 web_ui()->RegisterMessageCallback( 323 web_ui()->RegisterMessageCallback(
267 "getStoredPages", 324 "getStoredPages",
268 base::Bind(&OfflineInternalsUIMessageHandler::HandleGetStoredPages, 325 base::Bind(&OfflineInternalsUIMessageHandler::HandleGetStoredPages,
269 weak_ptr_factory_.GetWeakPtr())); 326 weak_ptr_factory_.GetWeakPtr()));
327 web_ui()->RegisterMessageCallback(
328 "getEventLogs",
329 base::Bind(&OfflineInternalsUIMessageHandler::HandleGetEventLogs,
330 weak_ptr_factory_.GetWeakPtr()));
331 web_ui()->RegisterMessageCallback(
332 "setRecordRequestQueue",
333 base::Bind(&OfflineInternalsUIMessageHandler::HandleSetRecordRequestQueue,
334 weak_ptr_factory_.GetWeakPtr()));
335 web_ui()->RegisterMessageCallback(
336 "setRecordPageModel",
337 base::Bind(&OfflineInternalsUIMessageHandler::HandleSetRecordPageModel,
338 weak_ptr_factory_.GetWeakPtr()));
339 web_ui()->RegisterMessageCallback(
340 "getLoggingState",
341 base::Bind(&OfflineInternalsUIMessageHandler::HandleGetLoggingState,
342 weak_ptr_factory_.GetWeakPtr()));
270 343
271 // Get the offline page model associated with this web ui. 344 // Get the offline page model associated with this web ui.
272 Profile* profile = Profile::FromWebUI(web_ui()); 345 Profile* profile = Profile::FromWebUI(web_ui());
273 offline_page_model_ = 346 offline_page_model_ =
274 offline_pages::OfflinePageModelFactory::GetForBrowserContext(profile); 347 offline_pages::OfflinePageModelFactory::GetForBrowserContext(profile);
275 request_coordinator_ = 348 request_coordinator_ =
276 offline_pages::RequestCoordinatorFactory::GetForBrowserContext(profile); 349 offline_pages::RequestCoordinatorFactory::GetForBrowserContext(profile);
277 } 350 }
278 351
279 } // namespace 352 } // namespace
(...skipping 13 matching lines...) Expand all
293 html_source->AddResourcePath("offline_internals_browser_proxy.js", 366 html_source->AddResourcePath("offline_internals_browser_proxy.js",
294 IDR_OFFLINE_INTERNALS_BROWSER_PROXY_JS); 367 IDR_OFFLINE_INTERNALS_BROWSER_PROXY_JS);
295 html_source->SetDefaultResource(IDR_OFFLINE_INTERNALS_HTML); 368 html_source->SetDefaultResource(IDR_OFFLINE_INTERNALS_HTML);
296 369
297 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), html_source); 370 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), html_source);
298 371
299 web_ui->AddMessageHandler(new OfflineInternalsUIMessageHandler()); 372 web_ui->AddMessageHandler(new OfflineInternalsUIMessageHandler());
300 } 373 }
301 374
302 OfflineInternalsUI::~OfflineInternalsUI() {} 375 OfflineInternalsUI::~OfflineInternalsUI() {}
OLDNEW
« no previous file with comments | « chrome/browser/resources/offline_pages/offline_internals_browser_proxy.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698