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

Side by Side Diff: chrome/browser/chromeos/display/display_preferences.cc

Issue 2814843007: Fix expected PlacementList sort order. (Closed)
Patch Set: Don't register invalid layouts Created 3 years, 8 months 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
« no previous file with comments | « no previous file | ui/display/display.h » ('j') | ui/display/display.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/chromeos/display/display_preferences.h" 5 #include "chrome/browser/chromeos/display/display_preferences.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 int rotation = display::Display::ROTATE_0; 296 int rotation = display::Display::ROTATE_0;
297 if (!properties->GetInteger("orientation", &rotation)) 297 if (!properties->GetInteger("orientation", &rotation))
298 return; 298 return;
299 299
300 GetDisplayManager()->RegisterDisplayRotationProperties( 300 GetDisplayManager()->RegisterDisplayRotationProperties(
301 rotation_lock, static_cast<display::Display::Rotation>(rotation)); 301 rotation_lock, static_cast<display::Display::Rotation>(rotation));
302 } 302 }
303 303
304 void StoreDisplayLayoutPref(const display::DisplayIdList& list, 304 void StoreDisplayLayoutPref(const display::DisplayIdList& list,
305 const display::DisplayLayout& display_layout) { 305 const display::DisplayLayout& display_layout) {
306 DCHECK(display::DisplayLayout::Validate(list, display_layout));
306 std::string name = display::DisplayIdListToString(list); 307 std::string name = display::DisplayIdListToString(list);
307 308
308 PrefService* local_state = g_browser_process->local_state(); 309 PrefService* local_state = g_browser_process->local_state();
309 DictionaryPrefUpdate update(local_state, prefs::kSecondaryDisplays); 310 DictionaryPrefUpdate update(local_state, prefs::kSecondaryDisplays);
310 base::DictionaryValue* pref_data = update.Get(); 311 base::DictionaryValue* pref_data = update.Get();
311 std::unique_ptr<base::Value> layout_value(new base::DictionaryValue()); 312 std::unique_ptr<base::Value> layout_value(new base::DictionaryValue());
312 if (pref_data->HasKey(name)) { 313 if (pref_data->HasKey(name)) {
313 base::Value* value = nullptr; 314 base::Value* value = nullptr;
314 if (pref_data->Get(name, &value) && value != nullptr) 315 if (pref_data->Get(name, &value) && value != nullptr)
315 layout_value.reset(value->DeepCopy()); 316 layout_value.reset(value->DeepCopy());
316 } 317 }
317 if (display::DisplayLayoutToJson(display_layout, layout_value.get())) 318 if (display::DisplayLayoutToJson(display_layout, layout_value.get()))
318 pref_data->Set(name, std::move(layout_value)); 319 pref_data->Set(name, std::move(layout_value));
319 } 320 }
320 321
321 void StoreCurrentDisplayLayoutPrefs() { 322 void StoreCurrentDisplayLayoutPrefs() {
322 display::DisplayManager* display_manager = GetDisplayManager(); 323 display::DisplayManager* display_manager = GetDisplayManager();
323 if (!UserCanSaveDisplayPreference() || 324 if (!UserCanSaveDisplayPreference() ||
324 display_manager->num_connected_displays() < 2) { 325 display_manager->num_connected_displays() < 2) {
325 return; 326 return;
326 } 327 }
327 328
328 display::DisplayIdList list = display_manager->GetCurrentDisplayIdList(); 329 display::DisplayIdList list = display_manager->GetCurrentDisplayIdList();
329 const display::DisplayLayout& display_layout = 330 const display::DisplayLayout& display_layout =
330 display_manager->layout_store()->GetRegisteredDisplayLayout(list); 331 display_manager->layout_store()->GetRegisteredDisplayLayout(list);
332
333 if (!display::DisplayLayout::Validate(list, display_layout)) {
334 // We should never apply an invalid layout, if we do, it persists and the
335 // user has no way of fixing it except by deleting the local state.
336 LOG(ERROR) << "Attempting to store an invalid display layout in the local"
337 << " state. Skipping.";
338 return;
339 }
340
331 StoreDisplayLayoutPref(list, display_layout); 341 StoreDisplayLayoutPref(list, display_layout);
332 } 342 }
333 343
334 void StoreCurrentDisplayProperties() { 344 void StoreCurrentDisplayProperties() {
335 display::DisplayManager* display_manager = GetDisplayManager(); 345 display::DisplayManager* display_manager = GetDisplayManager();
336 PrefService* local_state = g_browser_process->local_state(); 346 PrefService* local_state = g_browser_process->local_state();
337 347
338 DictionaryPrefUpdate update(local_state, prefs::kDisplayProperties); 348 DictionaryPrefUpdate update(local_state, prefs::kDisplayProperties);
339 base::DictionaryValue* pref_data = update.Get(); 349 base::DictionaryValue* pref_data = update.Get();
340 350
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 StoreDisplayPowerState(power_state); 501 StoreDisplayPowerState(power_state);
492 } 502 }
493 503
494 bool ParseTouchCalibrationStringForTest( 504 bool ParseTouchCalibrationStringForTest(
495 const std::string& str, 505 const std::string& str,
496 display::TouchCalibrationData::CalibrationPointPairQuad* point_pair_quad) { 506 display::TouchCalibrationData::CalibrationPointPairQuad* point_pair_quad) {
497 return ParseTouchCalibrationStringValue(str, point_pair_quad); 507 return ParseTouchCalibrationStringValue(str, point_pair_quad);
498 } 508 }
499 509
500 } // namespace chromeos 510 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | ui/display/display.h » ('j') | ui/display/display.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698