| 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 "ash/display/display_controller.h" | 7 #include "ash/display/display_controller.h" |
| 8 #include "ash/display/display_layout_store.h" |
| 8 #include "ash/display/display_manager.h" | 9 #include "ash/display/display_manager.h" |
| 9 #include "ash/display/display_pref_util.h" | 10 #include "ash/display/display_pref_util.h" |
| 10 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 11 #include "base/prefs/pref_registry_simple.h" | 12 #include "base/prefs/pref_registry_simple.h" |
| 12 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
| 13 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" |
| 16 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 17 #include "base/values.h" | 18 #include "base/values.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 !user_manager->IsLoggedInAsGuest() && | 76 !user_manager->IsLoggedInAsGuest() && |
| 76 !user_manager->IsLoggedInAsStub()); | 77 !user_manager->IsLoggedInAsStub()); |
| 77 } | 78 } |
| 78 | 79 |
| 79 ash::DisplayController* GetDisplayController() { | 80 ash::DisplayController* GetDisplayController() { |
| 80 return ash::Shell::GetInstance()->display_controller(); | 81 return ash::Shell::GetInstance()->display_controller(); |
| 81 } | 82 } |
| 82 | 83 |
| 83 void LoadDisplayLayouts() { | 84 void LoadDisplayLayouts() { |
| 84 PrefService* local_state = g_browser_process->local_state(); | 85 PrefService* local_state = g_browser_process->local_state(); |
| 85 ash::DisplayController* display_controller = GetDisplayController(); | 86 ash::internal::DisplayLayoutStore* layout_store = |
| 87 GetDisplayManager()->layout_store(); |
| 86 | 88 |
| 87 const base::DictionaryValue* layouts = local_state->GetDictionary( | 89 const base::DictionaryValue* layouts = local_state->GetDictionary( |
| 88 prefs::kSecondaryDisplays); | 90 prefs::kSecondaryDisplays); |
| 89 for (DictionaryValue::Iterator it(*layouts); !it.IsAtEnd(); it.Advance()) { | 91 for (DictionaryValue::Iterator it(*layouts); !it.IsAtEnd(); it.Advance()) { |
| 90 ash::DisplayLayout layout; | 92 ash::DisplayLayout layout; |
| 91 if (!ash::DisplayLayout::ConvertFromValue(it.value(), &layout)) { | 93 if (!ash::DisplayLayout::ConvertFromValue(it.value(), &layout)) { |
| 92 LOG(WARNING) << "Invalid preference value for " << it.key(); | 94 LOG(WARNING) << "Invalid preference value for " << it.key(); |
| 93 continue; | 95 continue; |
| 94 } | 96 } |
| 95 | 97 |
| 96 if (it.key().find(",") != std::string::npos) { | 98 if (it.key().find(",") != std::string::npos) { |
| 97 std::vector<std::string> ids; | 99 std::vector<std::string> ids; |
| 98 base::SplitString(it.key(), ',', &ids); | 100 base::SplitString(it.key(), ',', &ids); |
| 99 int64 id1 = gfx::Display::kInvalidDisplayID; | 101 int64 id1 = gfx::Display::kInvalidDisplayID; |
| 100 int64 id2 = gfx::Display::kInvalidDisplayID; | 102 int64 id2 = gfx::Display::kInvalidDisplayID; |
| 101 if (!base::StringToInt64(ids[0], &id1) || | 103 if (!base::StringToInt64(ids[0], &id1) || |
| 102 !base::StringToInt64(ids[1], &id2) || | 104 !base::StringToInt64(ids[1], &id2) || |
| 103 id1 == gfx::Display::kInvalidDisplayID || | 105 id1 == gfx::Display::kInvalidDisplayID || |
| 104 id2 == gfx::Display::kInvalidDisplayID) { | 106 id2 == gfx::Display::kInvalidDisplayID) { |
| 105 continue; | 107 continue; |
| 106 } | 108 } |
| 107 display_controller->RegisterLayoutForDisplayIdPair(id1, id2, layout); | 109 layout_store->RegisterLayoutForDisplayIdPair(id1, id2, layout); |
| 108 } | 110 } |
| 109 } | 111 } |
| 110 } | 112 } |
| 111 | 113 |
| 112 void LoadDisplayProperties() { | 114 void LoadDisplayProperties() { |
| 113 PrefService* local_state = g_browser_process->local_state(); | 115 PrefService* local_state = g_browser_process->local_state(); |
| 114 const base::DictionaryValue* properties = local_state->GetDictionary( | 116 const base::DictionaryValue* properties = local_state->GetDictionary( |
| 115 prefs::kDisplayProperties); | 117 prefs::kDisplayProperties); |
| 116 for (DictionaryValue::Iterator it(*properties); !it.IsAtEnd(); it.Advance()) { | 118 for (DictionaryValue::Iterator it(*properties); !it.IsAtEnd(); it.Advance()) { |
| 117 const base::DictionaryValue* dict_value = NULL; | 119 const base::DictionaryValue* dict_value = NULL; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 layout_value.reset(value->DeepCopy()); | 160 layout_value.reset(value->DeepCopy()); |
| 159 } | 161 } |
| 160 if (ash::DisplayLayout::ConvertToValue(display_layout, layout_value.get())) | 162 if (ash::DisplayLayout::ConvertToValue(display_layout, layout_value.get())) |
| 161 pref_data->Set(name, layout_value.release()); | 163 pref_data->Set(name, layout_value.release()); |
| 162 } | 164 } |
| 163 | 165 |
| 164 void StoreCurrentDisplayLayoutPrefs() { | 166 void StoreCurrentDisplayLayoutPrefs() { |
| 165 if (!IsValidUser() || GetDisplayManager()->num_connected_displays() < 2) | 167 if (!IsValidUser() || GetDisplayManager()->num_connected_displays() < 2) |
| 166 return; | 168 return; |
| 167 | 169 |
| 168 ash::DisplayController* display_controller = GetDisplayController(); | 170 ash::DisplayIdPair pair = GetDisplayController()->GetCurrentDisplayIdPair(); |
| 169 ash::DisplayIdPair pair = display_controller->GetCurrentDisplayIdPair(); | |
| 170 ash::DisplayLayout display_layout = | 171 ash::DisplayLayout display_layout = |
| 171 display_controller->GetRegisteredDisplayLayout(pair); | 172 GetDisplayManager()->layout_store()->GetRegisteredDisplayLayout(pair); |
| 172 StoreDisplayLayoutPref(pair, display_layout); | 173 StoreDisplayLayoutPref(pair, display_layout); |
| 173 } | 174 } |
| 174 | 175 |
| 175 void StoreCurrentDisplayProperties() { | 176 void StoreCurrentDisplayProperties() { |
| 176 ash::internal::DisplayManager* display_manager = GetDisplayManager(); | 177 ash::internal::DisplayManager* display_manager = GetDisplayManager(); |
| 177 PrefService* local_state = g_browser_process->local_state(); | 178 PrefService* local_state = g_browser_process->local_state(); |
| 178 | 179 |
| 179 DictionaryPrefUpdate update(local_state, prefs::kDisplayProperties); | 180 DictionaryPrefUpdate update(local_state, prefs::kDisplayProperties); |
| 180 base::DictionaryValue* pref_data = update.Get(); | 181 base::DictionaryValue* pref_data = update.Get(); |
| 181 | 182 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 const ash::DisplayLayout& layout) { | 276 const ash::DisplayLayout& layout) { |
| 276 StoreDisplayLayoutPref(std::make_pair(id1, id2), layout); | 277 StoreDisplayLayoutPref(std::make_pair(id1, id2), layout); |
| 277 } | 278 } |
| 278 | 279 |
| 279 // Stores the given |power_state|. | 280 // Stores the given |power_state|. |
| 280 void StoreDisplayPowerStateForTest(DisplayPowerState power_state) { | 281 void StoreDisplayPowerStateForTest(DisplayPowerState power_state) { |
| 281 StoreDisplayPowerState(power_state); | 282 StoreDisplayPowerState(power_state); |
| 282 } | 283 } |
| 283 | 284 |
| 284 } // namespace chromeos | 285 } // namespace chromeos |
| OLD | NEW |