| 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> |
| 8 |
| 7 #include "ash/display/display_layout_store.h" | 9 #include "ash/display/display_layout_store.h" |
| 8 #include "ash/display/display_manager.h" | 10 #include "ash/display/display_manager.h" |
| 9 #include "ash/display/display_pref_util.h" | 11 #include "ash/display/display_pref_util.h" |
| 10 #include "ash/display/display_util.h" | 12 #include "ash/display/display_util.h" |
| 11 #include "ash/shell.h" | 13 #include "ash/shell.h" |
| 12 #include "base/prefs/pref_registry_simple.h" | 14 #include "base/prefs/pref_registry_simple.h" |
| 13 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
| 14 #include "base/prefs/scoped_user_pref_update.h" | 16 #include "base/prefs/scoped_user_pref_update.h" |
| 15 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
| 16 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 !it.IsAtEnd(); it.Advance()) { | 119 !it.IsAtEnd(); it.Advance()) { |
| 118 ash::DisplayLayout layout; | 120 ash::DisplayLayout layout; |
| 119 if (!ash::DisplayLayout::ConvertFromValue(it.value(), &layout)) { | 121 if (!ash::DisplayLayout::ConvertFromValue(it.value(), &layout)) { |
| 120 LOG(WARNING) << "Invalid preference value for " << it.key(); | 122 LOG(WARNING) << "Invalid preference value for " << it.key(); |
| 121 continue; | 123 continue; |
| 122 } | 124 } |
| 123 | 125 |
| 124 if (it.key().find(",") != std::string::npos) { | 126 if (it.key().find(",") != std::string::npos) { |
| 125 std::vector<std::string> ids = base::SplitString( | 127 std::vector<std::string> ids = base::SplitString( |
| 126 it.key(), ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 128 it.key(), ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 127 int64 id1 = gfx::Display::kInvalidDisplayID; | 129 int64_t id1 = gfx::Display::kInvalidDisplayID; |
| 128 int64 id2 = gfx::Display::kInvalidDisplayID; | 130 int64_t id2 = gfx::Display::kInvalidDisplayID; |
| 129 if (!base::StringToInt64(ids[0], &id1) || | 131 if (!base::StringToInt64(ids[0], &id1) || |
| 130 !base::StringToInt64(ids[1], &id2) || | 132 !base::StringToInt64(ids[1], &id2) || |
| 131 id1 == gfx::Display::kInvalidDisplayID || | 133 id1 == gfx::Display::kInvalidDisplayID || |
| 132 id2 == gfx::Display::kInvalidDisplayID) { | 134 id2 == gfx::Display::kInvalidDisplayID) { |
| 133 continue; | 135 continue; |
| 134 } | 136 } |
| 135 layout_store->RegisterLayoutForDisplayIdPair(id1, id2, layout); | 137 layout_store->RegisterLayoutForDisplayIdPair(id1, id2, layout); |
| 136 } | 138 } |
| 137 } | 139 } |
| 138 } | 140 } |
| 139 | 141 |
| 140 void LoadDisplayProperties() { | 142 void LoadDisplayProperties() { |
| 141 PrefService* local_state = g_browser_process->local_state(); | 143 PrefService* local_state = g_browser_process->local_state(); |
| 142 const base::DictionaryValue* properties = local_state->GetDictionary( | 144 const base::DictionaryValue* properties = local_state->GetDictionary( |
| 143 prefs::kDisplayProperties); | 145 prefs::kDisplayProperties); |
| 144 for (base::DictionaryValue::Iterator it(*properties); | 146 for (base::DictionaryValue::Iterator it(*properties); |
| 145 !it.IsAtEnd(); it.Advance()) { | 147 !it.IsAtEnd(); it.Advance()) { |
| 146 const base::DictionaryValue* dict_value = NULL; | 148 const base::DictionaryValue* dict_value = NULL; |
| 147 if (!it.value().GetAsDictionary(&dict_value) || dict_value == NULL) | 149 if (!it.value().GetAsDictionary(&dict_value) || dict_value == NULL) |
| 148 continue; | 150 continue; |
| 149 int64 id = gfx::Display::kInvalidDisplayID; | 151 int64_t id = gfx::Display::kInvalidDisplayID; |
| 150 if (!base::StringToInt64(it.key(), &id) || | 152 if (!base::StringToInt64(it.key(), &id) || |
| 151 id == gfx::Display::kInvalidDisplayID) { | 153 id == gfx::Display::kInvalidDisplayID) { |
| 152 continue; | 154 continue; |
| 153 } | 155 } |
| 154 gfx::Display::Rotation rotation = gfx::Display::ROTATE_0; | 156 gfx::Display::Rotation rotation = gfx::Display::ROTATE_0; |
| 155 float ui_scale = 1.0f; | 157 float ui_scale = 1.0f; |
| 156 const gfx::Insets* insets_to_set = NULL; | 158 const gfx::Insets* insets_to_set = NULL; |
| 157 | 159 |
| 158 int rotation_value = 0; | 160 int rotation_value = 0; |
| 159 if (dict_value->GetInteger("rotation", &rotation_value)) { | 161 if (dict_value->GetInteger("rotation", &rotation_value)) { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 void StoreCurrentDisplayProperties() { | 244 void StoreCurrentDisplayProperties() { |
| 243 ash::DisplayManager* display_manager = GetDisplayManager(); | 245 ash::DisplayManager* display_manager = GetDisplayManager(); |
| 244 PrefService* local_state = g_browser_process->local_state(); | 246 PrefService* local_state = g_browser_process->local_state(); |
| 245 | 247 |
| 246 DictionaryPrefUpdate update(local_state, prefs::kDisplayProperties); | 248 DictionaryPrefUpdate update(local_state, prefs::kDisplayProperties); |
| 247 base::DictionaryValue* pref_data = update.Get(); | 249 base::DictionaryValue* pref_data = update.Get(); |
| 248 | 250 |
| 249 size_t num = display_manager->GetNumDisplays(); | 251 size_t num = display_manager->GetNumDisplays(); |
| 250 for (size_t i = 0; i < num; ++i) { | 252 for (size_t i = 0; i < num; ++i) { |
| 251 const gfx::Display& display = display_manager->GetDisplayAt(i); | 253 const gfx::Display& display = display_manager->GetDisplayAt(i); |
| 252 int64 id = display.id(); | 254 int64_t id = display.id(); |
| 253 ash::DisplayInfo info = display_manager->GetDisplayInfo(id); | 255 ash::DisplayInfo info = display_manager->GetDisplayInfo(id); |
| 254 | 256 |
| 255 scoped_ptr<base::DictionaryValue> property_value( | 257 scoped_ptr<base::DictionaryValue> property_value( |
| 256 new base::DictionaryValue()); | 258 new base::DictionaryValue()); |
| 257 // Don't save the display preference in unified mode because its | 259 // Don't save the display preference in unified mode because its |
| 258 // size and modes can change depending on the combination of displays. | 260 // size and modes can change depending on the combination of displays. |
| 259 if (display_manager->IsInUnifiedMode()) | 261 if (display_manager->IsInUnifiedMode()) |
| 260 continue; | 262 continue; |
| 261 property_value->SetInteger( | 263 property_value->SetInteger( |
| 262 "rotation", | 264 "rotation", |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 std::string value = local_state->GetString(prefs::kDisplayPowerState); | 387 std::string value = local_state->GetString(prefs::kDisplayPowerState); |
| 386 chromeos::DisplayPowerState power_state; | 388 chromeos::DisplayPowerState power_state; |
| 387 if (GetDisplayPowerStateFromString(value, &power_state)) { | 389 if (GetDisplayPowerStateFromString(value, &power_state)) { |
| 388 ash::Shell::GetInstance()->display_configurator()->SetInitialDisplayPower( | 390 ash::Shell::GetInstance()->display_configurator()->SetInitialDisplayPower( |
| 389 power_state); | 391 power_state); |
| 390 } | 392 } |
| 391 } | 393 } |
| 392 } | 394 } |
| 393 | 395 |
| 394 // Stores the display layout for given display pairs. | 396 // Stores the display layout for given display pairs. |
| 395 void StoreDisplayLayoutPrefForTest(int64 id1, | 397 void StoreDisplayLayoutPrefForTest(int64_t id1, |
| 396 int64 id2, | 398 int64_t id2, |
| 397 const ash::DisplayLayout& layout) { | 399 const ash::DisplayLayout& layout) { |
| 398 StoreDisplayLayoutPref(ash::CreateDisplayIdPair(id1, id2), layout); | 400 StoreDisplayLayoutPref(ash::CreateDisplayIdPair(id1, id2), layout); |
| 399 } | 401 } |
| 400 | 402 |
| 401 // Stores the given |power_state|. | 403 // Stores the given |power_state|. |
| 402 void StoreDisplayPowerStateForTest(DisplayPowerState power_state) { | 404 void StoreDisplayPowerStateForTest(DisplayPowerState power_state) { |
| 403 StoreDisplayPowerState(power_state); | 405 StoreDisplayPowerState(power_state); |
| 404 } | 406 } |
| 405 | 407 |
| 406 } // namespace chromeos | 408 } // namespace chromeos |
| OLD | NEW |