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