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 "ash/launcher/launcher_item_delegate_manager.h"
7 #include "ash/launcher/launcher_item_delegate.h"
8 #include "ash/launcher/launcher_model.h"
10 #include "base/logging.h"
11 #include "base/stl_util.h"
15 LauncherItemDelegateManager::LauncherItemDelegateManager(
16 ash::LauncherModel
* model
) : model_(model
) {
18 model_
->AddObserver(this);
21 LauncherItemDelegateManager::~LauncherItemDelegateManager() {
22 model_
->RemoveObserver(this);
23 STLDeleteContainerPairSecondPointers(id_to_item_delegate_map_
.begin(),
24 id_to_item_delegate_map_
.end());
27 void LauncherItemDelegateManager::SetLauncherItemDelegate(
29 scoped_ptr
<LauncherItemDelegate
> item_delegate
) {
30 // If another LauncherItemDelegate is already registered for |id|, we assume
31 // that this request is replacing LauncherItemDelegate for |id| with
33 RemoveLauncherItemDelegate(id
);
34 id_to_item_delegate_map_
[id
] = item_delegate
.release();
37 LauncherItemDelegate
* LauncherItemDelegateManager::GetLauncherItemDelegate(
39 if (model_
->ItemIndexByID(id
) != -1) {
40 // Each LauncherItem has to have a LauncherItemDelegate.
41 DCHECK(id_to_item_delegate_map_
.find(id
) != id_to_item_delegate_map_
.end());
42 return id_to_item_delegate_map_
[id
];
47 void LauncherItemDelegateManager::LauncherItemAdded(int index
) {
50 void LauncherItemDelegateManager::LauncherItemRemoved(int index
,
52 RemoveLauncherItemDelegate(id
);
55 void LauncherItemDelegateManager::LauncherItemMoved(int start_index
,
59 void LauncherItemDelegateManager::LauncherItemChanged(
61 const LauncherItem
& old_item
) {
64 void LauncherItemDelegateManager::LauncherStatusChanged() {
67 void LauncherItemDelegateManager::RemoveLauncherItemDelegate(
69 if (id_to_item_delegate_map_
.find(id
) != id_to_item_delegate_map_
.end()) {
70 delete id_to_item_delegate_map_
[id
];
71 id_to_item_delegate_map_
.erase(id
);