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

Side by Side Diff: chrome/browser/ui/webui/settings/about_handler.cc

Issue 2873193002: Make update over cellular an option for user (Closed)
Patch Set: Apply fix to patch set 5 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
« no previous file with comments | « chrome/browser/ui/webui/settings/about_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/settings/about_handler.h" 5 #include "chrome/browser/ui/webui/settings/about_handler.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "ash/system/devicetype_utils.h" 11 #include "ash/system/devicetype_utils.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
16 #include "base/files/file_util.h" 16 #include "base/files/file_util.h"
17 #include "base/i18n/message_formatter.h" 17 #include "base/i18n/message_formatter.h"
18 #include "base/location.h" 18 #include "base/location.h"
19 #include "base/macros.h" 19 #include "base/macros.h"
20 #include "base/memory/ptr_util.h" 20 #include "base/memory/ptr_util.h"
21 #include "base/strings/string16.h" 21 #include "base/strings/string16.h"
22 #include "base/strings/string_number_conversions.h"
22 #include "base/strings/string_util.h" 23 #include "base/strings/string_util.h"
23 #include "base/strings/utf_string_conversions.h" 24 #include "base/strings/utf_string_conversions.h"
24 #include "base/task_scheduler/post_task.h" 25 #include "base/task_scheduler/post_task.h"
25 #include "base/time/time.h" 26 #include "base/time/time.h"
26 #include "base/values.h" 27 #include "base/values.h"
27 #include "build/build_config.h" 28 #include "build/build_config.h"
28 #include "chrome/browser/browser_process.h" 29 #include "chrome/browser/browser_process.h"
29 #include "chrome/browser/chrome_notification_types.h" 30 #include "chrome/browser/chrome_notification_types.h"
30 #include "chrome/browser/obsolete_system/obsolete_system.h" 31 #include "chrome/browser/obsolete_system/obsolete_system.h"
31 #include "chrome/browser/ui/browser.h" 32 #include "chrome/browser/ui/browser.h"
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 case VersionUpdater::FAILED_OFFLINE: 233 case VersionUpdater::FAILED_OFFLINE:
233 case VersionUpdater::FAILED_CONNECTION_TYPE_DISALLOWED: 234 case VersionUpdater::FAILED_CONNECTION_TYPE_DISALLOWED:
234 status_str = "failed"; 235 status_str = "failed";
235 break; 236 break;
236 case VersionUpdater::DISABLED: 237 case VersionUpdater::DISABLED:
237 status_str = "disabled"; 238 status_str = "disabled";
238 break; 239 break;
239 case VersionUpdater::DISABLED_BY_ADMIN: 240 case VersionUpdater::DISABLED_BY_ADMIN:
240 status_str = "disabled_by_admin"; 241 status_str = "disabled_by_admin";
241 break; 242 break;
243 case VersionUpdater::NEED_PERMISSION_TO_UPDATE:
244 status_str = "need_permission_to_update";
245 break;
242 } 246 }
243 247
244 return status_str; 248 return status_str;
245 } 249 }
246 250
247 } // namespace 251 } // namespace
248 252
249 namespace settings { 253 namespace settings {
250 254
251 AboutHandler::AboutHandler() : weak_factory_(this) {} 255 AboutHandler::AboutHandler() : weak_factory_(this) {}
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 web_ui()->RegisterMessageCallback( 337 web_ui()->RegisterMessageCallback(
334 "openHelpPage", 338 "openHelpPage",
335 base::Bind(&AboutHandler::HandleOpenHelpPage, base::Unretained(this))); 339 base::Bind(&AboutHandler::HandleOpenHelpPage, base::Unretained(this)));
336 #if defined(OS_CHROMEOS) 340 #if defined(OS_CHROMEOS)
337 web_ui()->RegisterMessageCallback( 341 web_ui()->RegisterMessageCallback(
338 "setChannel", 342 "setChannel",
339 base::Bind(&AboutHandler::HandleSetChannel, base::Unretained(this))); 343 base::Bind(&AboutHandler::HandleSetChannel, base::Unretained(this)));
340 web_ui()->RegisterMessageCallback( 344 web_ui()->RegisterMessageCallback(
341 "requestUpdate", 345 "requestUpdate",
342 base::Bind(&AboutHandler::HandleRequestUpdate, base::Unretained(this))); 346 base::Bind(&AboutHandler::HandleRequestUpdate, base::Unretained(this)));
343 347 web_ui()->RegisterMessageCallback(
348 "requestUpdateOverCellular",
349 base::Bind(&AboutHandler::HandleRequestUpdateOverCellular,
350 base::Unretained(this)));
344 web_ui()->RegisterMessageCallback( 351 web_ui()->RegisterMessageCallback(
345 "getVersionInfo", 352 "getVersionInfo",
346 base::Bind(&AboutHandler::HandleGetVersionInfo, base::Unretained(this))); 353 base::Bind(&AboutHandler::HandleGetVersionInfo, base::Unretained(this)));
347 web_ui()->RegisterMessageCallback( 354 web_ui()->RegisterMessageCallback(
348 "getRegulatoryInfo", base::Bind(&AboutHandler::HandleGetRegulatoryInfo, 355 "getRegulatoryInfo", base::Bind(&AboutHandler::HandleGetRegulatoryInfo,
349 base::Unretained(this))); 356 base::Unretained(this)));
350 web_ui()->RegisterMessageCallback( 357 web_ui()->RegisterMessageCallback(
351 "getChannelInfo", base::Bind(&AboutHandler::HandleGetChannelInfo, 358 "getChannelInfo", base::Bind(&AboutHandler::HandleGetChannelInfo,
352 base::Unretained(this))); 359 base::Unretained(this)));
353 #endif 360 #endif
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 channel_info->SetBoolean("canChangeChannel", 544 channel_info->SetBoolean("canChangeChannel",
538 CanChangeChannel(Profile::FromWebUI(web_ui()))); 545 CanChangeChannel(Profile::FromWebUI(web_ui())));
539 546
540 ResolveJavascriptCallback(base::Value(callback_id), *channel_info); 547 ResolveJavascriptCallback(base::Value(callback_id), *channel_info);
541 } 548 }
542 549
543 void AboutHandler::HandleRequestUpdate(const base::ListValue* args) { 550 void AboutHandler::HandleRequestUpdate(const base::ListValue* args) {
544 RequestUpdate(); 551 RequestUpdate();
545 } 552 }
546 553
554 void AboutHandler::HandleRequestUpdateOverCellular(
555 const base::ListValue* args) {
556 CHECK_EQ(2U, args->GetSize());
557
558 std::string target_version;
559 std::string target_size_string;
560 int64_t target_size;
561
562 CHECK(args->GetString(0, &target_version));
563 CHECK(args->GetString(1, &target_size_string));
564 CHECK(base::StringToInt64(target_size_string, &target_size));
565
566 RequestUpdateOverCellular(target_version, target_size);
567 }
568
547 #endif // defined(OS_CHROMEOS) 569 #endif // defined(OS_CHROMEOS)
548 570
549 void AboutHandler::RequestUpdate() { 571 void AboutHandler::RequestUpdate() {
550 version_updater_->CheckForUpdate( 572 version_updater_->CheckForUpdate(
551 base::Bind(&AboutHandler::SetUpdateStatus, base::Unretained(this)), 573 base::Bind(&AboutHandler::SetUpdateStatus, base::Unretained(this)),
552 #if defined(OS_MACOSX) 574 #if defined(OS_MACOSX)
553 base::Bind(&AboutHandler::SetPromotionState, base::Unretained(this))); 575 base::Bind(&AboutHandler::SetPromotionState, base::Unretained(this)));
554 #else 576 #else
555 VersionUpdater::PromoteCallback()); 577 VersionUpdater::PromoteCallback());
556 #endif // OS_MACOSX 578 #endif // OS_MACOSX
557 } 579 }
558 580
581 void AboutHandler::RequestUpdateOverCellular(std::string& target_version,
582 int64_t target_size) {
583 version_updater_->SetUpdateOverCellularTarget(
584 base::Bind(&AboutHandler::SetUpdateStatus, base::Unretained(this)),
585 target_version, target_size);
stevenjb 2017/05/12 18:28:54 If AboutHandler::SetUpdateStatus never runs then u
weidongg 2017/05/12 20:31:57 We could run the callback if SetUpdateOverCellular
stevenjb 2017/05/12 20:50:16 That would be fine also, although maybe a little b
586 }
587
559 void AboutHandler::SetUpdateStatus(VersionUpdater::Status status, 588 void AboutHandler::SetUpdateStatus(VersionUpdater::Status status,
560 int progress, 589 int progress,
590 const std::string& version,
591 const int64_t size,
561 const base::string16& message) { 592 const base::string16& message) {
562 // Only UPDATING state should have progress set. 593 // Only UPDATING state should have progress set.
563 DCHECK(status == VersionUpdater::UPDATING || progress == 0); 594 DCHECK(status == VersionUpdater::UPDATING || progress == 0);
564 595
565 std::unique_ptr<base::DictionaryValue> event(new base::DictionaryValue); 596 std::unique_ptr<base::DictionaryValue> event(new base::DictionaryValue);
566 event->SetString("status", UpdateStatusToString(status)); 597 event->SetString("status", UpdateStatusToString(status));
567 event->SetString("message", message); 598 event->SetString("message", message);
568 event->SetInteger("progress", progress); 599 event->SetInteger("progress", progress);
569 600 event->SetString("version", version);
601 // DictionaryValue does not support int64_t, so convert to string.
602 event->SetString("size", base::Int64ToString(size));
570 #if defined(OS_CHROMEOS) 603 #if defined(OS_CHROMEOS)
571 if (status == VersionUpdater::FAILED_OFFLINE || 604 if (status == VersionUpdater::FAILED_OFFLINE ||
572 status == VersionUpdater::FAILED_CONNECTION_TYPE_DISALLOWED) { 605 status == VersionUpdater::FAILED_CONNECTION_TYPE_DISALLOWED) {
573 base::string16 types_msg = GetAllowedConnectionTypesMessage(); 606 base::string16 types_msg = GetAllowedConnectionTypesMessage();
574 if (!types_msg.empty()) 607 if (!types_msg.empty())
575 event->SetString("connectionTypes", types_msg); 608 event->SetString("connectionTypes", types_msg);
576 else 609 else
577 event->Set("connectionTypes", base::MakeUnique<base::Value>()); 610 event->Set("connectionTypes", base::MakeUnique<base::Value>());
578 } else { 611 } else {
579 event->Set("connectionTypes", base::MakeUnique<base::Value>()); 612 event->Set("connectionTypes", base::MakeUnique<base::Value>());
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 label_dir_path.AppendASCII(kRegulatoryLabelImageFilename).MaybeAsASCII(); 675 label_dir_path.AppendASCII(kRegulatoryLabelImageFilename).MaybeAsASCII();
643 std::string url = 676 std::string url =
644 std::string("chrome://") + chrome::kChromeOSAssetHost + "/" + image_path; 677 std::string("chrome://") + chrome::kChromeOSAssetHost + "/" + image_path;
645 regulatory_info->SetString("url", url); 678 regulatory_info->SetString("url", url);
646 679
647 ResolveJavascriptCallback(base::Value(callback_id), *regulatory_info); 680 ResolveJavascriptCallback(base::Value(callback_id), *regulatory_info);
648 } 681 }
649 #endif // defined(OS_CHROMEOS) 682 #endif // defined(OS_CHROMEOS)
650 683
651 } // namespace settings 684 } // namespace settings
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/settings/about_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698