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

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

Issue 2820263002: [Offline Prefetch] Create a new JobScheduler task to wake up for net activity. (Closed)
Patch Set: Return false. Created 3 years, 7 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
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 <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/guid.h" 13 #include "base/guid.h"
14 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" 17 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h"
18 #include "chrome/browser/android/offline_pages/prefetch/prefetch_background_task .h"
18 #include "chrome/browser/android/offline_pages/request_coordinator_factory.h" 19 #include "chrome/browser/android/offline_pages/request_coordinator_factory.h"
19 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
20 #include "components/offline_pages/core/client_namespace_constants.h" 21 #include "components/offline_pages/core/client_namespace_constants.h"
21 #include "content/public/browser/web_ui.h" 22 #include "content/public/browser/web_ui.h"
22 #include "net/base/network_change_notifier.h" 23 #include "net/base/network_change_notifier.h"
23 24
24 namespace offline_internals { 25 namespace offline_internals {
25 26
26 OfflineInternalsUIMessageHandler::OfflineInternalsUIMessageHandler() 27 OfflineInternalsUIMessageHandler::OfflineInternalsUIMessageHandler()
27 : offline_page_model_(nullptr), 28 : offline_page_model_(nullptr),
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 const base::ListValue* args) { 221 const base::ListValue* args) {
221 const base::Value* callback_id; 222 const base::Value* callback_id;
222 CHECK(args->Get(0, &callback_id)); 223 CHECK(args->Get(0, &callback_id));
223 224
224 ResolveJavascriptCallback( 225 ResolveJavascriptCallback(
225 *callback_id, 226 *callback_id,
226 base::Value(net::NetworkChangeNotifier::IsOffline() ? "Offline" 227 base::Value(net::NetworkChangeNotifier::IsOffline() ? "Offline"
227 : "Online")); 228 : "Online"));
228 } 229 }
229 230
231 void OfflineInternalsUIMessageHandler::HandleScheduleNwake(
tommycli 2017/05/03 16:00:12 Can these methods be the first method called from
dewittj 2017/05/03 21:34:10 Done.
232 const base::ListValue* args) {
233 const base::Value* callback_id;
234 CHECK(args->Get(0, &callback_id));
235
236 offline_pages::PrefetchBackgroundTask::Schedule();
237
238 ResolveJavascriptCallback(*callback_id, base::Value("Scheduled."));
tommycli 2017/05/03 16:00:12 I'm assuming this is an internal page and so there
dewittj 2017/05/03 21:34:10 Correct.
239 }
240
241 void OfflineInternalsUIMessageHandler::HandleCancelNwake(
242 const base::ListValue* args) {
243 const base::Value* callback_id;
244 CHECK(args->Get(0, &callback_id));
245
246 offline_pages::PrefetchBackgroundTask::Cancel();
247
248 ResolveJavascriptCallback(*callback_id, base::Value("Cancelled."));
249 }
250
230 void OfflineInternalsUIMessageHandler::HandleSetRecordRequestQueue( 251 void OfflineInternalsUIMessageHandler::HandleSetRecordRequestQueue(
231 const base::ListValue* args) { 252 const base::ListValue* args) {
232 bool should_record; 253 bool should_record;
233 CHECK(args->GetBoolean(0, &should_record)); 254 CHECK(args->GetBoolean(0, &should_record));
234 if (request_coordinator_) 255 if (request_coordinator_)
235 request_coordinator_->GetLogger()->SetIsLogging(should_record); 256 request_coordinator_->GetLogger()->SetIsLogging(should_record);
236 } 257 }
237 258
238 void OfflineInternalsUIMessageHandler::HandleGetLoggingState( 259 void OfflineInternalsUIMessageHandler::HandleGetLoggingState(
239 const base::ListValue* args) { 260 const base::ListValue* args) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 base::Bind(&OfflineInternalsUIMessageHandler::HandleGetLoggingState, 354 base::Bind(&OfflineInternalsUIMessageHandler::HandleGetLoggingState,
334 weak_ptr_factory_.GetWeakPtr())); 355 weak_ptr_factory_.GetWeakPtr()));
335 web_ui()->RegisterMessageCallback( 356 web_ui()->RegisterMessageCallback(
336 "addToRequestQueue", 357 "addToRequestQueue",
337 base::Bind(&OfflineInternalsUIMessageHandler::HandleAddToRequestQueue, 358 base::Bind(&OfflineInternalsUIMessageHandler::HandleAddToRequestQueue,
338 weak_ptr_factory_.GetWeakPtr())); 359 weak_ptr_factory_.GetWeakPtr()));
339 web_ui()->RegisterMessageCallback( 360 web_ui()->RegisterMessageCallback(
340 "getNetworkStatus", 361 "getNetworkStatus",
341 base::Bind(&OfflineInternalsUIMessageHandler::HandleGetNetworkStatus, 362 base::Bind(&OfflineInternalsUIMessageHandler::HandleGetNetworkStatus,
342 weak_ptr_factory_.GetWeakPtr())); 363 weak_ptr_factory_.GetWeakPtr()));
364 web_ui()->RegisterMessageCallback(
365 "scheduleNwake",
366 base::Bind(&OfflineInternalsUIMessageHandler::HandleScheduleNwake,
367 weak_ptr_factory_.GetWeakPtr()));
368
tommycli 2017/05/03 16:00:12 intentional extra newline?
dewittj 2017/05/03 21:34:10 Done.
369 web_ui()->RegisterMessageCallback(
370 "cancelNwake",
371 base::Bind(&OfflineInternalsUIMessageHandler::HandleCancelNwake,
372 weak_ptr_factory_.GetWeakPtr()));
343 373
344 // Get the offline page model associated with this web ui. 374 // Get the offline page model associated with this web ui.
345 Profile* profile = Profile::FromWebUI(web_ui()); 375 Profile* profile = Profile::FromWebUI(web_ui());
346 offline_page_model_ = 376 offline_page_model_ =
347 offline_pages::OfflinePageModelFactory::GetForBrowserContext(profile); 377 offline_pages::OfflinePageModelFactory::GetForBrowserContext(profile);
348 request_coordinator_ = 378 request_coordinator_ =
349 offline_pages::RequestCoordinatorFactory::GetForBrowserContext(profile); 379 offline_pages::RequestCoordinatorFactory::GetForBrowserContext(profile);
350 } 380 }
351 381
352 } // namespace offline_internals 382 } // namespace offline_internals
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698