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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2009 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.
4
5 #include "chrome/browser/extensions/extension_toolbar_model.h"
6
7 #include "chrome/browser/extensions/extensions_service.h"
8 #include "chrome/common/extensions/extension.h"
9 #include "chrome/common/notification_service.h"
10
11 ExtensionToolbarModel::ExtensionToolbarModel(ExtensionsService* service)
12 : service_(service) {
13 DCHECK(service_);
14
15 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
16 Source<Profile>(service_->profile()));
17 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
18 Source<Profile>(service_->profile()));
19 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED,
20 Source<Profile>(service_->profile()));
21 registrar_.Add(this, NotificationType::EXTENSIONS_READY,
22 Source<Profile>(service_->profile()));
23 }
24
25 ExtensionToolbarModel::~ExtensionToolbarModel() {
26 }
27
28 void ExtensionToolbarModel::AddObserver(Observer* observer) {
29 observers_.AddObserver(observer);
30 }
31
32 void ExtensionToolbarModel::RemoveObserver(Observer* observer) {
33 observers_.RemoveObserver(observer);
34 }
35
36 void ExtensionToolbarModel::Observe(NotificationType type,
37 const NotificationSource& source,
38 const NotificationDetails& details) {
39 if (type == NotificationType::EXTENSIONS_READY) {
40 for (size_t i = 0; i < service_->extensions()->size(); ++i) {
41 Extension* extension = service_->GetExtensionById(
42 service_->extensions()->at(i)->id(), false);
43 AddExtension(extension);
44 }
45 return;
46 }
47
48 Extension* extension = Details<Extension>(details).ptr();
49 if (type == NotificationType::EXTENSION_LOADED) {
50 if (service_->is_ready())
51 AddExtension(extension);
52 } else if (type == NotificationType::EXTENSION_UNLOADED ||
53 type == NotificationType::EXTENSION_UNLOADED_DISABLED) {
54 RemoveExtension(extension);
55 } else {
56 NOTREACHED() << "Received unexpected notification";
57 }
58 }
59
60 void ExtensionToolbarModel::AddExtension(Extension* extension) {
61 // We only care about extensions with browser actions.
62 if (!extension->browser_action())
63 return;
64
65 toolitems_.push_back(extension);
66 FOR_EACH_OBSERVER(Observer, observers_,
67 BrowserActionAdded(extension, toolitems_.size() - 1));
68 }
69
70 void ExtensionToolbarModel::RemoveExtension(Extension* extension) {
71 ExtensionList::iterator pos = std::find(begin(), end(), extension);
72 if (pos != end()) {
73 toolitems_.erase(pos);
74 FOR_EACH_OBSERVER(Observer, observers_,
75 BrowserActionRemoved(extension));
76 }
77 }
OLDNEW
« 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