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

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

Issue 2474653003: PreferencesManager (Closed)
Patch Set: Enforce Observer Removal 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
« no previous file with comments | « ash/common/shelf/shelf_controller.h ('k') | ash/common/wm_shell.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..389eeb6d8f26bb3b93d13863aa80318a970dd2df 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"
@@ -164,10 +166,23 @@ WmShelf* GetShelfForDisplay(int64_t display_id) {
ShelfController::ShelfController() {}
-ShelfController::~ShelfController() {}
+ShelfController::~ShelfController() {
+ preferences::PrefObserverStore* store = WmShell::Get()->pref_store();
+ if (store)
+ store->RemoveObserver(this);
+}
void ShelfController::BindRequest(mojom::ShelfControllerRequest request) {
bindings_.AddBinding(this, std::move(request));
+
+ // Sample of connecting to the PreferencesManager
+ preferences::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 +208,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 +318,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
« no previous file with comments | « ash/common/shelf/shelf_controller.h ('k') | ash/common/wm_shell.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698