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 #ifndef ASH_SHELF_SHELF_ITEM_DELEGATE_MANAGER_H_
6 #define ASH_SHELF_SHELF_ITEM_DELEGATE_MANAGER_H_
10 #include "ash/ash_export.h"
11 #include "ash/shelf/shelf_item_types.h"
12 #include "ash/shelf/shelf_model_observer.h"
13 #include "base/compiler_specific.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/observer_list.h"
18 class ShelfItemDelegate
;
22 class ShelfItemDelegateManagerTestAPI
;
25 // This class is added as a temporary fix for M39 to fix crbug.com/329597.
26 // TODO(skuhne): Find the real reason for this problem and remove this fix.
27 class ASH_EXPORT ShelfItemDelegateManagerObserver
{
29 ShelfItemDelegateManagerObserver() {}
30 virtual ~ShelfItemDelegateManagerObserver() {}
32 // Gets called when a ShelfItemDelegate gets changed. Note that
33 // |item_delegate| can be NULL.
34 virtual void OnSetShelfItemDelegate(ShelfID id
,
35 ShelfItemDelegate
* item_delegate
) = 0;
38 // ShelfItemDelegateManager manages the set of ShelfItemDelegates for the
39 // launcher. ShelfItemDelegateManager does not create ShelfItemDelegates,
40 // rather it is expected that someone else invokes SetShelfItemDelegate
41 // appropriately. On the other hand, ShelfItemDelegateManager destroys
42 // ShelfItemDelegates when the corresponding item from the model is removed.
43 class ASH_EXPORT ShelfItemDelegateManager
: public ShelfModelObserver
{
45 explicit ShelfItemDelegateManager(ShelfModel
* model
);
46 ~ShelfItemDelegateManager() override
;
48 void AddObserver(ShelfItemDelegateManagerObserver
* observer
);
49 void RemoveObserver(ShelfItemDelegateManagerObserver
* observer
);
51 // Set |item_delegate| for |id| and take an ownership.
52 void SetShelfItemDelegate(ShelfID id
,
53 scoped_ptr
<ShelfItemDelegate
> item_delegate
);
55 // Returns ShelfItemDelegate for |item_type|. Always returns non-NULL.
56 ShelfItemDelegate
* GetShelfItemDelegate(ShelfID id
);
58 // ShelfModelObserver overrides:
59 void ShelfItemAdded(int model_index
) override
;
60 void ShelfItemRemoved(int index
, ShelfID id
) override
;
61 void ShelfItemMoved(int start_index
, int targetindex
) override
;
62 void ShelfItemChanged(int index
, const ShelfItem
& old_item
) override
;
63 void ShelfStatusChanged() override
;
66 friend class test::ShelfItemDelegateManagerTestAPI
;
68 typedef std::map
<ShelfID
, ShelfItemDelegate
*> ShelfIDToItemDelegateMap
;
70 // Remove and destroy ShelfItemDelegate for |id|.
71 void RemoveShelfItemDelegate(ShelfID id
);
76 ShelfIDToItemDelegateMap id_to_item_delegate_map_
;
78 ObserverList
<ShelfItemDelegateManagerObserver
> observers_
;
80 DISALLOW_COPY_AND_ASSIGN(ShelfItemDelegateManager
);
85 #endif // ASH_SHELF_SHELF_ITEM_DELEGATE_MANAGER_H_