bluetooth: Initial JNI setup for device/bluetooth.
[chromium-blink-merge.git] / ash / shelf / shelf_item_delegate_manager.h
blobd2e77b978e0f0b2e2be117169809c9e089756ddf
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_
8 #include <map>
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"
17 namespace ash {
18 class ShelfItemDelegate;
19 class ShelfModel;
21 namespace test {
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 {
28 public:
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 {
44 public:
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;
65 private:
66 friend class test::ShelfItemDelegateManagerTestAPI;
68 typedef std::map<ShelfID, ShelfItemDelegate*> ShelfIDToItemDelegateMap;
70 // Remove and destroy ShelfItemDelegate for |id|.
71 void RemoveShelfItemDelegate(ShelfID id);
73 // Owned by Shell.
74 ShelfModel* model_;
76 ShelfIDToItemDelegateMap id_to_item_delegate_map_;
78 ObserverList<ShelfItemDelegateManagerObserver> observers_;
80 DISALLOW_COPY_AND_ASSIGN(ShelfItemDelegateManager);
83 } // namespace ash
85 #endif // ASH_SHELF_SHELF_ITEM_DELEGATE_MANAGER_H_