| 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" |
| 11 #include "ash/display/display_pref_util.h" | 11 #include "ash/display/display_pref_util.h" |
| 12 #include "ash/display/display_util.h" | 12 #include "ash/display/display_util.h" |
| 13 #include "ash/display/json_converter.h" |
| 13 #include "ash/shell.h" | 14 #include "ash/shell.h" |
| 14 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
| 15 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/strings/string_split.h" | 17 #include "base/strings/string_split.h" |
| 17 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 18 #include "base/sys_info.h" | 19 #include "base/sys_info.h" |
| 19 #include "base/values.h" | 20 #include "base/values.h" |
| 20 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
| 21 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 22 #include "components/prefs/pref_registry_simple.h" | 23 #include "components/prefs/pref_registry_simple.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 | 112 |
| 112 void LoadDisplayLayouts() { | 113 void LoadDisplayLayouts() { |
| 113 PrefService* local_state = g_browser_process->local_state(); | 114 PrefService* local_state = g_browser_process->local_state(); |
| 114 ash::DisplayLayoutStore* layout_store = GetDisplayManager()->layout_store(); | 115 ash::DisplayLayoutStore* layout_store = GetDisplayManager()->layout_store(); |
| 115 | 116 |
| 116 const base::DictionaryValue* layouts = local_state->GetDictionary( | 117 const base::DictionaryValue* layouts = local_state->GetDictionary( |
| 117 prefs::kSecondaryDisplays); | 118 prefs::kSecondaryDisplays); |
| 118 for (base::DictionaryValue::Iterator it(*layouts); | 119 for (base::DictionaryValue::Iterator it(*layouts); |
| 119 !it.IsAtEnd(); it.Advance()) { | 120 !it.IsAtEnd(); it.Advance()) { |
| 120 scoped_ptr<ash::DisplayLayout> layout(new ash::DisplayLayout); | 121 scoped_ptr<ash::DisplayLayout> layout(new ash::DisplayLayout); |
| 121 if (!ash::DisplayLayout::ConvertFromValue(it.value(), layout.get())) { | 122 if (!ash::JsonToDisplayLayout(it.value(), layout.get())) { |
| 122 LOG(WARNING) << "Invalid preference value for " << it.key(); | 123 LOG(WARNING) << "Invalid preference value for " << it.key(); |
| 123 continue; | 124 continue; |
| 124 } | 125 } |
| 125 | 126 |
| 126 if (it.key().find(",") != std::string::npos) { | 127 if (it.key().find(",") != std::string::npos) { |
| 127 std::vector<std::string> ids_str = base::SplitString( | 128 std::vector<std::string> ids_str = base::SplitString( |
| 128 it.key(), ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 129 it.key(), ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 129 int64_t id1 = gfx::Display::kInvalidDisplayID; | 130 int64_t id1 = gfx::Display::kInvalidDisplayID; |
| 130 int64_t id2 = gfx::Display::kInvalidDisplayID; | 131 int64_t id2 = gfx::Display::kInvalidDisplayID; |
| 131 if (!base::StringToInt64(ids_str[0], &id1) || | 132 if (!base::StringToInt64(ids_str[0], &id1) || |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 | 220 |
| 220 PrefService* local_state = g_browser_process->local_state(); | 221 PrefService* local_state = g_browser_process->local_state(); |
| 221 DictionaryPrefUpdate update(local_state, prefs::kSecondaryDisplays); | 222 DictionaryPrefUpdate update(local_state, prefs::kSecondaryDisplays); |
| 222 base::DictionaryValue* pref_data = update.Get(); | 223 base::DictionaryValue* pref_data = update.Get(); |
| 223 scoped_ptr<base::Value> layout_value(new base::DictionaryValue()); | 224 scoped_ptr<base::Value> layout_value(new base::DictionaryValue()); |
| 224 if (pref_data->HasKey(name)) { | 225 if (pref_data->HasKey(name)) { |
| 225 base::Value* value = nullptr; | 226 base::Value* value = nullptr; |
| 226 if (pref_data->Get(name, &value) && value != nullptr) | 227 if (pref_data->Get(name, &value) && value != nullptr) |
| 227 layout_value.reset(value->DeepCopy()); | 228 layout_value.reset(value->DeepCopy()); |
| 228 } | 229 } |
| 229 if (ash::DisplayLayout::ConvertToValue(display_layout, layout_value.get())) | 230 if (ash::DisplayLayoutToJson(display_layout, layout_value.get())) |
| 230 pref_data->Set(name, layout_value.release()); | 231 pref_data->Set(name, layout_value.release()); |
| 231 } | 232 } |
| 232 | 233 |
| 233 void StoreCurrentDisplayLayoutPrefs() { | 234 void StoreCurrentDisplayLayoutPrefs() { |
| 234 ash::DisplayManager* display_manager = GetDisplayManager(); | 235 ash::DisplayManager* display_manager = GetDisplayManager(); |
| 235 if (!UserCanSaveDisplayPreference() || | 236 if (!UserCanSaveDisplayPreference() || |
| 236 display_manager->num_connected_displays() < 2) { | 237 display_manager->num_connected_displays() < 2) { |
| 237 return; | 238 return; |
| 238 } | 239 } |
| 239 | 240 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 const ash::DisplayLayout& layout) { | 397 const ash::DisplayLayout& layout) { |
| 397 StoreDisplayLayoutPref(list, layout); | 398 StoreDisplayLayoutPref(list, layout); |
| 398 } | 399 } |
| 399 | 400 |
| 400 // Stores the given |power_state|. | 401 // Stores the given |power_state|. |
| 401 void StoreDisplayPowerStateForTest(DisplayPowerState power_state) { | 402 void StoreDisplayPowerStateForTest(DisplayPowerState power_state) { |
| 402 StoreDisplayPowerState(power_state); | 403 StoreDisplayPowerState(power_state); |
| 403 } | 404 } |
| 404 | 405 |
| 405 } // namespace chromeos | 406 } // namespace chromeos |
| OLD | NEW |