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

Unified Diff: chrome/browser/extensions/extension_warning_badge_service.cc

Issue 921423003: Rename ExtensionWarningBadgeService to WarningBadgeService (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_warning_badge_service.cc
diff --git a/chrome/browser/extensions/extension_warning_badge_service.cc b/chrome/browser/extensions/extension_warning_badge_service.cc
deleted file mode 100644
index 7afb6fcb4b490090bf2f6ee4e516b074892a139d..0000000000000000000000000000000000000000
--- a/chrome/browser/extensions/extension_warning_badge_service.cc
+++ /dev/null
@@ -1,152 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/extensions/extension_warning_badge_service.h"
-
-#include "base/stl_util.h"
-#include "chrome/app/chrome_command_ids.h"
-#include "chrome/browser/extensions/extension_warning_badge_service_factory.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/ui/browser_commands.h"
-#include "chrome/browser/ui/global_error/global_error.h"
-#include "chrome/browser/ui/global_error/global_error_service.h"
-#include "chrome/browser/ui/global_error/global_error_service_factory.h"
-#include "chrome/grit/generated_resources.h"
-#include "ui/base/l10n/l10n_util.h"
-
-namespace extensions {
-
-namespace {
-// Non-modal GlobalError implementation that warns the user if extensions
-// created warnings or errors. If the user clicks on the wrench menu, the user
-// is redirected to chrome://extensions to inspect the errors.
-class ErrorBadge : public GlobalError {
- public:
- explicit ErrorBadge(ExtensionWarningBadgeService* badge_service);
- ~ErrorBadge() override;
-
- // Implementation for GlobalError:
- bool HasMenuItem() override;
- int MenuItemCommandID() override;
- base::string16 MenuItemLabel() override;
- void ExecuteMenuItem(Browser* browser) override;
-
- bool HasBubbleView() override;
- bool HasShownBubbleView() override;
- void ShowBubbleView(Browser* browser) override;
- GlobalErrorBubbleViewBase* GetBubbleView() override;
-
- static int GetMenuItemCommandID();
-
- private:
- ExtensionWarningBadgeService* badge_service_;
-
- DISALLOW_COPY_AND_ASSIGN(ErrorBadge);
-};
-
-ErrorBadge::ErrorBadge(ExtensionWarningBadgeService* badge_service)
- : badge_service_(badge_service) {}
-
-ErrorBadge::~ErrorBadge() {}
-
-bool ErrorBadge::HasMenuItem() {
- return true;
-}
-
-int ErrorBadge::MenuItemCommandID() {
- return GetMenuItemCommandID();
-}
-
-base::string16 ErrorBadge::MenuItemLabel() {
- return l10n_util::GetStringUTF16(IDS_EXTENSION_WARNINGS_WRENCH_MENU_ITEM);
-}
-
-void ErrorBadge::ExecuteMenuItem(Browser* browser) {
- // Suppress all current warnings in the extension service from triggering
- // a badge on the wrench menu in the future of this session.
- badge_service_->SuppressCurrentWarnings();
-
- chrome::ExecuteCommand(browser, IDC_MANAGE_EXTENSIONS);
-}
-
-bool ErrorBadge::HasBubbleView() { return false; }
-
-bool ErrorBadge::HasShownBubbleView() { return false; }
-
-void ErrorBadge::ShowBubbleView(Browser* browser) { NOTREACHED(); }
-
-GlobalErrorBubbleViewBase* ErrorBadge::GetBubbleView() {
- return NULL;
-}
-
-// static
-int ErrorBadge::GetMenuItemCommandID() {
- return IDC_EXTENSION_ERRORS;
-}
-
-} // namespace
-
-ExtensionWarningBadgeService::ExtensionWarningBadgeService(Profile* profile)
- : profile_(profile), warning_service_observer_(this) {
- DCHECK(CalledOnValidThread());
- warning_service_observer_.Add(WarningService::Get(profile_));
-}
-
-ExtensionWarningBadgeService::~ExtensionWarningBadgeService() {}
-
-// static
-ExtensionWarningBadgeService* ExtensionWarningBadgeService::Get(
- content::BrowserContext* context) {
- return ExtensionWarningBadgeServiceFactory::GetForBrowserContext(context);
-}
-
-void ExtensionWarningBadgeService::SuppressCurrentWarnings() {
- DCHECK(CalledOnValidThread());
- size_t old_size = suppressed_warnings_.size();
-
- const WarningSet& warnings = GetCurrentWarnings();
- suppressed_warnings_.insert(warnings.begin(), warnings.end());
-
- if (old_size != suppressed_warnings_.size())
- UpdateBadgeStatus();
-}
-
-const WarningSet& ExtensionWarningBadgeService::GetCurrentWarnings() const {
- return WarningService::Get(profile_)->warnings();
-}
-
-void ExtensionWarningBadgeService::ExtensionWarningsChanged() {
- DCHECK(CalledOnValidThread());
- UpdateBadgeStatus();
-}
-
-void ExtensionWarningBadgeService::UpdateBadgeStatus() {
- const std::set<Warning>& warnings = GetCurrentWarnings();
- bool non_suppressed_warnings_exist = false;
- for (std::set<Warning>::const_iterator i = warnings.begin();
- i != warnings.end(); ++i) {
- if (!ContainsKey(suppressed_warnings_, *i)) {
- non_suppressed_warnings_exist = true;
- break;
- }
- }
- ShowBadge(non_suppressed_warnings_exist);
-}
-
-void ExtensionWarningBadgeService::ShowBadge(bool show) {
- GlobalErrorService* service =
- GlobalErrorServiceFactory::GetForProfile(profile_);
- GlobalError* error = service->GetGlobalErrorByMenuItemCommandID(
- ErrorBadge::GetMenuItemCommandID());
-
- // Activate or hide the warning badge in case the current state is incorrect.
- if (error && !show) {
- service->RemoveGlobalError(error);
- delete error;
- } else if (!error && show) {
- service->AddGlobalError(new ErrorBadge(this));
- }
-}
-
-} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698