OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_SHELF_SHELF_CONTROLLER_H_ | 5 #ifndef ASH_SHELF_SHELF_CONTROLLER_H_ |
6 #define ASH_SHELF_SHELF_CONTROLLER_H_ | 6 #define ASH_SHELF_SHELF_CONTROLLER_H_ |
7 | 7 |
8 #include <map> | |
9 #include <string> | |
10 | |
11 #include "ash/public/cpp/shelf_item.h" | 8 #include "ash/public/cpp/shelf_item.h" |
12 #include "ash/public/cpp/shelf_types.h" | 9 #include "ash/public/cpp/shelf_types.h" |
13 #include "ash/public/interfaces/shelf.mojom.h" | 10 #include "ash/public/interfaces/shelf.mojom.h" |
14 #include "ash/shelf/shelf_model.h" | 11 #include "ash/shelf/shelf_model.h" |
| 12 #include "ash/shelf/shelf_model_observer.h" |
15 #include "mojo/public/cpp/bindings/binding_set.h" | 13 #include "mojo/public/cpp/bindings/binding_set.h" |
16 #include "mojo/public/cpp/bindings/interface_ptr_set.h" | 14 #include "mojo/public/cpp/bindings/interface_ptr_set.h" |
17 | 15 |
18 namespace ash { | 16 namespace ash { |
19 | 17 |
20 class Shelf; | 18 class Shelf; |
21 | 19 |
22 // Ash's implementation of the mojom::ShelfController interface. Chrome connects | 20 // Ash's implementation of the mojom::ShelfController interface. Chrome connects |
23 // to this interface to observe and manage the per-display ash shelf instances. | 21 // to this interface to observe and manage the per-display ash shelf instances. |
24 class ShelfController : public mojom::ShelfController { | 22 // This class also owns Ash's ShelfModel, and syncs it with Chrome's ShelfModel. |
| 23 // TODO(mash): Remove Chrome's dependencies on synchronous ShelfModel access. |
| 24 class ShelfController : public mojom::ShelfController, |
| 25 public mojom::ShelfModelObserver, |
| 26 public ShelfModelObserver { |
25 public: | 27 public: |
26 ShelfController(); | 28 ShelfController(); |
27 ~ShelfController() override; | 29 ~ShelfController() override; |
28 | 30 |
29 // Binds the mojom::ShelfController interface request to this object. | 31 // Binds the mojom::ShelfController interface request to this object. |
30 void BindRequest(mojom::ShelfControllerRequest request); | 32 void BindRequest(mojom::ShelfControllerRequest request); |
31 | 33 |
32 ShelfModel* model() { return &model_; } | 34 ShelfModel* model() { return &model_; } |
33 | 35 |
34 // Functions used to notify mojom::ShelfObserver instances of changes. | 36 // Functions used to notify mojom::ShelfObserver instances of changes. |
35 void NotifyShelfInitialized(Shelf* shelf); | 37 void NotifyShelfInitialized(Shelf* shelf); |
36 void NotifyShelfAlignmentChanged(Shelf* shelf); | 38 void NotifyShelfAlignmentChanged(Shelf* shelf); |
37 void NotifyShelfAutoHideBehaviorChanged(Shelf* shelf); | 39 void NotifyShelfAutoHideBehaviorChanged(Shelf* shelf); |
38 | 40 |
39 // mojom::Shelf: | 41 // mojom::Shelf: |
40 void AddObserver(mojom::ShelfObserverAssociatedPtrInfo observer) override; | 42 void AddObserver(mojom::ShelfObserverAssociatedPtrInfo observer) override; |
| 43 void LinkShelfModels(mojom::ShelfModelObserverPtr observer, |
| 44 LinkShelfModelsCallback callback) override; |
41 void SetAlignment(ShelfAlignment alignment, int64_t display_id) override; | 45 void SetAlignment(ShelfAlignment alignment, int64_t display_id) override; |
42 void SetAutoHideBehavior(ShelfAutoHideBehavior auto_hide, | 46 void SetAutoHideBehavior(ShelfAutoHideBehavior auto_hide, |
43 int64_t display_id) override; | 47 int64_t display_id) override; |
44 void PinItem(const ShelfItem& item, | 48 |
45 mojom::ShelfItemDelegateAssociatedPtrInfo delegate) override; | 49 // mojom::ShelfModelObserver: |
46 void UnpinItem(const std::string& app_id) override; | 50 void OnShelfItemAdded(int32_t index, const ShelfItem& item) override; |
47 void SetItemImage(const std::string& app_id, const SkBitmap& image) override; | 51 void OnShelfItemRemoved(int32_t index, const ShelfItem& item) override; |
| 52 void OnShelfItemMoved(int32_t start_index, int32_t target_index) override; |
| 53 void OnShelfItemChanged(int32_t index, const ShelfItem& item) override; |
| 54 void OnShelfItemDelegateChanged( |
| 55 const ShelfID& id, |
| 56 mojom::ShelfItemDelegatePtr delegate) override; |
| 57 |
| 58 // ShelfModelObserver: |
| 59 void ShelfItemAdded(int index) override; |
| 60 void ShelfItemRemoved(int index, const ShelfItem& old_item) override; |
| 61 void ShelfItemMoved(int start_index, int target_index) override; |
| 62 void ShelfItemChanged(int index, const ShelfItem& old_item) override; |
| 63 void ShelfItemDelegateChanged(const ShelfID& id, |
| 64 ShelfItemDelegate* delegate) override; |
48 | 65 |
49 private: | 66 private: |
50 // The shelf model shared by all shelf instances. | 67 // The shelf model shared by all shelf instances. |
51 ShelfModel model_; | 68 ShelfModel model_; |
52 | 69 |
53 // Bindings for the ShelfController interface. | 70 // Bindings for the ShelfController interface. |
54 mojo::BindingSet<mojom::ShelfController> bindings_; | 71 mojo::BindingSet<mojom::ShelfController> bindings_; |
55 | 72 |
| 73 // Binding for observation of the remote ShelfModel owned by Chrome. |
| 74 mojo::Binding<mojom::ShelfModelObserver> shelf_model_observer_binding_; |
| 75 |
| 76 // True when applying changes from the remote ShelfModel owned by Chrome. |
| 77 // Changes to the local ShelfModel should not be reported during this time. |
| 78 bool applying_remote_shelf_model_changes_ = false; |
| 79 |
56 // The set of shelf observers notified about shelf state and settings changes. | 80 // The set of shelf observers notified about shelf state and settings changes. |
57 mojo::AssociatedInterfacePtrSet<mojom::ShelfObserver> observers_; | 81 mojo::AssociatedInterfacePtrSet<mojom::ShelfObserver> observers_; |
58 | 82 |
| 83 // The set of shelf model observers notified about shelf model changes. |
| 84 mojo::InterfacePtrSet<mojom::ShelfModelObserver> model_observers_; |
| 85 |
59 DISALLOW_COPY_AND_ASSIGN(ShelfController); | 86 DISALLOW_COPY_AND_ASSIGN(ShelfController); |
60 }; | 87 }; |
61 | 88 |
62 } // namespace ash | 89 } // namespace ash |
63 | 90 |
64 #endif // ASH_SHELF_SHELF_CONTROLLER_H_ | 91 #endif // ASH_SHELF_SHELF_CONTROLLER_H_ |
OLD | NEW |