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

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

Issue 2925973002: Migrate upgrade notifications to observer (Closed)
Patch Set: Add DISALLOW_COPY_AND_ASSIGN Created 3 years, 6 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') | chrome/browser/upgrade_detector.h » ('j') | 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_number_conversions.h"
23 #include "base/strings/string_util.h" 23 #include "base/strings/string_util.h"
24 #include "base/strings/utf_string_conversions.h" 24 #include "base/strings/utf_string_conversions.h"
25 #include "base/task_scheduler/post_task.h" 25 #include "base/task_scheduler/post_task.h"
26 #include "base/time/time.h" 26 #include "base/time/time.h"
27 #include "base/values.h" 27 #include "base/values.h"
28 #include "build/build_config.h" 28 #include "build/build_config.h"
29 #include "chrome/browser/browser_process.h" 29 #include "chrome/browser/browser_process.h"
30 #include "chrome/browser/chrome_notification_types.h"
31 #include "chrome/browser/obsolete_system/obsolete_system.h" 30 #include "chrome/browser/obsolete_system/obsolete_system.h"
32 #include "chrome/browser/ui/browser.h" 31 #include "chrome/browser/ui/browser.h"
33 #include "chrome/browser/ui/browser_commands.h" 32 #include "chrome/browser/ui/browser_commands.h"
34 #include "chrome/browser/ui/browser_finder.h" 33 #include "chrome/browser/ui/browser_finder.h"
35 #include "chrome/browser/ui/chrome_pages.h" 34 #include "chrome/browser/ui/chrome_pages.h"
35 #include "chrome/browser/upgrade_detector.h"
36 #include "chrome/common/channel_info.h" 36 #include "chrome/common/channel_info.h"
37 #include "chrome/common/chrome_content_client.h" 37 #include "chrome/common/chrome_content_client.h"
38 #include "chrome/common/pref_names.h" 38 #include "chrome/common/pref_names.h"
39 #include "chrome/common/url_constants.h" 39 #include "chrome/common/url_constants.h"
40 #include "chrome/grit/chromium_strings.h" 40 #include "chrome/grit/chromium_strings.h"
41 #include "chrome/grit/generated_resources.h" 41 #include "chrome/grit/generated_resources.h"
42 #include "components/google/core/browser/google_util.h" 42 #include "components/google/core/browser/google_util.h"
43 #include "components/policy/core/common/policy_namespace.h" 43 #include "components/policy/core/common/policy_namespace.h"
44 #include "components/policy/policy_constants.h" 44 #include "components/policy/policy_constants.h"
45 #include "components/strings/grit/components_chromium_strings.h" 45 #include "components/strings/grit/components_chromium_strings.h"
46 #include "components/strings/grit/components_strings.h" 46 #include "components/strings/grit/components_strings.h"
47 #include "components/version_info/version_info.h" 47 #include "components/version_info/version_info.h"
48 #include "content/public/browser/browser_thread.h" 48 #include "content/public/browser/browser_thread.h"
49 #include "content/public/browser/notification_service.h"
50 #include "content/public/browser/web_contents.h" 49 #include "content/public/browser/web_contents.h"
51 #include "content/public/browser/web_ui.h" 50 #include "content/public/browser/web_ui.h"
52 #include "content/public/browser/web_ui_data_source.h" 51 #include "content/public/browser/web_ui_data_source.h"
53 #include "content/public/common/user_agent.h" 52 #include "content/public/common/user_agent.h"
54 #include "ui/base/l10n/l10n_util.h" 53 #include "ui/base/l10n/l10n_util.h"
55 #include "v8/include/v8-version-string.h" 54 #include "v8/include/v8-version-string.h"
56 55
57 #if defined(OS_CHROMEOS) 56 #if defined(OS_CHROMEOS)
58 #include "base/files/file_util_proxy.h" 57 #include "base/files/file_util_proxy.h"
59 #include "base/i18n/time_formatting.h" 58 #include "base/i18n/time_formatting.h"
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 break; 257 break;
259 } 258 }
260 259
261 return status_str; 260 return status_str;
262 } 261 }
263 262
264 } // namespace 263 } // namespace
265 264
266 namespace settings { 265 namespace settings {
267 266
268 AboutHandler::AboutHandler() : weak_factory_(this) {} 267 AboutHandler::AboutHandler()
268 : apply_changes_from_upgrade_observer_(false), weak_factory_(this) {
269 UpgradeDetector::GetInstance()->AddObserver(this);
270 }
269 271
270 AboutHandler::~AboutHandler() {} 272 AboutHandler::~AboutHandler() {
273 UpgradeDetector::GetInstance()->RemoveObserver(this);
274 }
271 275
272 AboutHandler* AboutHandler::Create(content::WebUIDataSource* html_source, 276 AboutHandler* AboutHandler::Create(content::WebUIDataSource* html_source,
273 Profile* profile) { 277 Profile* profile) {
274 html_source->AddString( 278 html_source->AddString(
275 "aboutBrowserVersion", 279 "aboutBrowserVersion",
276 l10n_util::GetStringFUTF16( 280 l10n_util::GetStringFUTF16(
277 IDS_SETTINGS_ABOUT_PAGE_BROWSER_VERSION, 281 IDS_SETTINGS_ABOUT_PAGE_BROWSER_VERSION,
278 base::UTF8ToUTF16(version_info::GetVersionNumber()), 282 base::UTF8ToUTF16(version_info::GetVersionNumber()),
279 l10n_util::GetStringUTF16(version_info::IsOfficialBuild() 283 l10n_util::GetStringUTF16(version_info::IsOfficialBuild()
280 ? IDS_VERSION_UI_OFFICIAL 284 ? IDS_VERSION_UI_OFFICIAL
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 #endif 382 #endif
379 383
380 #if defined(OS_CHROMEOS) 384 #if defined(OS_CHROMEOS)
381 // Handler for the product label image, which will be shown if available. 385 // Handler for the product label image, which will be shown if available.
382 content::URLDataSource::Add(Profile::FromWebUI(web_ui()), 386 content::URLDataSource::Add(Profile::FromWebUI(web_ui()),
383 new chromeos::ImageSource()); 387 new chromeos::ImageSource());
384 #endif 388 #endif
385 } 389 }
386 390
387 void AboutHandler::OnJavascriptAllowed() { 391 void AboutHandler::OnJavascriptAllowed() {
392 apply_changes_from_upgrade_observer_ = true;
388 version_updater_.reset(VersionUpdater::Create(web_ui()->GetWebContents())); 393 version_updater_.reset(VersionUpdater::Create(web_ui()->GetWebContents()));
389 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
390 content::NotificationService::AllSources());
391 policy_registrar_.reset(new policy::PolicyChangeRegistrar( 394 policy_registrar_.reset(new policy::PolicyChangeRegistrar(
392 g_browser_process->policy_service(), 395 g_browser_process->policy_service(),
393 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, std::string()))); 396 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, std::string())));
394 policy_registrar_->Observe( 397 policy_registrar_->Observe(
395 policy::key::kDeviceAutoUpdateDisabled, 398 policy::key::kDeviceAutoUpdateDisabled,
396 base::Bind(&AboutHandler::OnDeviceAutoUpdatePolicyChanged, 399 base::Bind(&AboutHandler::OnDeviceAutoUpdatePolicyChanged,
397 base::Unretained(this))); 400 base::Unretained(this)));
398 } 401 }
399 402
400 void AboutHandler::OnJavascriptDisallowed() { 403 void AboutHandler::OnJavascriptDisallowed() {
404 apply_changes_from_upgrade_observer_ = false;
401 version_updater_.reset(); 405 version_updater_.reset();
402 policy_registrar_.reset(); 406 policy_registrar_.reset();
403 registrar_.Remove(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
404 content::NotificationService::AllSources());
405 } 407 }
406 408
407 void AboutHandler::Observe(int type, 409 void AboutHandler::OnUpgradeRecommended() {
408 const content::NotificationSource& source, 410 if (apply_changes_from_upgrade_observer_) {
409 const content::NotificationDetails& details) { 411 // A version update is installed and ready to go. Refresh the UI so the
410 DCHECK_EQ(chrome::NOTIFICATION_UPGRADE_RECOMMENDED, type); 412 // correct state will be shown.
411 413 RequestUpdate();
412 // A version update is installed and ready to go. Refresh the UI so the 414 }
413 // correct state will be shown.
414 RequestUpdate();
415 } 415 }
416 416
417 void AboutHandler::OnDeviceAutoUpdatePolicyChanged( 417 void AboutHandler::OnDeviceAutoUpdatePolicyChanged(
418 const base::Value* previous_policy, 418 const base::Value* previous_policy,
419 const base::Value* current_policy) { 419 const base::Value* current_policy) {
420 bool previous_auto_update_disabled = false; 420 bool previous_auto_update_disabled = false;
421 if (previous_policy) 421 if (previous_policy)
422 CHECK(previous_policy->GetAsBoolean(&previous_auto_update_disabled)); 422 CHECK(previous_policy->GetAsBoolean(&previous_auto_update_disabled));
423 423
424 bool current_auto_update_disabled = false; 424 bool current_auto_update_disabled = false;
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 label_dir_path.AppendASCII(kRegulatoryLabelImageFilename).MaybeAsASCII(); 686 label_dir_path.AppendASCII(kRegulatoryLabelImageFilename).MaybeAsASCII();
687 std::string url = 687 std::string url =
688 std::string("chrome://") + chrome::kChromeOSAssetHost + "/" + image_path; 688 std::string("chrome://") + chrome::kChromeOSAssetHost + "/" + image_path;
689 regulatory_info->SetString("url", url); 689 regulatory_info->SetString("url", url);
690 690
691 ResolveJavascriptCallback(base::Value(callback_id), *regulatory_info); 691 ResolveJavascriptCallback(base::Value(callback_id), *regulatory_info);
692 } 692 }
693 #endif // defined(OS_CHROMEOS) 693 #endif // defined(OS_CHROMEOS)
694 694
695 } // namespace settings 695 } // namespace settings
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/settings/about_handler.h ('k') | chrome/browser/upgrade_detector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698