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

Side by Side Diff: chrome/browser/extensions/extension_warning_badge_service.cc

Issue 698623002: Split WarningService from ExtensionSystem. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/extensions/extension_warning_badge_service.h" 5 #include "chrome/browser/extensions/extension_warning_badge_service.h"
6 6
7 #include "base/stl_util.h" 7 #include "base/stl_util.h"
8 #include "chrome/app/chrome_command_ids.h" 8 #include "chrome/app/chrome_command_ids.h"
9 #include "chrome/browser/extensions/extension_warning_badge_service_factory.h"
9 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser_commands.h" 11 #include "chrome/browser/ui/browser_commands.h"
11 #include "chrome/browser/ui/global_error/global_error.h" 12 #include "chrome/browser/ui/global_error/global_error.h"
12 #include "chrome/browser/ui/global_error/global_error_service.h" 13 #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/ui/global_error/global_error_service_factory.h"
14 #include "chrome/grit/generated_resources.h" 15 #include "chrome/grit/generated_resources.h"
15 #include "extensions/browser/extension_system.h"
16 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/base/l10n/l10n_util.h"
17 17
18 namespace extensions { 18 namespace extensions {
19 19
20 namespace { 20 namespace {
21 // Non-modal GlobalError implementation that warns the user if extensions 21 // Non-modal GlobalError implementation that warns the user if extensions
22 // created warnings or errors. If the user clicks on the wrench menu, the user 22 // created warnings or errors. If the user clicks on the wrench menu, the user
23 // is redirected to chrome://extensions to inspect the errors. 23 // is redirected to chrome://extensions to inspect the errors.
24 class ErrorBadge : public GlobalError { 24 class ErrorBadge : public GlobalError {
25 public: 25 public:
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 return NULL; 80 return NULL;
81 } 81 }
82 82
83 // static 83 // static
84 int ErrorBadge::GetMenuItemCommandID() { 84 int ErrorBadge::GetMenuItemCommandID() {
85 return IDC_EXTENSION_ERRORS; 85 return IDC_EXTENSION_ERRORS;
86 } 86 }
87 87
88 } // namespace 88 } // namespace
89 89
90
91 ExtensionWarningBadgeService::ExtensionWarningBadgeService(Profile* profile) 90 ExtensionWarningBadgeService::ExtensionWarningBadgeService(Profile* profile)
92 : profile_(profile) { 91 : profile_(profile), warning_service_observer_(this) {
93 DCHECK(CalledOnValidThread()); 92 DCHECK(CalledOnValidThread());
93 warning_service_observer_.Add(WarningService::Get(profile_));
Marijn Kruisselbrink 2014/10/31 20:38:09 The old code removed this observer in the Shutdown
94 } 94 }
95 95
96 ExtensionWarningBadgeService::~ExtensionWarningBadgeService() {} 96 ExtensionWarningBadgeService::~ExtensionWarningBadgeService() {}
97 97
98 // static
99 ExtensionWarningBadgeService* ExtensionWarningBadgeService::Get(
100 content::BrowserContext* context) {
101 return ExtensionWarningBadgeServiceFactory::GetForBrowserContext(context);
102 }
103
98 void ExtensionWarningBadgeService::SuppressCurrentWarnings() { 104 void ExtensionWarningBadgeService::SuppressCurrentWarnings() {
99 DCHECK(CalledOnValidThread()); 105 DCHECK(CalledOnValidThread());
100 size_t old_size = suppressed_warnings_.size(); 106 size_t old_size = suppressed_warnings_.size();
101 107
102 const WarningSet& warnings = GetCurrentWarnings(); 108 const WarningSet& warnings = GetCurrentWarnings();
103 suppressed_warnings_.insert(warnings.begin(), warnings.end()); 109 suppressed_warnings_.insert(warnings.begin(), warnings.end());
104 110
105 if (old_size != suppressed_warnings_.size()) 111 if (old_size != suppressed_warnings_.size())
106 UpdateBadgeStatus(); 112 UpdateBadgeStatus();
107 } 113 }
108 114
109 const WarningSet& ExtensionWarningBadgeService::GetCurrentWarnings() const { 115 const WarningSet& ExtensionWarningBadgeService::GetCurrentWarnings() const {
110 return ExtensionSystem::Get(profile_)->warning_service()->warnings(); 116 return WarningService::Get(profile_)->warnings();
111 } 117 }
112 118
113 void ExtensionWarningBadgeService::ExtensionWarningsChanged() { 119 void ExtensionWarningBadgeService::ExtensionWarningsChanged() {
114 DCHECK(CalledOnValidThread()); 120 DCHECK(CalledOnValidThread());
115 UpdateBadgeStatus(); 121 UpdateBadgeStatus();
116 } 122 }
117 123
118 void ExtensionWarningBadgeService::UpdateBadgeStatus() { 124 void ExtensionWarningBadgeService::UpdateBadgeStatus() {
119 const std::set<Warning>& warnings = GetCurrentWarnings(); 125 const std::set<Warning>& warnings = GetCurrentWarnings();
120 bool non_suppressed_warnings_exist = false; 126 bool non_suppressed_warnings_exist = false;
(...skipping 16 matching lines...) Expand all
137 // Activate or hide the warning badge in case the current state is incorrect. 143 // Activate or hide the warning badge in case the current state is incorrect.
138 if (error && !show) { 144 if (error && !show) {
139 service->RemoveGlobalError(error); 145 service->RemoveGlobalError(error);
140 delete error; 146 delete error;
141 } else if (!error && show) { 147 } else if (!error && show) {
142 service->AddGlobalError(new ErrorBadge(this)); 148 service->AddGlobalError(new ErrorBadge(this));
143 } 149 }
144 } 150 }
145 151
146 } // namespace extensions 152 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698