1 // Copyright 2013 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.
5 #include "ui/app_list/app_list_item.h"
7 #include "base/logging.h"
8 #include "ui/app_list/app_list_item_observer.h"
12 AppListItem::AppListItem(const std::string
& id
)
15 is_installing_(false),
16 percent_downloaded_(-1) {
19 AppListItem::~AppListItem() {
20 FOR_EACH_OBSERVER(AppListItemObserver
, observers_
, ItemBeingDestroyed());
23 void AppListItem::SetIcon(const gfx::ImageSkia
& icon
) {
25 FOR_EACH_OBSERVER(AppListItemObserver
, observers_
, ItemIconChanged());
28 void AppListItem::SetIsInstalling(bool is_installing
) {
29 if (is_installing_
== is_installing
)
32 is_installing_
= is_installing
;
33 FOR_EACH_OBSERVER(AppListItemObserver
,
35 ItemIsInstallingChanged());
38 void AppListItem::SetPercentDownloaded(int percent_downloaded
) {
39 if (percent_downloaded_
== percent_downloaded
)
42 percent_downloaded_
= percent_downloaded
;
43 FOR_EACH_OBSERVER(AppListItemObserver
,
45 ItemPercentDownloadedChanged());
48 void AppListItem::AddObserver(AppListItemObserver
* observer
) {
49 observers_
.AddObserver(observer
);
52 void AppListItem::RemoveObserver(AppListItemObserver
* observer
) {
53 observers_
.RemoveObserver(observer
);
56 void AppListItem::Activate(int event_flags
) {
59 const char* AppListItem::GetItemType() const {
60 static const char* app_type
= "";
64 ui::MenuModel
* AppListItem::GetContextMenuModel() {
68 AppListItem
* AppListItem::FindChildItem(const std::string
& id
) {
72 size_t AppListItem::ChildItemCount() const {
76 void AppListItem::OnExtensionPreferenceChanged() {}
78 bool AppListItem::CompareForTest(const AppListItem
* other
) const {
79 return id_
== other
->id_
&&
80 folder_id_
== other
->folder_id_
&&
81 name_
== other
->name_
&&
82 short_name_
== other
->short_name_
&&
83 GetItemType() == other
->GetItemType() &&
84 position_
.Equals(other
->position_
);
87 std::string
AppListItem::ToDebugString() const {
88 return id_
.substr(0, 8) + " '" + name_
+ "'"
89 + " [" + position_
.ToDebugString() + "]";
94 void AppListItem::SetName(const std::string
& name
) {
95 if (name_
== name
&& (short_name_
.empty() || short_name_
== name
))
99 FOR_EACH_OBSERVER(AppListItemObserver
, observers_
, ItemNameChanged());
102 void AppListItem::SetNameAndShortName(const std::string
& name
,
103 const std::string
& short_name
) {
104 if (name_
== name
&& short_name_
== short_name
)
107 short_name_
= short_name
;
108 FOR_EACH_OBSERVER(AppListItemObserver
, observers_
, ItemNameChanged());
111 } // namespace app_list