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

Unified Diff: ash/common/shelf/shelf_controller.cc

Issue 2474653003: PreferencesManager (Closed)
Patch Set: Address Review Comments Created 4 years 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 side-by-side diff with in-line comments
Download patch
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..e2e36d49e394a6be3f53e1adb62c55d5d2e89704 100644
--- a/ash/common/shelf/shelf_controller.cc
+++ b/ash/common/shelf/shelf_controller.cc
@@ -7,11 +7,13 @@
#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 "ui/base/resource/resource_bundle.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
@@ -168,6 +170,15 @@ ShelfController::~ShelfController() {}
void ShelfController::BindRequest(mojom::ShelfControllerRequest request) {
bindings_.AddBinding(this, std::move(request));
+
+ // Sample of connecting to the PreferencesManager
+ PrefObserverStore* store = WmShell::Get()->pref_store();
+ std::set<std::string> keys;
+ // chrome::common::pref_names::kShelfAutoHideBehavior
+ const std::string key("auto_hide_behavior");
+ keys.insert(key);
+ store->AddObserver(this);
+ store->Subscribe(keys);
}
void ShelfController::NotifyShelfCreated(WmShelf* shelf) {
@@ -193,6 +204,28 @@ void ShelfController::NotifyShelfAutoHideBehaviorChanged(WmShelf* shelf) {
observers_.ForAllPtrs([behavior, display_id](mojom::ShelfObserver* observer) {
observer->OnAutoHideBehaviorChanged(behavior, display_id);
});
+
+ // This was acutally a race-conditiony place to put this example code. You
+ // can't call it until init has completed.
+ /*
+ // 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 +314,21 @@ void ShelfController::SetItemImage(const std::string& app_id,
model_.Set(index, item);
}
+void ShelfController::OnPrefValueChanged(const std::string& key) {
+ const base::Value* value = nullptr;
+ WmShell::Get()->pref_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";
+}
+
} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698