OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 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_toolbar_model.h" | 5 #include "chrome/browser/extensions/extension_toolbar_model.h" |
6 | 6 |
7 #include "chrome/browser/extensions/extensions_service.h" | 7 #include "chrome/browser/extensions/extensions_service.h" |
8 #include "chrome/common/extensions/extension.h" | 8 #include "chrome/common/extensions/extension.h" |
9 #include "chrome/common/notification_service.h" | 9 #include "chrome/common/notification_service.h" |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 } | 26 } |
27 | 27 |
28 void ExtensionToolbarModel::AddObserver(Observer* observer) { | 28 void ExtensionToolbarModel::AddObserver(Observer* observer) { |
29 observers_.AddObserver(observer); | 29 observers_.AddObserver(observer); |
30 } | 30 } |
31 | 31 |
32 void ExtensionToolbarModel::RemoveObserver(Observer* observer) { | 32 void ExtensionToolbarModel::RemoveObserver(Observer* observer) { |
33 observers_.RemoveObserver(observer); | 33 observers_.RemoveObserver(observer); |
34 } | 34 } |
35 | 35 |
| 36 void ExtensionToolbarModel::MoveBrowserAction(Extension* extension, |
| 37 int index) { |
| 38 ExtensionList::iterator pos = std::find(begin(), end(), extension); |
| 39 if (pos == end()) { |
| 40 NOTREACHED(); |
| 41 return; |
| 42 } |
| 43 toolitems_.erase(pos); |
| 44 |
| 45 int i = 0; |
| 46 bool inserted = false; |
| 47 for (ExtensionList::iterator iter = begin(); iter != end(); ++iter, ++i) { |
| 48 if (i == index) { |
| 49 toolitems_.insert(pos, extension); |
| 50 inserted = true; |
| 51 break; |
| 52 } |
| 53 } |
| 54 |
| 55 if (!inserted) { |
| 56 DCHECK_EQ(index, static_cast<int>(toolitems_.size())); |
| 57 index = toolitems_.size(); |
| 58 |
| 59 toolitems_.push_back(extension); |
| 60 } |
| 61 |
| 62 FOR_EACH_OBSERVER(Observer, observers_, BrowserActionMoved(extension, index)); |
| 63 } |
| 64 |
36 void ExtensionToolbarModel::Observe(NotificationType type, | 65 void ExtensionToolbarModel::Observe(NotificationType type, |
37 const NotificationSource& source, | 66 const NotificationSource& source, |
38 const NotificationDetails& details) { | 67 const NotificationDetails& details) { |
39 if (type == NotificationType::EXTENSIONS_READY) { | 68 if (type == NotificationType::EXTENSIONS_READY) { |
40 for (size_t i = 0; i < service_->extensions()->size(); ++i) { | 69 for (size_t i = 0; i < service_->extensions()->size(); ++i) { |
41 Extension* extension = service_->GetExtensionById( | 70 Extension* extension = service_->GetExtensionById( |
42 service_->extensions()->at(i)->id(), false); | 71 service_->extensions()->at(i)->id(), false); |
43 AddExtension(extension); | 72 AddExtension(extension); |
44 } | 73 } |
45 return; | 74 return; |
(...skipping 24 matching lines...) Expand all Loading... |
70 } | 99 } |
71 | 100 |
72 void ExtensionToolbarModel::RemoveExtension(Extension* extension) { | 101 void ExtensionToolbarModel::RemoveExtension(Extension* extension) { |
73 ExtensionList::iterator pos = std::find(begin(), end(), extension); | 102 ExtensionList::iterator pos = std::find(begin(), end(), extension); |
74 if (pos != end()) { | 103 if (pos != end()) { |
75 toolitems_.erase(pos); | 104 toolitems_.erase(pos); |
76 FOR_EACH_OBSERVER(Observer, observers_, | 105 FOR_EACH_OBSERVER(Observer, observers_, |
77 BrowserActionRemoved(extension)); | 106 BrowserActionRemoved(extension)); |
78 } | 107 } |
79 } | 108 } |
OLD | NEW |