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

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

Issue 2718563008: mash: Use mojo for ShelfItemDelegate and [app] MenuItem. (Closed)
Patch Set: Address comments. Created 3 years, 9 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef ASH_COMMON_SHELF_SHELF_MODEL_H_ 5 #ifndef ASH_COMMON_SHELF_SHELF_MODEL_H_
6 #define ASH_COMMON_SHELF_SHELF_MODEL_H_ 6 #define ASH_COMMON_SHELF_SHELF_MODEL_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 10
11 #include "ash/ash_export.h" 11 #include "ash/ash_export.h"
12 #include "ash/common/shelf/shelf_item_types.h" 12 #include "ash/common/shelf/shelf_item_types.h"
13 #include "ash/public/interfaces/shelf.mojom.h"
13 #include "base/macros.h" 14 #include "base/macros.h"
14 #include "base/observer_list.h" 15 #include "base/observer_list.h"
15 16
16 namespace ash { 17 namespace ash {
17 18
18 class ShelfItemDelegate;
19 class ShelfModelObserver; 19 class ShelfModelObserver;
20 20
21 // Model used for shelf items. Owns ShelfItemDelegates but does not create them. 21 // Model used for shelf items. Owns ShelfItemDelegates but does not create them.
22 class ASH_EXPORT ShelfModel { 22 class ASH_EXPORT ShelfModel {
23 public: 23 public:
24 ShelfModel(); 24 ShelfModel();
25 ~ShelfModel(); 25 ~ShelfModel();
26 26
27 // Cleans up the ShelfItemDelegates. 27 // Cleans up the ShelfItemDelegates.
28 void DestroyItemDelegates(); 28 void DestroyItemDelegates();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 ShelfID reserve_external_id() { return next_id_++; } 69 ShelfID reserve_external_id() { return next_id_++; }
70 70
71 // Returns an iterator into items() for the item with the specified id, or 71 // Returns an iterator into items() for the item with the specified id, or
72 // items().end() if there is no item with the specified id. 72 // items().end() if there is no item with the specified id.
73 ShelfItems::const_iterator ItemByID(ShelfID id) const; 73 ShelfItems::const_iterator ItemByID(ShelfID id) const;
74 74
75 const ShelfItems& items() const { return items_; } 75 const ShelfItems& items() const { return items_; }
76 int item_count() const { return static_cast<int>(items_.size()); } 76 int item_count() const { return static_cast<int>(items_.size()); }
77 77
78 // Set |item_delegate| for |id| and takes ownership. 78 // Set |item_delegate| for |id| and takes ownership.
79 void SetShelfItemDelegate(ShelfID id, 79 void SetShelfItemDelegate(
80 std::unique_ptr<ShelfItemDelegate> item_delegate); 80 ShelfID id,
81 std::unique_ptr<mojom::ShelfItemDelegate> item_delegate);
81 82
82 // Returns ShelfItemDelegate for |id|, or null if none exists. 83 // Returns ShelfItemDelegate for |id|, or null if none exists.
83 ShelfItemDelegate* GetShelfItemDelegate(ShelfID id); 84 mojom::ShelfItemDelegate* GetShelfItemDelegate(ShelfID id);
84 85
85 void AddObserver(ShelfModelObserver* observer); 86 void AddObserver(ShelfModelObserver* observer);
86 void RemoveObserver(ShelfModelObserver* observer); 87 void RemoveObserver(ShelfModelObserver* observer);
87 88
88 private: 89 private:
89 // Makes sure |index| is in line with the type-based order of items. If that 90 // Makes sure |index| is in line with the type-based order of items. If that
90 // is not the case, adjusts index by shifting it to the valid range and 91 // is not the case, adjusts index by shifting it to the valid range and
91 // returns the new value. 92 // returns the new value.
92 int ValidateInsertionIndex(ShelfItemType type, int index) const; 93 int ValidateInsertionIndex(ShelfItemType type, int index) const;
93 94
94 // Remove and destroy ShelfItemDelegate for |id|. 95 // Remove and destroy ShelfItemDelegate for |id|.
95 void RemoveShelfItemDelegate(ShelfID id); 96 void RemoveShelfItemDelegate(ShelfID id);
96 97
97 // ID assigned to the next item. 98 // ID assigned to the next item.
98 ShelfID next_id_; 99 ShelfID next_id_;
99 100
100 ShelfItems items_; 101 ShelfItems items_;
101 base::ObserverList<ShelfModelObserver> observers_; 102 base::ObserverList<ShelfModelObserver> observers_;
102 103
103 std::map<ShelfID, std::unique_ptr<ShelfItemDelegate>> 104 std::map<ShelfID, std::unique_ptr<mojom::ShelfItemDelegate>>
104 id_to_item_delegate_map_; 105 id_to_item_delegate_map_;
105 106
106 DISALLOW_COPY_AND_ASSIGN(ShelfModel); 107 DISALLOW_COPY_AND_ASSIGN(ShelfModel);
107 }; 108 };
108 109
109 } // namespace ash 110 } // namespace ash
110 111
111 #endif // ASH_COMMON_SHELF_SHELF_MODEL_H_ 112 #endif // ASH_COMMON_SHELF_SHELF_MODEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698