Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(187)

Side by Side Diff: ash/common/shelf/shelf_item_delegate_manager.h

Issue 2171813004: mash: Fold ShelfItemDelegateManager into ShelfModel (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleanup Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_COMMON_SHELF_SHELF_ITEM_DELEGATE_MANAGER_H_
6 #define ASH_COMMON_SHELF_SHELF_ITEM_DELEGATE_MANAGER_H_
7
8 #include <map>
9 #include <memory>
10
11 #include "ash/ash_export.h"
12 #include "ash/common/shelf/shelf_item_types.h"
13 #include "ash/common/shelf/shelf_model_observer.h"
14 #include "base/macros.h"
15 #include "base/observer_list.h"
16
17 namespace ash {
18 class ShelfItemDelegate;
19 class ShelfModel;
20
21 namespace test {
22 class ShelfItemDelegateManagerTestAPI;
23 }
24
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 {
28 public:
29 ShelfItemDelegateManagerObserver() {}
30 virtual ~ShelfItemDelegateManagerObserver() {}
31
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;
36 };
37
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 {
44 public:
45 explicit ShelfItemDelegateManager(ShelfModel* model);
46 ~ShelfItemDelegateManager() override;
47
48 void AddObserver(ShelfItemDelegateManagerObserver* observer);
49 void RemoveObserver(ShelfItemDelegateManagerObserver* observer);
50
51 // Set |item_delegate| for |id| and take an ownership.
52 void SetShelfItemDelegate(ShelfID id,
53 std::unique_ptr<ShelfItemDelegate> item_delegate);
54
55 // Returns ShelfItemDelegate for |item_type|. Always returns non-NULL.
56 ShelfItemDelegate* GetShelfItemDelegate(ShelfID id);
57
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
64 private:
65 friend class test::ShelfItemDelegateManagerTestAPI;
66
67 typedef std::map<ShelfID, ShelfItemDelegate*> ShelfIDToItemDelegateMap;
68
69 // Remove and destroy ShelfItemDelegate for |id|.
70 void RemoveShelfItemDelegate(ShelfID id);
71
72 // Owned by Shell.
73 ShelfModel* model_;
74
75 ShelfIDToItemDelegateMap id_to_item_delegate_map_;
76
77 base::ObserverList<ShelfItemDelegateManagerObserver> observers_;
78
79 DISALLOW_COPY_AND_ASSIGN(ShelfItemDelegateManager);
80 };
81
82 } // namespace ash
83
84 #endif // ASH_COMMON_SHELF_SHELF_ITEM_DELEGATE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698