Chromium Code Reviews| 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_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 Loading... | |
| 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 | |
| 53 // Callback for async GetAllPages calls. | 62 // Callback for async GetAllPages calls. |
| 54 void HandleStoredPagesCallback( | 63 void HandleStoredPagesCallback( |
| 55 std::string callback_id, | 64 std::string callback_id, |
| 56 const offline_pages::MultipleOfflinePageItemResult& pages); | 65 const offline_pages::MultipleOfflinePageItemResult& pages); |
| 57 | 66 |
| 58 // Callback for async GetRequests calls. | 67 // Callback for async GetRequests calls. |
| 59 void HandleRequestQueueCallback( | 68 void HandleRequestQueueCallback( |
| 60 std::string callback_id, | 69 std::string callback_id, |
| 61 offline_pages::RequestQueue::GetRequestsResult result, | 70 offline_pages::RequestQueue::GetRequestsResult result, |
| 62 const std::vector<offline_pages::SavePageRequest>& requests); | 71 const std::vector<offline_pages::SavePageRequest>& requests); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 if (offline_page_model_) { | 252 if (offline_page_model_) { |
| 244 offline_page_model_->GetAllPages( | 253 offline_page_model_->GetAllPages( |
| 245 base::Bind(&OfflineInternalsUIMessageHandler::HandleStoredPagesCallback, | 254 base::Bind(&OfflineInternalsUIMessageHandler::HandleStoredPagesCallback, |
| 246 weak_ptr_factory_.GetWeakPtr(), callback_id)); | 255 weak_ptr_factory_.GetWeakPtr(), callback_id)); |
| 247 } else { | 256 } else { |
| 248 base::ListValue results; | 257 base::ListValue results; |
| 249 ResolveJavascriptCallback(base::StringValue(callback_id), results); | 258 ResolveJavascriptCallback(base::StringValue(callback_id), results); |
| 250 } | 259 } |
| 251 } | 260 } |
| 252 | 261 |
| 262 void OfflineInternalsUIMessageHandler::HandleSetRecordPageModel( | |
| 263 const base::ListValue* args) { | |
| 264 bool should_record; | |
| 265 args->GetBoolean(0, &should_record); | |
|
dpapad
2016/06/24 20:33:39
CHECK(args->GetBoolean(0, &should_record));
chili
2016/06/24 21:43:17
Done.
| |
| 266 offline_page_model_->GetLogger()->SetIsLogging(should_record); | |
| 267 } | |
| 268 | |
| 269 void OfflineInternalsUIMessageHandler::HandleSetRecordRequestQueue( | |
| 270 const base::ListValue* args) { | |
| 271 bool should_record; | |
| 272 args->GetBoolean(0, &should_record); | |
| 273 request_coordinator_->GetLogger()->SetIsLogging(should_record); | |
| 274 } | |
| 275 | |
| 276 void OfflineInternalsUIMessageHandler::HandleGetEventLogs( | |
| 277 const base::ListValue* args) { | |
| 278 const base::Value* callback_id; | |
| 279 CHECK(args->Get(0, &callback_id)); | |
| 280 | |
| 281 std::vector<std::string> logs; | |
| 282 offline_page_model_->GetLogger()->GetLogs(logs); | |
| 283 request_coordinator_->GetLogger()->GetLogs(logs); | |
| 284 std::sort(logs.begin(), logs.end()); | |
| 285 | |
| 286 base::ListValue result; | |
| 287 result.AppendStrings(logs); | |
| 288 | |
| 289 ResolveJavascriptCallback(*callback_id, result); | |
| 290 } | |
| 291 | |
| 253 void OfflineInternalsUIMessageHandler::RegisterMessages() { | 292 void OfflineInternalsUIMessageHandler::RegisterMessages() { |
| 254 web_ui()->RegisterMessageCallback( | 293 web_ui()->RegisterMessageCallback( |
| 255 "deleteAllPages", | 294 "deleteAllPages", |
| 256 base::Bind(&OfflineInternalsUIMessageHandler::HandleDeleteAllPages, | 295 base::Bind(&OfflineInternalsUIMessageHandler::HandleDeleteAllPages, |
| 257 weak_ptr_factory_.GetWeakPtr())); | 296 weak_ptr_factory_.GetWeakPtr())); |
| 258 web_ui()->RegisterMessageCallback( | 297 web_ui()->RegisterMessageCallback( |
| 259 "deleteSelectedPages", | 298 "deleteSelectedPages", |
| 260 base::Bind(&OfflineInternalsUIMessageHandler::HandleDeleteSelectedPages, | 299 base::Bind(&OfflineInternalsUIMessageHandler::HandleDeleteSelectedPages, |
| 261 weak_ptr_factory_.GetWeakPtr())); | 300 weak_ptr_factory_.GetWeakPtr())); |
| 262 web_ui()->RegisterMessageCallback( | 301 web_ui()->RegisterMessageCallback( |
| 263 "getRequestQueue", | 302 "getRequestQueue", |
| 264 base::Bind(&OfflineInternalsUIMessageHandler::HandleGetRequestQueue, | 303 base::Bind(&OfflineInternalsUIMessageHandler::HandleGetRequestQueue, |
| 265 weak_ptr_factory_.GetWeakPtr())); | 304 weak_ptr_factory_.GetWeakPtr())); |
| 266 web_ui()->RegisterMessageCallback( | 305 web_ui()->RegisterMessageCallback( |
| 267 "getStoredPages", | 306 "getStoredPages", |
| 268 base::Bind(&OfflineInternalsUIMessageHandler::HandleGetStoredPages, | 307 base::Bind(&OfflineInternalsUIMessageHandler::HandleGetStoredPages, |
| 269 weak_ptr_factory_.GetWeakPtr())); | 308 weak_ptr_factory_.GetWeakPtr())); |
| 309 web_ui()->RegisterMessageCallback( | |
| 310 "getEventLogs", | |
| 311 base::Bind(&OfflineInternalsUIMessageHandler::HandleGetEventLogs, | |
| 312 weak_ptr_factory_.GetWeakPtr())); | |
| 313 web_ui()->RegisterMessageCallback( | |
| 314 "setRecordRequestQueue", | |
| 315 base::Bind(&OfflineInternalsUIMessageHandler::HandleSetRecordRequestQueue, | |
| 316 weak_ptr_factory_.GetWeakPtr())); | |
| 317 web_ui()->RegisterMessageCallback( | |
| 318 "setRecordPageModel", | |
| 319 base::Bind(&OfflineInternalsUIMessageHandler::HandleSetRecordPageModel, | |
| 320 weak_ptr_factory_.GetWeakPtr())); | |
| 270 | 321 |
| 271 // Get the offline page model associated with this web ui. | 322 // Get the offline page model associated with this web ui. |
| 272 Profile* profile = Profile::FromWebUI(web_ui()); | 323 Profile* profile = Profile::FromWebUI(web_ui()); |
| 273 offline_page_model_ = | 324 offline_page_model_ = |
| 274 offline_pages::OfflinePageModelFactory::GetForBrowserContext(profile); | 325 offline_pages::OfflinePageModelFactory::GetForBrowserContext(profile); |
| 275 request_coordinator_ = | 326 request_coordinator_ = |
| 276 offline_pages::RequestCoordinatorFactory::GetForBrowserContext(profile); | 327 offline_pages::RequestCoordinatorFactory::GetForBrowserContext(profile); |
| 277 } | 328 } |
| 278 | 329 |
| 279 } // namespace | 330 } // namespace |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 293 html_source->AddResourcePath("offline_internals_browser_proxy.js", | 344 html_source->AddResourcePath("offline_internals_browser_proxy.js", |
| 294 IDR_OFFLINE_INTERNALS_BROWSER_PROXY_JS); | 345 IDR_OFFLINE_INTERNALS_BROWSER_PROXY_JS); |
| 295 html_source->SetDefaultResource(IDR_OFFLINE_INTERNALS_HTML); | 346 html_source->SetDefaultResource(IDR_OFFLINE_INTERNALS_HTML); |
| 296 | 347 |
| 297 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), html_source); | 348 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), html_source); |
| 298 | 349 |
| 299 web_ui->AddMessageHandler(new OfflineInternalsUIMessageHandler()); | 350 web_ui->AddMessageHandler(new OfflineInternalsUIMessageHandler()); |
| 300 } | 351 } |
| 301 | 352 |
| 302 OfflineInternalsUI::~OfflineInternalsUI() {} | 353 OfflineInternalsUI::~OfflineInternalsUI() {} |
| OLD | NEW |