Chromium Code Reviews| Index: ash/common/shelf/shelf_controller.cc |
| diff --git a/ash/common/shelf/shelf_controller.cc b/ash/common/shelf/shelf_controller.cc |
| index 043fec9e7513655c295521b1b328c4b116ffe463..6faca21efd858706b3ce1663d0f24b85d0ca611e 100644 |
| --- a/ash/common/shelf/shelf_controller.cc |
| +++ b/ash/common/shelf/shelf_controller.cc |
| @@ -7,11 +7,15 @@ |
| #include "ash/common/shelf/shelf_item_delegate.h" |
| #include "ash/common/shelf/shelf_menu_model.h" |
| #include "ash/common/shelf/wm_shelf.h" |
| +#include "ash/common/shell_delegate.h" |
| #include "ash/common/wm_lookup.h" |
| #include "ash/common/wm_root_window_controller.h" |
| #include "ash/common/wm_shell.h" |
| #include "ash/common/wm_window.h" |
| #include "base/strings/utf_string_conversions.h" |
| +#include "services/preferences/public/cpp/pref_observer_store.h" |
| +#include "services/preferences/public/interfaces/preferences.mojom.h" |
| +#include "services/service_manager/public/cpp/connector.h" |
| #include "ui/base/resource/resource_bundle.h" |
| #include "ui/display/display.h" |
| #include "ui/display/screen.h" |
| @@ -164,10 +168,29 @@ WmShelf* GetShelfForDisplay(int64_t display_id) { |
| ShelfController::ShelfController() {} |
| -ShelfController::~ShelfController() {} |
| +ShelfController::~ShelfController() { |
| + if (store_) |
| + store_->RemoveObserver(this); |
| +} |
| void ShelfController::BindRequest(mojom::ShelfControllerRequest request) { |
| bindings_.AddBinding(this, std::move(request)); |
| + |
| + // Sample of connecting to the PreferencesManager |
| + WmShell* shell = WmShell::Get(); |
| + service_manager::Connector* connector = |
| + shell->delegate()->GetShellConnector(); |
| + if (!connector) |
| + return; |
| + prefs::mojom::PreferencesManagerPtr pref_manager_ptr; |
| + connector->ConnectToInterface("service:content_browser", &pref_manager_ptr); |
| + store_ = new PrefObserverStore(std::move(pref_manager_ptr)); |
| + std::set<std::string> keys; |
| + // chrome::common::pref_names::kShelfAutoHideBehavior |
| + const std::string key("auto_hide_behavior"); |
| + keys.insert(key); |
|
James Cook
2016/11/15 20:27:17
Drive-by: I wonder if we should have a single pref
jonross
2016/11/15 22:49:44
We could make a single exit point from Ash. To red
|
| + store_->AddObserver(this); |
| + store_->Init(keys); |
| } |
| void ShelfController::NotifyShelfCreated(WmShelf* shelf) { |
| @@ -193,6 +216,23 @@ void ShelfController::NotifyShelfAutoHideBehaviorChanged(WmShelf* shelf) { |
| observers_.ForAllPtrs([behavior, display_id](mojom::ShelfObserver* observer) { |
| observer->OnAutoHideBehaviorChanged(behavior, display_id); |
| }); |
| + |
| + // Using Preferences to set the value. the chrome ShelfObserver can seprately |
| + // listen to preference changes to make any according UI state changes. |
| + std::string behaviour_pref; |
| + switch (behavior) { |
| + case SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS: |
| + behaviour_pref = "Always"; |
| + break; |
| + case SHELF_AUTO_HIDE_BEHAVIOR_NEVER: |
| + behaviour_pref = "Never"; |
| + break; |
| + default: |
| + behaviour_pref = "ooops"; |
| + } |
| + std::unique_ptr<base::Value> value(new base::StringValue(behaviour_pref)); |
| + if (store_) |
| + store_->SetValue("auto_hide_behavior", std::move(value), 0); |
| } |
| void ShelfController::AddObserver( |
| @@ -281,4 +321,32 @@ void ShelfController::SetItemImage(const std::string& app_id, |
| model_.Set(index, item); |
| } |
| +void ShelfController::OnPrefValueChanged(const std::string& key) { |
| + const base::Value* value = nullptr; |
| + store_->GetValue("auto_hide_behavior", &value); |
| + if (!value) |
| + return; |
| + std::string actual_value; |
| + value->GetAsString(&actual_value); |
| + LOG(ERROR) << "JR OnPrefValueChanged " << key << " : " << actual_value |
| + << "\n"; |
| + |
| + // Call a method that needs the pref here |
| +} |
| + |
| +void ShelfController::OnInitializationCompleted(bool succeeded) { |
| + LOG(ERROR) << "JR OnInitializationCompleted\n"; |
| + if (!succeeded) |
| + return; |
| + const base::Value* value = nullptr; |
| + store_->GetValue("auto_hide_behavior", &value); |
| + if (!value) |
| + return; |
| + std::string actual_value; |
| + value->GetAsString(&actual_value); |
| + LOG(ERROR) << "\tJR auto_hide_behavior: " << actual_value << "\n"; |
| + |
| + // Call a method that needs the pref here |
| +} |
| + |
| } // namespace ash |