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

Side by Side Diff: ash/common/shelf/shelf_controller.cc

Issue 2474653003: PreferencesManager (Closed)
Patch Set: Update mojom to support separate subscriptions 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/common/shelf/shelf_controller.h" 5 #include "ash/common/shelf/shelf_controller.h"
6 6
7 #include "ash/common/shelf/shelf_item_delegate.h" 7 #include "ash/common/shelf/shelf_item_delegate.h"
8 #include "ash/common/shelf/shelf_menu_model.h" 8 #include "ash/common/shelf/shelf_menu_model.h"
9 #include "ash/common/shelf/wm_shelf.h" 9 #include "ash/common/shelf/wm_shelf.h"
10 #include "ash/common/shell_delegate.h"
10 #include "ash/common/wm_lookup.h" 11 #include "ash/common/wm_lookup.h"
11 #include "ash/common/wm_root_window_controller.h" 12 #include "ash/common/wm_root_window_controller.h"
12 #include "ash/common/wm_shell.h" 13 #include "ash/common/wm_shell.h"
13 #include "ash/common/wm_window.h" 14 #include "ash/common/wm_window.h"
14 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "services/preferences/public/cpp/pref_observer_store.h"
15 #include "ui/base/resource/resource_bundle.h" 17 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/display/display.h" 18 #include "ui/display/display.h"
17 #include "ui/display/screen.h" 19 #include "ui/display/screen.h"
18 #include "ui/gfx/image/image_skia.h" 20 #include "ui/gfx/image/image_skia.h"
19 #include "ui/resources/grit/ui_resources.h" 21 #include "ui/resources/grit/ui_resources.h"
20 22
21 namespace ash { 23 namespace ash {
22 24
23 namespace { 25 namespace {
24 26
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 } 163 }
162 164
163 } // namespace 165 } // namespace
164 166
165 ShelfController::ShelfController() {} 167 ShelfController::ShelfController() {}
166 168
167 ShelfController::~ShelfController() {} 169 ShelfController::~ShelfController() {}
168 170
169 void ShelfController::BindRequest(mojom::ShelfControllerRequest request) { 171 void ShelfController::BindRequest(mojom::ShelfControllerRequest request) {
170 bindings_.AddBinding(this, std::move(request)); 172 bindings_.AddBinding(this, std::move(request));
173
174 // Sample of connecting to the PreferencesManager
175 PrefObserverStore* store = WmShell::Get()->pref_store();
176 std::set<std::string> keys;
177 // chrome::common::pref_names::kShelfAutoHideBehavior
178 const std::string key("auto_hide_behavior");
179 keys.insert(key);
180 store->AddObserver(this);
181 store->Subscribe(keys);
171 } 182 }
172 183
173 void ShelfController::NotifyShelfCreated(WmShelf* shelf) { 184 void ShelfController::NotifyShelfCreated(WmShelf* shelf) {
174 // Notify observers, Chrome will set alignment and auto-hide from prefs. 185 // Notify observers, Chrome will set alignment and auto-hide from prefs.
175 int64_t display_id = shelf->GetWindow()->GetDisplayNearestWindow().id(); 186 int64_t display_id = shelf->GetWindow()->GetDisplayNearestWindow().id();
176 observers_.ForAllPtrs([display_id](mojom::ShelfObserver* observer) { 187 observers_.ForAllPtrs([display_id](mojom::ShelfObserver* observer) {
177 observer->OnShelfCreated(display_id); 188 observer->OnShelfCreated(display_id);
178 }); 189 });
179 } 190 }
180 191
181 void ShelfController::NotifyShelfAlignmentChanged(WmShelf* shelf) { 192 void ShelfController::NotifyShelfAlignmentChanged(WmShelf* shelf) {
182 ShelfAlignment alignment = shelf->alignment(); 193 ShelfAlignment alignment = shelf->alignment();
183 int64_t display_id = shelf->GetWindow()->GetDisplayNearestWindow().id(); 194 int64_t display_id = shelf->GetWindow()->GetDisplayNearestWindow().id();
184 observers_.ForAllPtrs( 195 observers_.ForAllPtrs(
185 [alignment, display_id](mojom::ShelfObserver* observer) { 196 [alignment, display_id](mojom::ShelfObserver* observer) {
186 observer->OnAlignmentChanged(alignment, display_id); 197 observer->OnAlignmentChanged(alignment, display_id);
187 }); 198 });
188 } 199 }
189 200
190 void ShelfController::NotifyShelfAutoHideBehaviorChanged(WmShelf* shelf) { 201 void ShelfController::NotifyShelfAutoHideBehaviorChanged(WmShelf* shelf) {
191 ShelfAutoHideBehavior behavior = shelf->auto_hide_behavior(); 202 ShelfAutoHideBehavior behavior = shelf->auto_hide_behavior();
192 int64_t display_id = shelf->GetWindow()->GetDisplayNearestWindow().id(); 203 int64_t display_id = shelf->GetWindow()->GetDisplayNearestWindow().id();
193 observers_.ForAllPtrs([behavior, display_id](mojom::ShelfObserver* observer) { 204 observers_.ForAllPtrs([behavior, display_id](mojom::ShelfObserver* observer) {
194 observer->OnAutoHideBehaviorChanged(behavior, display_id); 205 observer->OnAutoHideBehaviorChanged(behavior, display_id);
195 }); 206 });
207
208 // This was acutally a race-conditiony place to put this example code. You
209 // can't call it until init has completed.
210 /*
211 // Using Preferences to set the value. the chrome ShelfObserver can
212 seprately
213 // listen to preference changes to make any according UI state changes.
214 std::string behaviour_pref;
215 switch (behavior) {
216 case SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS:
217 behaviour_pref = "Always";
218 break;
219 case SHELF_AUTO_HIDE_BEHAVIOR_NEVER:
220 behaviour_pref = "Never";
221 break;
222 default:
223 behaviour_pref = "ooops";
224 }
225 std::unique_ptr<base::Value> value(new base::StringValue(behaviour_pref));
226 if (store_)
227 store_->SetValue("auto_hide_behavior", std::move(value), 0);
228 */
196 } 229 }
197 230
198 void ShelfController::AddObserver( 231 void ShelfController::AddObserver(
199 mojom::ShelfObserverAssociatedPtrInfo observer) { 232 mojom::ShelfObserverAssociatedPtrInfo observer) {
200 mojom::ShelfObserverAssociatedPtr observer_ptr; 233 mojom::ShelfObserverAssociatedPtr observer_ptr;
201 observer_ptr.Bind(std::move(observer)); 234 observer_ptr.Bind(std::move(observer));
202 observers_.AddPtr(std::move(observer_ptr)); 235 observers_.AddPtr(std::move(observer_ptr));
203 } 236 }
204 237
205 void ShelfController::SetAlignment(ShelfAlignment alignment, 238 void ShelfController::SetAlignment(ShelfAlignment alignment,
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 if (!app_id_to_shelf_id_.count(app_id)) 307 if (!app_id_to_shelf_id_.count(app_id))
275 return; 308 return;
276 ShelfID shelf_id = app_id_to_shelf_id_[app_id]; 309 ShelfID shelf_id = app_id_to_shelf_id_[app_id];
277 int index = model_.ItemIndexByID(shelf_id); 310 int index = model_.ItemIndexByID(shelf_id);
278 DCHECK_GE(index, 0); 311 DCHECK_GE(index, 0);
279 ShelfItem item = *model_.ItemByID(shelf_id); 312 ShelfItem item = *model_.ItemByID(shelf_id);
280 item.image = GetShelfIconFromBitmap(image); 313 item.image = GetShelfIconFromBitmap(image);
281 model_.Set(index, item); 314 model_.Set(index, item);
282 } 315 }
283 316
317 void ShelfController::OnPrefValueChanged(const std::string& key) {
318 const base::Value* value = nullptr;
319 WmShell::Get()->pref_store()->GetValue("auto_hide_behavior", &value);
320 if (!value)
321 return;
322 std::string actual_value;
323 value->GetAsString(&actual_value);
324 LOG(ERROR) << "JR OnPrefValueChanged " << key << " : " << actual_value
325 << "\n";
326
327 // Call a method that needs the pref here
328 }
329
330 void ShelfController::OnInitializationCompleted(bool succeeded) {
331 LOG(ERROR) << "JR OnInitializationCompleted\n";
332 }
333
284 } // namespace ash 334 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698