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

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

Issue 2791803002: mash: Move LauncherItemController to ash, rename ShelfItemDelegate. (Closed)
Patch Set: Move shelf_item_delegate to ash/public/cpp, cleanup. Created 3 years, 8 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/public/cpp/shelf_item.h" 12 #include "ash/public/cpp/shelf_item.h"
13 #include "ash/public/cpp/shelf_item_delegate.h"
James Cook 2017/04/04 15:34:44 Can you forward declare this now?
msw 2017/04/04 18:53:09 Done.
13 #include "ash/public/interfaces/shelf.mojom.h" 14 #include "ash/public/interfaces/shelf.mojom.h"
14 #include "base/macros.h" 15 #include "base/macros.h"
15 #include "base/observer_list.h" 16 #include "base/observer_list.h"
16 17
17 namespace ash { 18 namespace ash {
18 19
19 class ShelfModelObserver; 20 class ShelfModelObserver;
20 21
21 // Model used for shelf items. Owns ShelfItemDelegates but does not create them. 22 // Model used for shelf items. Owns ShelfItemDelegates but does not create them.
22 class ASH_EXPORT ShelfModel { 23 class ASH_EXPORT ShelfModel {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 ShelfID reserve_external_id() { return next_id_++; } 70 ShelfID reserve_external_id() { return next_id_++; }
70 71
71 // Returns an iterator into items() for the item with the specified id, or 72 // 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. 73 // items().end() if there is no item with the specified id.
73 ShelfItems::const_iterator ItemByID(ShelfID id) const; 74 ShelfItems::const_iterator ItemByID(ShelfID id) const;
74 75
75 const ShelfItems& items() const { return items_; } 76 const ShelfItems& items() const { return items_; }
76 int item_count() const { return static_cast<int>(items_.size()); } 77 int item_count() const { return static_cast<int>(items_.size()); }
77 78
78 // Set |item_delegate| for |id| and takes ownership. 79 // Set |item_delegate| for |id| and takes ownership.
79 void SetShelfItemDelegate( 80 void SetShelfItemDelegate(ShelfID id,
80 ShelfID id, 81 std::unique_ptr<ShelfItemDelegate> item_delegate);
81 std::unique_ptr<mojom::ShelfItemDelegate> item_delegate);
82 82
83 // Returns ShelfItemDelegate for |id|, or null if none exists. 83 // Returns ShelfItemDelegate for |id|, or null if none exists.
84 mojom::ShelfItemDelegate* GetShelfItemDelegate(ShelfID id); 84 ShelfItemDelegate* GetShelfItemDelegate(ShelfID id);
85 85
86 void AddObserver(ShelfModelObserver* observer); 86 void AddObserver(ShelfModelObserver* observer);
87 void RemoveObserver(ShelfModelObserver* observer); 87 void RemoveObserver(ShelfModelObserver* observer);
88 88
89 private: 89 private:
90 // 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
91 // 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
92 // returns the new value. 92 // returns the new value.
93 int ValidateInsertionIndex(ShelfItemType type, int index) const; 93 int ValidateInsertionIndex(ShelfItemType type, int index) const;
94 94
95 // Remove and destroy ShelfItemDelegate for |id|. 95 // Remove and destroy ShelfItemDelegate for |id|.
96 void RemoveShelfItemDelegate(ShelfID id); 96 void RemoveShelfItemDelegate(ShelfID id);
97 97
98 // ID assigned to the next item. 98 // ID assigned to the next item.
99 ShelfID next_id_; 99 ShelfID next_id_;
100 100
101 ShelfItems items_; 101 ShelfItems items_;
102 base::ObserverList<ShelfModelObserver> observers_; 102 base::ObserverList<ShelfModelObserver> observers_;
103 103
104 std::map<ShelfID, std::unique_ptr<mojom::ShelfItemDelegate>> 104 std::map<ShelfID, std::unique_ptr<ShelfItemDelegate>>
105 id_to_item_delegate_map_; 105 id_to_item_delegate_map_;
106 106
107 DISALLOW_COPY_AND_ASSIGN(ShelfModel); 107 DISALLOW_COPY_AND_ASSIGN(ShelfModel);
108 }; 108 };
109 109
110 } // namespace ash 110 } // namespace ash
111 111
112 #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