1 // Copyright 2020 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_PUBLIC_CPP_HOLDING_SPACE_HOLDING_SPACE_CONTROLLER_H_ 6 #define ASH_PUBLIC_CPP_HOLDING_SPACE_HOLDING_SPACE_CONTROLLER_H_ 7 8 #include <memory> 9 10 #include "ash/public/cpp/ash_public_export.h" 11 #include "ash/public/cpp/session/session_observer.h" 12 #include "base/observer_list.h" 13 #include "components/account_id/account_id.h" 14 15 namespace ash { 16 17 class HoldingSpaceClient; 18 class HoldingSpaceColorProvider; 19 class HoldingSpaceControllerObserver; 20 class HoldingSpaceModel; 21 22 // Keeps track of all registered holding space models per user account and makes 23 // sure the current active model belongs to the current active user. 24 // There is expected to exist at most one instance of this class at a time. In 25 // production the instance is owned by ash::Shell. The instance can be retrieved 26 // using HoldingSpaceController::Get(). 27 class ASH_PUBLIC_EXPORT HoldingSpaceController : public SessionObserver { 28 public: 29 explicit HoldingSpaceController(std::unique_ptr<HoldingSpaceColorProvider>); 30 HoldingSpaceController(const HoldingSpaceController& other) = delete; 31 HoldingSpaceController& operator=(const HoldingSpaceController& other) = 32 delete; 33 ~HoldingSpaceController() override; 34 35 // Returns the global HoldingSpaceController instance. It's set in the 36 // HoldingSpaceController constructor, and reset in the destructor. The 37 // instance is owned by ash shell. 38 static HoldingSpaceController* Get(); 39 40 void AddObserver(HoldingSpaceControllerObserver* observer); 41 void RemoveObserver(HoldingSpaceControllerObserver* observer); 42 43 // Adds a client and model to it's corresponding user account id in a map. 44 void RegisterClientAndModelForUser(const AccountId& account_id, 45 HoldingSpaceClient* client, 46 HoldingSpaceModel* model); 47 client()48 HoldingSpaceClient* client() { return client_; } 49 model()50 HoldingSpaceModel* model() { return model_; } 51 52 private: 53 // SessionObserver: 54 void OnActiveUserSessionChanged(const AccountId& account_id) override; 55 56 void SetClient(HoldingSpaceClient* client); 57 void SetModel(HoldingSpaceModel* model); 58 59 // The singleton provider for colors used by holding space. 60 std::unique_ptr<HoldingSpaceColorProvider> color_provider_; 61 62 // The currently active holding space client, set by `SetClient()`. 63 HoldingSpaceClient* client_ = nullptr; 64 65 // The currently active holding space model, set by `SetModel()`. 66 HoldingSpaceModel* model_ = nullptr; 67 68 // The currently active user account id. 69 AccountId active_user_account_id_; 70 71 using ClientAndModel = std::pair<HoldingSpaceClient*, HoldingSpaceModel*>; 72 std::map<const AccountId, ClientAndModel> clients_and_models_by_account_id_; 73 74 base::ObserverList<HoldingSpaceControllerObserver> observers_; 75 }; 76 77 } // namespace ash 78 79 #endif // ASH_PUBLIC_CPP_HOLDING_SPACE_HOLDING_SPACE_CONTROLLER_H_ 80