summaryrefslogtreecommitdiffstats
path: root/chromium/ash/shelf/shelf_item_delegate_manager.cc
blob: 79124caac15a4b2608e2924141eb899b82002c33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright 2013 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 "ash/shelf/shelf_item_delegate_manager.h"

#include "ash/shelf/shelf_item_delegate.h"
#include "ash/shelf/shelf_model.h"
#include "ash/shell.h"
#include "base/logging.h"
#include "base/stl_util.h"

namespace ash {

ShelfItemDelegateManager::ShelfItemDelegateManager(ShelfModel* model)
    : model_(model) {
  DCHECK(model_);
  model_->AddObserver(this);
}

ShelfItemDelegateManager::~ShelfItemDelegateManager() {
  model_->RemoveObserver(this);
  STLDeleteContainerPairSecondPointers(id_to_item_delegate_map_.begin(),
                                       id_to_item_delegate_map_.end());
}

void ShelfItemDelegateManager::SetShelfItemDelegate(
    LauncherID id,
    scoped_ptr<ShelfItemDelegate> item_delegate) {
  // If another ShelfItemDelegate is already registered for |id|, we assume
  // that this request is replacing ShelfItemDelegate for |id| with
  // |item_delegate|.
  RemoveShelfItemDelegate(id);
  id_to_item_delegate_map_[id] = item_delegate.release();
}

ShelfItemDelegate* ShelfItemDelegateManager::GetShelfItemDelegate(
    LauncherID id) {
  if (model_->ItemIndexByID(id) != -1) {
    // Each LauncherItem has to have a ShelfItemDelegate.
    DCHECK(id_to_item_delegate_map_.find(id) != id_to_item_delegate_map_.end());
    return id_to_item_delegate_map_[id];
  }
  return NULL;
}

void ShelfItemDelegateManager::ShelfItemAdded(int index) {
}

void ShelfItemDelegateManager::ShelfItemRemoved(int index, LauncherID id) {
  RemoveShelfItemDelegate(id);
}

void ShelfItemDelegateManager::ShelfItemMoved(int start_index,
                                              int target_index) {
}

void ShelfItemDelegateManager::ShelfItemChanged(int index,
                                                const LauncherItem& old_item) {
}

void ShelfItemDelegateManager::ShelfStatusChanged() {
}

void ShelfItemDelegateManager::RemoveShelfItemDelegate(LauncherID id) {
  if (id_to_item_delegate_map_.find(id) != id_to_item_delegate_map_.end()) {
    delete id_to_item_delegate_map_[id];
    id_to_item_delegate_map_.erase(id);
  }
}

}  // namespace ash