| OLD | NEW |
| 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/display/display_layout_store.h" | 9 #include "ash/display/display_layout_store.h" |
| 10 #include "ash/display/display_manager.h" | 10 #include "ash/display/display_manager.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 } | 111 } |
| 112 | 112 |
| 113 void LoadDisplayLayouts() { | 113 void LoadDisplayLayouts() { |
| 114 PrefService* local_state = g_browser_process->local_state(); | 114 PrefService* local_state = g_browser_process->local_state(); |
| 115 ash::DisplayLayoutStore* layout_store = GetDisplayManager()->layout_store(); | 115 ash::DisplayLayoutStore* layout_store = GetDisplayManager()->layout_store(); |
| 116 | 116 |
| 117 const base::DictionaryValue* layouts = local_state->GetDictionary( | 117 const base::DictionaryValue* layouts = local_state->GetDictionary( |
| 118 prefs::kSecondaryDisplays); | 118 prefs::kSecondaryDisplays); |
| 119 for (base::DictionaryValue::Iterator it(*layouts); | 119 for (base::DictionaryValue::Iterator it(*layouts); |
| 120 !it.IsAtEnd(); it.Advance()) { | 120 !it.IsAtEnd(); it.Advance()) { |
| 121 scoped_ptr<display::DisplayLayout> layout(new display::DisplayLayout); | 121 std::unique_ptr<display::DisplayLayout> layout(new display::DisplayLayout); |
| 122 if (!ash::JsonToDisplayLayout(it.value(), layout.get())) { | 122 if (!ash::JsonToDisplayLayout(it.value(), layout.get())) { |
| 123 LOG(WARNING) << "Invalid preference value for " << it.key(); | 123 LOG(WARNING) << "Invalid preference value for " << it.key(); |
| 124 continue; | 124 continue; |
| 125 } | 125 } |
| 126 | 126 |
| 127 if (it.key().find(",") != std::string::npos) { | 127 if (it.key().find(",") != std::string::npos) { |
| 128 std::vector<std::string> ids_str = base::SplitString( | 128 std::vector<std::string> ids_str = base::SplitString( |
| 129 it.key(), ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 129 it.key(), ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 130 std::vector<int64_t> ids; | 130 std::vector<int64_t> ids; |
| 131 for (std::string id_str : ids_str) { | 131 for (std::string id_str : ids_str) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 static_cast<gfx::Display::Rotation>(rotation)); | 212 static_cast<gfx::Display::Rotation>(rotation)); |
| 213 } | 213 } |
| 214 | 214 |
| 215 void StoreDisplayLayoutPref(const display::DisplayIdList& list, | 215 void StoreDisplayLayoutPref(const display::DisplayIdList& list, |
| 216 const display::DisplayLayout& display_layout) { | 216 const display::DisplayLayout& display_layout) { |
| 217 std::string name = ash::DisplayIdListToString(list); | 217 std::string name = ash::DisplayIdListToString(list); |
| 218 | 218 |
| 219 PrefService* local_state = g_browser_process->local_state(); | 219 PrefService* local_state = g_browser_process->local_state(); |
| 220 DictionaryPrefUpdate update(local_state, prefs::kSecondaryDisplays); | 220 DictionaryPrefUpdate update(local_state, prefs::kSecondaryDisplays); |
| 221 base::DictionaryValue* pref_data = update.Get(); | 221 base::DictionaryValue* pref_data = update.Get(); |
| 222 scoped_ptr<base::Value> layout_value(new base::DictionaryValue()); | 222 std::unique_ptr<base::Value> layout_value(new base::DictionaryValue()); |
| 223 if (pref_data->HasKey(name)) { | 223 if (pref_data->HasKey(name)) { |
| 224 base::Value* value = nullptr; | 224 base::Value* value = nullptr; |
| 225 if (pref_data->Get(name, &value) && value != nullptr) | 225 if (pref_data->Get(name, &value) && value != nullptr) |
| 226 layout_value.reset(value->DeepCopy()); | 226 layout_value.reset(value->DeepCopy()); |
| 227 } | 227 } |
| 228 if (ash::DisplayLayoutToJson(display_layout, layout_value.get())) | 228 if (ash::DisplayLayoutToJson(display_layout, layout_value.get())) |
| 229 pref_data->Set(name, layout_value.release()); | 229 pref_data->Set(name, layout_value.release()); |
| 230 } | 230 } |
| 231 | 231 |
| 232 void StoreCurrentDisplayLayoutPrefs() { | 232 void StoreCurrentDisplayLayoutPrefs() { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 248 | 248 |
| 249 DictionaryPrefUpdate update(local_state, prefs::kDisplayProperties); | 249 DictionaryPrefUpdate update(local_state, prefs::kDisplayProperties); |
| 250 base::DictionaryValue* pref_data = update.Get(); | 250 base::DictionaryValue* pref_data = update.Get(); |
| 251 | 251 |
| 252 size_t num = display_manager->GetNumDisplays(); | 252 size_t num = display_manager->GetNumDisplays(); |
| 253 for (size_t i = 0; i < num; ++i) { | 253 for (size_t i = 0; i < num; ++i) { |
| 254 const gfx::Display& display = display_manager->GetDisplayAt(i); | 254 const gfx::Display& display = display_manager->GetDisplayAt(i); |
| 255 int64_t id = display.id(); | 255 int64_t id = display.id(); |
| 256 ash::DisplayInfo info = display_manager->GetDisplayInfo(id); | 256 ash::DisplayInfo info = display_manager->GetDisplayInfo(id); |
| 257 | 257 |
| 258 scoped_ptr<base::DictionaryValue> property_value( | 258 std::unique_ptr<base::DictionaryValue> property_value( |
| 259 new base::DictionaryValue()); | 259 new base::DictionaryValue()); |
| 260 // Don't save the display preference in unified mode because its | 260 // Don't save the display preference in unified mode because its |
| 261 // size and modes can change depending on the combination of displays. | 261 // size and modes can change depending on the combination of displays. |
| 262 if (display_manager->IsInUnifiedMode()) | 262 if (display_manager->IsInUnifiedMode()) |
| 263 continue; | 263 continue; |
| 264 property_value->SetInteger( | 264 property_value->SetInteger( |
| 265 "rotation", | 265 "rotation", |
| 266 static_cast<int>(info.GetRotation(gfx::Display::ROTATION_SOURCE_USER))); | 266 static_cast<int>(info.GetRotation(gfx::Display::ROTATION_SOURCE_USER))); |
| 267 property_value->SetInteger( | 267 property_value->SetInteger( |
| 268 "ui-scale", static_cast<int>(info.configured_ui_scale() * 1000)); | 268 "ui-scale", static_cast<int>(info.configured_ui_scale() * 1000)); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 const display::DisplayLayout& layout) { | 395 const display::DisplayLayout& layout) { |
| 396 StoreDisplayLayoutPref(list, layout); | 396 StoreDisplayLayoutPref(list, layout); |
| 397 } | 397 } |
| 398 | 398 |
| 399 // Stores the given |power_state|. | 399 // Stores the given |power_state|. |
| 400 void StoreDisplayPowerStateForTest(DisplayPowerState power_state) { | 400 void StoreDisplayPowerStateForTest(DisplayPowerState power_state) { |
| 401 StoreDisplayPowerState(power_state); | 401 StoreDisplayPowerState(power_state); |
| 402 } | 402 } |
| 403 | 403 |
| 404 } // namespace chromeos | 404 } // namespace chromeos |
| OLD | NEW |