| 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_pref_util.h" | |
| 10 #include "ash/display/json_converter.h" | |
| 11 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 12 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| 13 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
| 15 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 16 #include "base/sys_info.h" | 14 #include "base/sys_info.h" |
| 17 #include "base/values.h" | 15 #include "base/values.h" |
| 18 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 19 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 20 #include "components/prefs/pref_registry_simple.h" | 18 #include "components/prefs/pref_registry_simple.h" |
| 21 #include "components/prefs/pref_service.h" | 19 #include "components/prefs/pref_service.h" |
| 22 #include "components/prefs/scoped_user_pref_update.h" | 20 #include "components/prefs/scoped_user_pref_update.h" |
| 23 #include "components/user_manager/user_manager.h" | 21 #include "components/user_manager/user_manager.h" |
| 24 #include "third_party/cros_system_api/dbus/service_constants.h" | 22 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 25 #include "ui/display/display.h" | 23 #include "ui/display/display.h" |
| 26 #include "ui/display/manager/display_layout_store.h" | 24 #include "ui/display/manager/display_layout_store.h" |
| 27 #include "ui/display/manager/display_manager.h" | 25 #include "ui/display/manager/display_manager.h" |
| 28 #include "ui/display/manager/display_manager_utilities.h" | 26 #include "ui/display/manager/display_manager_utilities.h" |
| 27 #include "ui/display/manager/display_pref_util.h" |
| 28 #include "ui/display/manager/json_converter.h" |
| 29 #include "ui/display/types/display_constants.h" | 29 #include "ui/display/types/display_constants.h" |
| 30 #include "ui/gfx/geometry/insets.h" | 30 #include "ui/gfx/geometry/insets.h" |
| 31 #include "url/url_canon.h" | 31 #include "url/url_canon.h" |
| 32 #include "url/url_util.h" | 32 #include "url/url_util.h" |
| 33 | 33 |
| 34 namespace chromeos { | 34 namespace chromeos { |
| 35 namespace { | 35 namespace { |
| 36 | 36 |
| 37 const char kInsetsTopKey[] = "insets_top"; | 37 const char kInsetsTopKey[] = "insets_top"; |
| 38 const char kInsetsLeftKey[] = "insets_left"; | 38 const char kInsetsLeftKey[] = "insets_left"; |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 void LoadDisplayLayouts() { | 199 void LoadDisplayLayouts() { |
| 200 PrefService* local_state = g_browser_process->local_state(); | 200 PrefService* local_state = g_browser_process->local_state(); |
| 201 display::DisplayLayoutStore* layout_store = | 201 display::DisplayLayoutStore* layout_store = |
| 202 GetDisplayManager()->layout_store(); | 202 GetDisplayManager()->layout_store(); |
| 203 | 203 |
| 204 const base::DictionaryValue* layouts = local_state->GetDictionary( | 204 const base::DictionaryValue* layouts = local_state->GetDictionary( |
| 205 prefs::kSecondaryDisplays); | 205 prefs::kSecondaryDisplays); |
| 206 for (base::DictionaryValue::Iterator it(*layouts); | 206 for (base::DictionaryValue::Iterator it(*layouts); |
| 207 !it.IsAtEnd(); it.Advance()) { | 207 !it.IsAtEnd(); it.Advance()) { |
| 208 std::unique_ptr<display::DisplayLayout> layout(new display::DisplayLayout); | 208 std::unique_ptr<display::DisplayLayout> layout(new display::DisplayLayout); |
| 209 if (!ash::JsonToDisplayLayout(it.value(), layout.get())) { | 209 if (!display::JsonToDisplayLayout(it.value(), layout.get())) { |
| 210 LOG(WARNING) << "Invalid preference value for " << it.key(); | 210 LOG(WARNING) << "Invalid preference value for " << it.key(); |
| 211 continue; | 211 continue; |
| 212 } | 212 } |
| 213 | 213 |
| 214 if (it.key().find(",") != std::string::npos) { | 214 if (it.key().find(",") != std::string::npos) { |
| 215 std::vector<std::string> ids_str = base::SplitString( | 215 std::vector<std::string> ids_str = base::SplitString( |
| 216 it.key(), ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 216 it.key(), ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 217 std::vector<int64_t> ids; | 217 std::vector<int64_t> ids; |
| 218 for (std::string id_str : ids_str) { | 218 for (std::string id_str : ids_str) { |
| 219 int64_t id; | 219 int64_t id; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 | 307 |
| 308 PrefService* local_state = g_browser_process->local_state(); | 308 PrefService* local_state = g_browser_process->local_state(); |
| 309 DictionaryPrefUpdate update(local_state, prefs::kSecondaryDisplays); | 309 DictionaryPrefUpdate update(local_state, prefs::kSecondaryDisplays); |
| 310 base::DictionaryValue* pref_data = update.Get(); | 310 base::DictionaryValue* pref_data = update.Get(); |
| 311 std::unique_ptr<base::Value> layout_value(new base::DictionaryValue()); | 311 std::unique_ptr<base::Value> layout_value(new base::DictionaryValue()); |
| 312 if (pref_data->HasKey(name)) { | 312 if (pref_data->HasKey(name)) { |
| 313 base::Value* value = nullptr; | 313 base::Value* value = nullptr; |
| 314 if (pref_data->Get(name, &value) && value != nullptr) | 314 if (pref_data->Get(name, &value) && value != nullptr) |
| 315 layout_value.reset(value->DeepCopy()); | 315 layout_value.reset(value->DeepCopy()); |
| 316 } | 316 } |
| 317 if (ash::DisplayLayoutToJson(display_layout, layout_value.get())) | 317 if (display::DisplayLayoutToJson(display_layout, layout_value.get())) |
| 318 pref_data->Set(name, layout_value.release()); | 318 pref_data->Set(name, layout_value.release()); |
| 319 } | 319 } |
| 320 | 320 |
| 321 void StoreCurrentDisplayLayoutPrefs() { | 321 void StoreCurrentDisplayLayoutPrefs() { |
| 322 display::DisplayManager* display_manager = GetDisplayManager(); | 322 display::DisplayManager* display_manager = GetDisplayManager(); |
| 323 if (!UserCanSaveDisplayPreference() || | 323 if (!UserCanSaveDisplayPreference() || |
| 324 display_manager->num_connected_displays() < 2) { | 324 display_manager->num_connected_displays() < 2) { |
| 325 return; | 325 return; |
| 326 } | 326 } |
| 327 | 327 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 TouchDataToValue(info.GetTouchCalibrationData(), property_value.get()); | 375 TouchDataToValue(info.GetTouchCalibrationData(), property_value.get()); |
| 376 pref_data->Set(base::Int64ToString(id), property_value.release()); | 376 pref_data->Set(base::Int64ToString(id), property_value.release()); |
| 377 } | 377 } |
| 378 } | 378 } |
| 379 | 379 |
| 380 typedef std::map<chromeos::DisplayPowerState, std::string> | 380 typedef std::map<chromeos::DisplayPowerState, std::string> |
| 381 DisplayPowerStateToStringMap; | 381 DisplayPowerStateToStringMap; |
| 382 | 382 |
| 383 const DisplayPowerStateToStringMap* GetDisplayPowerStateToStringMap() { | 383 const DisplayPowerStateToStringMap* GetDisplayPowerStateToStringMap() { |
| 384 // Don't save or retore ALL_OFF state. crbug.com/318456. | 384 // Don't save or retore ALL_OFF state. crbug.com/318456. |
| 385 static const DisplayPowerStateToStringMap* map = ash::CreateToStringMap( | 385 static const DisplayPowerStateToStringMap* map = display::CreateToStringMap( |
| 386 chromeos::DISPLAY_POWER_ALL_ON, "all_on", | 386 chromeos::DISPLAY_POWER_ALL_ON, "all_on", |
| 387 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, | 387 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, |
| 388 "internal_off_external_on", | 388 "internal_off_external_on", |
| 389 chromeos::DISPLAY_POWER_INTERNAL_ON_EXTERNAL_OFF, | 389 chromeos::DISPLAY_POWER_INTERNAL_ON_EXTERNAL_OFF, |
| 390 "internal_on_external_off"); | 390 "internal_on_external_off"); |
| 391 return map; | 391 return map; |
| 392 } | 392 } |
| 393 | 393 |
| 394 bool GetDisplayPowerStateFromString(const base::StringPiece& state, | 394 bool GetDisplayPowerStateFromString(const base::StringPiece& state, |
| 395 chromeos::DisplayPowerState* field) { | 395 chromeos::DisplayPowerState* field) { |
| 396 if (ash::ReverseFind(GetDisplayPowerStateToStringMap(), state, field)) | 396 if (display::ReverseFind(GetDisplayPowerStateToStringMap(), state, field)) |
| 397 return true; | 397 return true; |
| 398 LOG(ERROR) << "Invalid display power state value:" << state; | 398 LOG(ERROR) << "Invalid display power state value:" << state; |
| 399 return false; | 399 return false; |
| 400 } | 400 } |
| 401 | 401 |
| 402 void StoreDisplayPowerState(DisplayPowerState power_state) { | 402 void StoreDisplayPowerState(DisplayPowerState power_state) { |
| 403 const DisplayPowerStateToStringMap* map = GetDisplayPowerStateToStringMap(); | 403 const DisplayPowerStateToStringMap* map = GetDisplayPowerStateToStringMap(); |
| 404 DisplayPowerStateToStringMap::const_iterator iter = map->find(power_state); | 404 DisplayPowerStateToStringMap::const_iterator iter = map->find(power_state); |
| 405 if (iter != map->end()) { | 405 if (iter != map->end()) { |
| 406 PrefService* local_state = g_browser_process->local_state(); | 406 PrefService* local_state = g_browser_process->local_state(); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 StoreDisplayPowerState(power_state); | 491 StoreDisplayPowerState(power_state); |
| 492 } | 492 } |
| 493 | 493 |
| 494 bool ParseTouchCalibrationStringForTest( | 494 bool ParseTouchCalibrationStringForTest( |
| 495 const std::string& str, | 495 const std::string& str, |
| 496 display::TouchCalibrationData::CalibrationPointPairQuad* point_pair_quad) { | 496 display::TouchCalibrationData::CalibrationPointPairQuad* point_pair_quad) { |
| 497 return ParseTouchCalibrationStringValue(str, point_pair_quad); | 497 return ParseTouchCalibrationStringValue(str, point_pair_quad); |
| 498 } | 498 } |
| 499 | 499 |
| 500 } // namespace chromeos | 500 } // namespace chromeos |
| OLD | NEW |