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 |
msw
2016/11/18 00:32:57
aside: reducing some boilerplate might be nice.
jonross
2016/11/18 00:47:58
Moving this construction to WmShell would centrali
|
+ 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 |
msw
2016/11/18 00:32:57
aside: I guess we'll move ash-relevant pref names
jonross
2016/11/18 00:47:58
An issue with this is that the consts need to be i
James Cook
2016/11/18 00:50:34
+1. Most components have a pref_names.cc file, we
msw
2016/11/18 00:58:13
Yeah, ash/public/cpp/pref_names.h could declare th
jonross
2016/11/18 01:01:09
That SGTM
|
+ const std::string key("auto_hide_behavior"); |
+ keys.insert(key); |
+ 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) { |
msw
2016/11/18 00:32:57
aside: would it make sense to store the behavior e
jonross
2016/11/18 00:47:58
Yeah in most cases it would make sense to just hav
|
+ 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) { |
msw
2016/11/18 00:32:57
aside: I wonder if it'd make sense to just call On
jonross
2016/11/18 00:47:58
This init/changed paradigm is just brought over fr
jonross
2016/11/19 00:28:20
I've updated this based on your suggestion. Furthe
|
+ 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 |