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

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

Issue 462026: Extensions: create a simple model for the browser action buttons toolstrip an... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years 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
« no previous file with comments | « chrome/browser/extensions/extension_toolbar_model.h ('k') | chrome/browser/extensions/extensions_service.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/extension_toolbar_model.cc
===================================================================
--- chrome/browser/extensions/extension_toolbar_model.cc (revision 0)
+++ chrome/browser/extensions/extension_toolbar_model.cc (revision 0)
@@ -0,0 +1,77 @@
+// Copyright (c) 2009 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_toolbar_model.h"
+
+#include "chrome/browser/extensions/extensions_service.h"
+#include "chrome/common/extensions/extension.h"
+#include "chrome/common/notification_service.h"
+
+ExtensionToolbarModel::ExtensionToolbarModel(ExtensionsService* service)
+ : service_(service) {
+ DCHECK(service_);
+
+ registrar_.Add(this, NotificationType::EXTENSION_LOADED,
+ Source<Profile>(service_->profile()));
+ registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
+ Source<Profile>(service_->profile()));
+ registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED,
+ Source<Profile>(service_->profile()));
+ registrar_.Add(this, NotificationType::EXTENSIONS_READY,
+ Source<Profile>(service_->profile()));
+}
+
+ExtensionToolbarModel::~ExtensionToolbarModel() {
+}
+
+void ExtensionToolbarModel::AddObserver(Observer* observer) {
+ observers_.AddObserver(observer);
+}
+
+void ExtensionToolbarModel::RemoveObserver(Observer* observer) {
+ observers_.RemoveObserver(observer);
+}
+
+void ExtensionToolbarModel::Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ if (type == NotificationType::EXTENSIONS_READY) {
+ for (size_t i = 0; i < service_->extensions()->size(); ++i) {
+ Extension* extension = service_->GetExtensionById(
+ service_->extensions()->at(i)->id(), false);
+ AddExtension(extension);
+ }
+ return;
+ }
+
+ Extension* extension = Details<Extension>(details).ptr();
+ if (type == NotificationType::EXTENSION_LOADED) {
+ if (service_->is_ready())
+ AddExtension(extension);
+ } else if (type == NotificationType::EXTENSION_UNLOADED ||
+ type == NotificationType::EXTENSION_UNLOADED_DISABLED) {
+ RemoveExtension(extension);
+ } else {
+ NOTREACHED() << "Received unexpected notification";
+ }
+}
+
+void ExtensionToolbarModel::AddExtension(Extension* extension) {
+ // We only care about extensions with browser actions.
+ if (!extension->browser_action())
+ return;
+
+ toolitems_.push_back(extension);
+ FOR_EACH_OBSERVER(Observer, observers_,
+ BrowserActionAdded(extension, toolitems_.size() - 1));
+}
+
+void ExtensionToolbarModel::RemoveExtension(Extension* extension) {
+ ExtensionList::iterator pos = std::find(begin(), end(), extension);
+ if (pos != end()) {
+ toolitems_.erase(pos);
+ FOR_EACH_OBSERVER(Observer, observers_,
+ BrowserActionRemoved(extension));
+ }
+}
Property changes on: chrome/browser/extensions/extension_toolbar_model.cc
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « chrome/browser/extensions/extension_toolbar_model.h ('k') | chrome/browser/extensions/extensions_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698