Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / recovery / recovery_install_global_error.cc
blobce80798ef63db106d53ceeb4662a83813ab04676
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/recovery/recovery_install_global_error.h"
7 #include "base/prefs/pref_service.h"
8 #include "chrome/app/chrome_command_ids.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/component_updater/recovery_component_installer.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/global_error/global_error_service.h"
13 #include "chrome/browser/ui/global_error/global_error_service_factory.h"
14 #include "chrome/browser/upgrade_detector.h"
15 #include "chrome/common/chrome_switches.h"
16 #include "chrome/common/pref_names.h"
17 #include "grit/chromium_strings.h"
18 #include "grit/theme_resources.h"
19 #include "ui/base/l10n/l10n_util.h"
20 #include "ui/base/resource/resource_bundle.h"
22 RecoveryInstallGlobalError::RecoveryInstallGlobalError(Profile* profile)
23 : elevation_needed_(false),
24 profile_(profile),
25 has_shown_bubble_view_(false) {
26 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError(this);
28 PrefService* pref = g_browser_process->local_state();
29 if (pref->FindPreference(prefs::kRecoveryComponentNeedsElevation)) {
30 elevation_needed_ =
31 pref->GetBoolean(prefs::kRecoveryComponentNeedsElevation);
33 if (elevation_needed_) {
34 GlobalErrorServiceFactory::GetForProfile(profile_)->NotifyErrorsChanged(
35 this);
38 pref_registrar_.Init(pref);
39 pref_registrar_.Add(
40 prefs::kRecoveryComponentNeedsElevation,
41 base::Bind(&RecoveryInstallGlobalError::OnElevationRequirementChanged,
42 base::Unretained(this)));
45 RecoveryInstallGlobalError::~RecoveryInstallGlobalError() {
48 void RecoveryInstallGlobalError::Shutdown() {
49 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError(this);
52 GlobalError::Severity RecoveryInstallGlobalError::GetSeverity() {
53 return GlobalError::SEVERITY_HIGH;
56 bool RecoveryInstallGlobalError::HasMenuItem() {
57 return HasElevationNotification();
60 int RecoveryInstallGlobalError::MenuItemCommandID() {
61 return IDC_ELEVATED_RECOVERY_DIALOG;
64 base::string16 RecoveryInstallGlobalError::MenuItemLabel() {
65 return l10n_util::GetStringUTF16(IDS_UPDATE_NOW);
68 gfx::Image RecoveryInstallGlobalError::MenuItemIcon() {
69 return ResourceBundle::GetSharedInstance().GetNativeImageNamed(
70 IDR_UPDATE_MENU_SEVERITY_HIGH);
73 void RecoveryInstallGlobalError::ExecuteMenuItem(Browser* browser) {
74 ShowBubbleView(browser);
77 bool RecoveryInstallGlobalError::HasBubbleView() {
78 return HasElevationNotification();
81 bool RecoveryInstallGlobalError::HasShownBubbleView() {
82 return has_shown_bubble_view_;
85 void RecoveryInstallGlobalError::ShowBubbleView(Browser* browser) {
86 GlobalErrorWithStandardBubble::ShowBubbleView(browser);
87 has_shown_bubble_view_ = true;
90 bool RecoveryInstallGlobalError::ShouldCloseOnDeactivate() const {
91 return false;
94 gfx::Image RecoveryInstallGlobalError::GetBubbleViewIcon() {
95 return ResourceBundle::GetSharedInstance().GetNativeImageNamed(
96 IDR_UPDATE_MENU_SEVERITY_HIGH);
99 base::string16 RecoveryInstallGlobalError::GetBubbleViewTitle() {
100 return l10n_util::GetStringUTF16(IDS_RECOVERY_BUBBLE_TITLE);
103 std::vector<base::string16>
104 RecoveryInstallGlobalError::GetBubbleViewMessages() {
105 return std::vector<base::string16>(1,
106 l10n_util::GetStringUTF16(IDS_RECOVERY_BUBBLE_TEXT));
109 base::string16 RecoveryInstallGlobalError::GetBubbleViewAcceptButtonLabel() {
110 return l10n_util::GetStringUTF16(IDS_RUN_RECOVERY);
113 bool RecoveryInstallGlobalError::ShouldShowCloseButton() const {
114 return true;
117 bool RecoveryInstallGlobalError::ShouldAddElevationIconToAcceptButton() {
118 return true;
121 base::string16 RecoveryInstallGlobalError::GetBubbleViewCancelButtonLabel() {
122 return l10n_util::GetStringUTF16(IDS_DECLINE_RECOVERY);
125 void RecoveryInstallGlobalError::OnBubbleViewDidClose(Browser* browser) {
128 void RecoveryInstallGlobalError::BubbleViewAcceptButtonPressed(
129 Browser* browser) {
130 component_updater::AcceptedElevatedRecoveryInstall(pref_registrar_.prefs());
133 void RecoveryInstallGlobalError::BubbleViewCancelButtonPressed(
134 Browser* browser) {
135 component_updater::DeclinedElevatedRecoveryInstall(pref_registrar_.prefs());
138 bool RecoveryInstallGlobalError::HasElevationNotification() const {
139 // Do not show this bubble if we already have an upgrade notice.
140 return elevation_needed_ && !UpgradeDetector::GetInstance()->notify_upgrade();
143 void RecoveryInstallGlobalError::OnElevationRequirementChanged() {
144 PrefService* pref = pref_registrar_.prefs();
145 DCHECK(pref->FindPreference(prefs::kRecoveryComponentNeedsElevation));
146 elevation_needed_ = pref->GetBoolean(prefs::kRecoveryComponentNeedsElevation);
148 // Got a new elevation request, resets |has_shown_bubble_view_| so the
149 // bubble has a higher priority to show.
150 if (elevation_needed_)
151 has_shown_bubble_view_ = false;
153 GlobalErrorServiceFactory::GetForProfile(profile_)->NotifyErrorsChanged(this);