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/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 Loading... |
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 IDS_ABOUT_TERMS_OF_SERVICE, base::UTF8ToUTF16(chrome::kChromeUITermsURL)); | 299 IDS_ABOUT_TERMS_OF_SERVICE, base::UTF8ToUTF16(chrome::kChromeUITermsURL)); |
296 html_source->AddString("aboutProductTos", tos); | 300 html_source->AddString("aboutProductTos", tos); |
297 #endif | 301 #endif |
298 | 302 |
299 #if defined(OS_CHROMEOS) | 303 #if defined(OS_CHROMEOS) |
300 base::string16 os_license = l10n_util::GetStringFUTF16( | 304 base::string16 os_license = l10n_util::GetStringFUTF16( |
301 IDS_ABOUT_CROS_VERSION_LICENSE, | 305 IDS_ABOUT_CROS_VERSION_LICENSE, |
302 base::ASCIIToUTF16(chrome::kChromeUIOSCreditsURL)); | 306 base::ASCIIToUTF16(chrome::kChromeUIOSCreditsURL)); |
303 html_source->AddString("aboutProductOsLicense", os_license); | 307 html_source->AddString("aboutProductOsLicense", os_license); |
304 html_source->AddBoolean("aboutEnterpriseManaged", IsEnterpriseManaged()); | 308 html_source->AddBoolean("aboutEnterpriseManaged", IsEnterpriseManaged()); |
305 | |
306 base::Time build_time = base::SysInfo::GetLsbReleaseTime(); | 309 base::Time build_time = base::SysInfo::GetLsbReleaseTime(); |
307 base::string16 build_date = base::TimeFormatFriendlyDate(build_time); | 310 base::string16 build_date = base::TimeFormatFriendlyDate(build_time); |
308 html_source->AddString("aboutBuildDate", build_date); | 311 html_source->AddString("aboutBuildDate", build_date); |
309 | 312 |
310 base::CommandLine::StringType command_line = | 313 base::CommandLine::StringType command_line = |
311 base::CommandLine::ForCurrentProcess()->GetCommandLineString(); | 314 base::CommandLine::ForCurrentProcess()->GetCommandLineString(); |
312 html_source->AddString("aboutCommandLine", command_line); | 315 html_source->AddString("aboutCommandLine", command_line); |
313 | 316 |
314 html_source->AddString("aboutUserAgent", GetUserAgent()); | 317 html_source->AddString("aboutUserAgent", GetUserAgent()); |
315 html_source->AddString("aboutJsEngineVersion", V8_VERSION_STRING); | 318 html_source->AddString("aboutJsEngineVersion", V8_VERSION_STRING); |
(...skipping 17 matching lines...) Expand all Loading... |
333 web_ui()->RegisterMessageCallback( | 336 web_ui()->RegisterMessageCallback( |
334 "openHelpPage", | 337 "openHelpPage", |
335 base::Bind(&AboutHandler::HandleOpenHelpPage, base::Unretained(this))); | 338 base::Bind(&AboutHandler::HandleOpenHelpPage, base::Unretained(this))); |
336 #if defined(OS_CHROMEOS) | 339 #if defined(OS_CHROMEOS) |
337 web_ui()->RegisterMessageCallback( | 340 web_ui()->RegisterMessageCallback( |
338 "setChannel", | 341 "setChannel", |
339 base::Bind(&AboutHandler::HandleSetChannel, base::Unretained(this))); | 342 base::Bind(&AboutHandler::HandleSetChannel, base::Unretained(this))); |
340 web_ui()->RegisterMessageCallback( | 343 web_ui()->RegisterMessageCallback( |
341 "requestUpdate", | 344 "requestUpdate", |
342 base::Bind(&AboutHandler::HandleRequestUpdate, base::Unretained(this))); | 345 base::Bind(&AboutHandler::HandleRequestUpdate, base::Unretained(this))); |
343 | 346 web_ui()->RegisterMessageCallback( |
| 347 "requestUpdateOverCellular", |
| 348 base::Bind(&AboutHandler::HandleRequestUpdateOverCellular, |
| 349 base::Unretained(this))); |
344 web_ui()->RegisterMessageCallback( | 350 web_ui()->RegisterMessageCallback( |
345 "getVersionInfo", | 351 "getVersionInfo", |
346 base::Bind(&AboutHandler::HandleGetVersionInfo, base::Unretained(this))); | 352 base::Bind(&AboutHandler::HandleGetVersionInfo, base::Unretained(this))); |
347 web_ui()->RegisterMessageCallback( | 353 web_ui()->RegisterMessageCallback( |
348 "getRegulatoryInfo", base::Bind(&AboutHandler::HandleGetRegulatoryInfo, | 354 "getRegulatoryInfo", base::Bind(&AboutHandler::HandleGetRegulatoryInfo, |
349 base::Unretained(this))); | 355 base::Unretained(this))); |
350 web_ui()->RegisterMessageCallback( | 356 web_ui()->RegisterMessageCallback( |
351 "getChannelInfo", base::Bind(&AboutHandler::HandleGetChannelInfo, | 357 "getChannelInfo", base::Bind(&AboutHandler::HandleGetChannelInfo, |
352 base::Unretained(this))); | 358 base::Unretained(this))); |
353 #endif | 359 #endif |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 channel_info->SetBoolean("canChangeChannel", | 544 channel_info->SetBoolean("canChangeChannel", |
539 CanChangeChannel(Profile::FromWebUI(web_ui()))); | 545 CanChangeChannel(Profile::FromWebUI(web_ui()))); |
540 | 546 |
541 ResolveJavascriptCallback(base::Value(callback_id), *channel_info); | 547 ResolveJavascriptCallback(base::Value(callback_id), *channel_info); |
542 } | 548 } |
543 | 549 |
544 void AboutHandler::HandleRequestUpdate(const base::ListValue* args) { | 550 void AboutHandler::HandleRequestUpdate(const base::ListValue* args) { |
545 RequestUpdate(); | 551 RequestUpdate(); |
546 } | 552 } |
547 | 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 |
548 #endif // defined(OS_CHROMEOS) | 569 #endif // defined(OS_CHROMEOS) |
549 | 570 |
550 void AboutHandler::RequestUpdate() { | 571 void AboutHandler::RequestUpdate() { |
551 version_updater_->CheckForUpdate( | 572 version_updater_->CheckForUpdate( |
552 base::Bind(&AboutHandler::SetUpdateStatus, base::Unretained(this)), | 573 base::Bind(&AboutHandler::SetUpdateStatus, base::Unretained(this)), |
553 #if defined(OS_MACOSX) | 574 #if defined(OS_MACOSX) |
554 base::Bind(&AboutHandler::SetPromotionState, base::Unretained(this))); | 575 base::Bind(&AboutHandler::SetPromotionState, base::Unretained(this))); |
555 #else | 576 #else |
556 VersionUpdater::PromoteCallback()); | 577 VersionUpdater::PromoteCallback()); |
557 #endif // OS_MACOSX | 578 #endif // OS_MACOSX |
558 } | 579 } |
559 | 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); |
| 586 } |
| 587 |
560 void AboutHandler::SetUpdateStatus(VersionUpdater::Status status, | 588 void AboutHandler::SetUpdateStatus(VersionUpdater::Status status, |
561 int progress, | 589 int progress, |
| 590 const std::string& version, |
| 591 const int64_t size, |
562 const base::string16& message) { | 592 const base::string16& message) { |
563 // Only UPDATING state should have progress set. | 593 // Only UPDATING state should have progress set. |
564 DCHECK(status == VersionUpdater::UPDATING || progress == 0); | 594 DCHECK(status == VersionUpdater::UPDATING || progress == 0); |
565 | 595 |
566 std::unique_ptr<base::DictionaryValue> event(new base::DictionaryValue); | 596 std::unique_ptr<base::DictionaryValue> event(new base::DictionaryValue); |
567 event->SetString("status", UpdateStatusToString(status)); | 597 event->SetString("status", UpdateStatusToString(status)); |
568 event->SetString("message", message); | 598 event->SetString("message", message); |
569 event->SetInteger("progress", progress); | 599 event->SetInteger("progress", progress); |
570 | 600 event->SetString("version", version); |
| 601 // DictionaryValue does not support int64_t, so convert to string. |
| 602 event->SetString("size", base::Int64ToString(size)); |
571 #if defined(OS_CHROMEOS) | 603 #if defined(OS_CHROMEOS) |
572 if (status == VersionUpdater::FAILED_OFFLINE || | 604 if (status == VersionUpdater::FAILED_OFFLINE || |
573 status == VersionUpdater::FAILED_CONNECTION_TYPE_DISALLOWED) { | 605 status == VersionUpdater::FAILED_CONNECTION_TYPE_DISALLOWED) { |
574 base::string16 types_msg = GetAllowedConnectionTypesMessage(); | 606 base::string16 types_msg = GetAllowedConnectionTypesMessage(); |
575 if (!types_msg.empty()) | 607 if (!types_msg.empty()) |
576 event->SetString("connectionTypes", types_msg); | 608 event->SetString("connectionTypes", types_msg); |
577 else | 609 else |
578 event->Set("connectionTypes", base::MakeUnique<base::Value>()); | 610 event->Set("connectionTypes", base::MakeUnique<base::Value>()); |
579 } else { | 611 } else { |
580 event->Set("connectionTypes", base::MakeUnique<base::Value>()); | 612 event->Set("connectionTypes", base::MakeUnique<base::Value>()); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 label_dir_path.AppendASCII(kRegulatoryLabelImageFilename).MaybeAsASCII(); | 676 label_dir_path.AppendASCII(kRegulatoryLabelImageFilename).MaybeAsASCII(); |
645 std::string url = | 677 std::string url = |
646 std::string("chrome://") + chrome::kChromeOSAssetHost + "/" + image_path; | 678 std::string("chrome://") + chrome::kChromeOSAssetHost + "/" + image_path; |
647 regulatory_info->SetString("url", url); | 679 regulatory_info->SetString("url", url); |
648 | 680 |
649 ResolveJavascriptCallback(base::Value(callback_id), *regulatory_info); | 681 ResolveJavascriptCallback(base::Value(callback_id), *regulatory_info); |
650 } | 682 } |
651 #endif // defined(OS_CHROMEOS) | 683 #endif // defined(OS_CHROMEOS) |
652 | 684 |
653 } // namespace settings | 685 } // namespace settings |
OLD | NEW |