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

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: tommycli@ comments. 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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 base::Bind(&OfflineInternalsUIMessageHandler::HandleStoredPagesCallback, 204 base::Bind(&OfflineInternalsUIMessageHandler::HandleStoredPagesCallback,
204 weak_ptr_factory_.GetWeakPtr(), callback_id)); 205 weak_ptr_factory_.GetWeakPtr(), callback_id));
205 } else { 206 } else {
206 base::ListValue results; 207 base::ListValue results;
207 ResolveJavascriptCallback(base::Value(callback_id), results); 208 ResolveJavascriptCallback(base::Value(callback_id), results);
208 } 209 }
209 } 210 }
210 211
211 void OfflineInternalsUIMessageHandler::HandleSetRecordPageModel( 212 void OfflineInternalsUIMessageHandler::HandleSetRecordPageModel(
212 const base::ListValue* args) { 213 const base::ListValue* args) {
214 AllowJavascript();
213 bool should_record; 215 bool should_record;
214 CHECK(args->GetBoolean(0, &should_record)); 216 CHECK(args->GetBoolean(0, &should_record));
215 if (offline_page_model_) 217 if (offline_page_model_)
216 offline_page_model_->GetLogger()->SetIsLogging(should_record); 218 offline_page_model_->GetLogger()->SetIsLogging(should_record);
217 } 219 }
218 220
219 void OfflineInternalsUIMessageHandler::HandleGetNetworkStatus( 221 void OfflineInternalsUIMessageHandler::HandleGetNetworkStatus(
220 const base::ListValue* args) { 222 const base::ListValue* args) {
223 AllowJavascript();
221 const base::Value* callback_id; 224 const base::Value* callback_id;
222 CHECK(args->Get(0, &callback_id)); 225 CHECK(args->Get(0, &callback_id));
223 226
224 ResolveJavascriptCallback( 227 ResolveJavascriptCallback(
225 *callback_id, 228 *callback_id,
226 base::Value(net::NetworkChangeNotifier::IsOffline() ? "Offline" 229 base::Value(net::NetworkChangeNotifier::IsOffline() ? "Offline"
227 : "Online")); 230 : "Online"));
228 } 231 }
229 232
233 void OfflineInternalsUIMessageHandler::HandleScheduleNwake(
234 const base::ListValue* args) {
235 AllowJavascript();
236 const base::Value* callback_id;
237 CHECK(args->Get(0, &callback_id));
238
239 offline_pages::PrefetchBackgroundTask::Schedule();
240
241 ResolveJavascriptCallback(*callback_id, base::Value("Scheduled."));
242 }
243
244 void OfflineInternalsUIMessageHandler::HandleCancelNwake(
245 const base::ListValue* args) {
246 AllowJavascript();
247 const base::Value* callback_id;
248 CHECK(args->Get(0, &callback_id));
249
250 offline_pages::PrefetchBackgroundTask::Cancel();
251
252 ResolveJavascriptCallback(*callback_id, base::Value("Cancelled."));
253 }
254
230 void OfflineInternalsUIMessageHandler::HandleSetRecordRequestQueue( 255 void OfflineInternalsUIMessageHandler::HandleSetRecordRequestQueue(
231 const base::ListValue* args) { 256 const base::ListValue* args) {
257 AllowJavascript();
232 bool should_record; 258 bool should_record;
233 CHECK(args->GetBoolean(0, &should_record)); 259 CHECK(args->GetBoolean(0, &should_record));
234 if (request_coordinator_) 260 if (request_coordinator_)
235 request_coordinator_->GetLogger()->SetIsLogging(should_record); 261 request_coordinator_->GetLogger()->SetIsLogging(should_record);
236 } 262 }
237 263
238 void OfflineInternalsUIMessageHandler::HandleGetLoggingState( 264 void OfflineInternalsUIMessageHandler::HandleGetLoggingState(
239 const base::ListValue* args) { 265 const base::ListValue* args) {
240 AllowJavascript(); 266 AllowJavascript();
241 const base::Value* callback_id; 267 const base::Value* callback_id;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 base::Bind(&OfflineInternalsUIMessageHandler::HandleGetLoggingState, 359 base::Bind(&OfflineInternalsUIMessageHandler::HandleGetLoggingState,
334 weak_ptr_factory_.GetWeakPtr())); 360 weak_ptr_factory_.GetWeakPtr()));
335 web_ui()->RegisterMessageCallback( 361 web_ui()->RegisterMessageCallback(
336 "addToRequestQueue", 362 "addToRequestQueue",
337 base::Bind(&OfflineInternalsUIMessageHandler::HandleAddToRequestQueue, 363 base::Bind(&OfflineInternalsUIMessageHandler::HandleAddToRequestQueue,
338 weak_ptr_factory_.GetWeakPtr())); 364 weak_ptr_factory_.GetWeakPtr()));
339 web_ui()->RegisterMessageCallback( 365 web_ui()->RegisterMessageCallback(
340 "getNetworkStatus", 366 "getNetworkStatus",
341 base::Bind(&OfflineInternalsUIMessageHandler::HandleGetNetworkStatus, 367 base::Bind(&OfflineInternalsUIMessageHandler::HandleGetNetworkStatus,
342 weak_ptr_factory_.GetWeakPtr())); 368 weak_ptr_factory_.GetWeakPtr()));
369 web_ui()->RegisterMessageCallback(
370 "scheduleNwake",
371 base::Bind(&OfflineInternalsUIMessageHandler::HandleScheduleNwake,
372 weak_ptr_factory_.GetWeakPtr()));
373 web_ui()->RegisterMessageCallback(
374 "cancelNwake",
375 base::Bind(&OfflineInternalsUIMessageHandler::HandleCancelNwake,
376 weak_ptr_factory_.GetWeakPtr()));
343 377
344 // Get the offline page model associated with this web ui. 378 // Get the offline page model associated with this web ui.
345 Profile* profile = Profile::FromWebUI(web_ui()); 379 Profile* profile = Profile::FromWebUI(web_ui());
346 offline_page_model_ = 380 offline_page_model_ =
347 offline_pages::OfflinePageModelFactory::GetForBrowserContext(profile); 381 offline_pages::OfflinePageModelFactory::GetForBrowserContext(profile);
348 request_coordinator_ = 382 request_coordinator_ =
349 offline_pages::RequestCoordinatorFactory::GetForBrowserContext(profile); 383 offline_pages::RequestCoordinatorFactory::GetForBrowserContext(profile);
350 } 384 }
351 385
352 } // namespace offline_internals 386 } // namespace offline_internals
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698