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_manager.h" | |
10 #include "ash/display/display_pref_util.h" | 9 #include "ash/display/display_pref_util.h" |
11 #include "ash/display/json_converter.h" | 10 #include "ash/display/json_converter.h" |
12 #include "ash/shell.h" | 11 #include "ash/shell.h" |
13 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
14 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/string_split.h" | 14 #include "base/strings/string_split.h" |
16 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
17 #include "base/sys_info.h" | 16 #include "base/sys_info.h" |
18 #include "base/values.h" | 17 #include "base/values.h" |
19 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
20 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
21 #include "components/prefs/pref_registry_simple.h" | 20 #include "components/prefs/pref_registry_simple.h" |
22 #include "components/prefs/pref_service.h" | 21 #include "components/prefs/pref_service.h" |
23 #include "components/prefs/scoped_user_pref_update.h" | 22 #include "components/prefs/scoped_user_pref_update.h" |
24 #include "components/user_manager/user_manager.h" | 23 #include "components/user_manager/user_manager.h" |
25 #include "third_party/cros_system_api/dbus/service_constants.h" | 24 #include "third_party/cros_system_api/dbus/service_constants.h" |
26 #include "ui/display/display.h" | 25 #include "ui/display/display.h" |
27 #include "ui/display/manager/display_layout_store.h" | 26 #include "ui/display/manager/display_layout_store.h" |
| 27 #include "ui/display/manager/display_manager.h" |
28 #include "ui/display/manager/display_manager_utilities.h" | 28 #include "ui/display/manager/display_manager_utilities.h" |
29 #include "ui/gfx/geometry/insets.h" | 29 #include "ui/gfx/geometry/insets.h" |
30 #include "url/url_canon.h" | 30 #include "url/url_canon.h" |
31 #include "url/url_util.h" | 31 #include "url/url_util.h" |
32 | 32 |
33 namespace chromeos { | 33 namespace chromeos { |
34 namespace { | 34 namespace { |
35 | 35 |
36 const char kInsetsTopKey[] = "insets_top"; | 36 const char kInsetsTopKey[] = "insets_top"; |
37 const char kInsetsLeftKey[] = "insets_left"; | 37 const char kInsetsLeftKey[] = "insets_left"; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 else if (value == "dynamic") | 88 else if (value == "dynamic") |
89 return ui::COLOR_PROFILE_DYNAMIC; | 89 return ui::COLOR_PROFILE_DYNAMIC; |
90 else if (value == "movie") | 90 else if (value == "movie") |
91 return ui::COLOR_PROFILE_MOVIE; | 91 return ui::COLOR_PROFILE_MOVIE; |
92 else if (value == "reading") | 92 else if (value == "reading") |
93 return ui::COLOR_PROFILE_READING; | 93 return ui::COLOR_PROFILE_READING; |
94 NOTREACHED(); | 94 NOTREACHED(); |
95 return ui::COLOR_PROFILE_STANDARD; | 95 return ui::COLOR_PROFILE_STANDARD; |
96 } | 96 } |
97 | 97 |
98 ash::DisplayManager* GetDisplayManager() { | 98 display::DisplayManager* GetDisplayManager() { |
99 return ash::Shell::GetInstance()->display_manager(); | 99 return ash::Shell::GetInstance()->display_manager(); |
100 } | 100 } |
101 | 101 |
102 // Returns true id the current user can write display preferences to | 102 // Returns true id the current user can write display preferences to |
103 // Local State. | 103 // Local State. |
104 bool UserCanSaveDisplayPreference() { | 104 bool UserCanSaveDisplayPreference() { |
105 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); | 105 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
106 return user_manager->IsUserLoggedIn() && | 106 return user_manager->IsUserLoggedIn() && |
107 (user_manager->IsLoggedInAsUserWithGaiaAccount() || | 107 (user_manager->IsLoggedInAsUserWithGaiaAccount() || |
108 user_manager->IsLoggedInAsSupervisedUser() || | 108 user_manager->IsLoggedInAsSupervisedUser() || |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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() { |
233 ash::DisplayManager* display_manager = GetDisplayManager(); | 233 display::DisplayManager* display_manager = GetDisplayManager(); |
234 if (!UserCanSaveDisplayPreference() || | 234 if (!UserCanSaveDisplayPreference() || |
235 display_manager->num_connected_displays() < 2) { | 235 display_manager->num_connected_displays() < 2) { |
236 return; | 236 return; |
237 } | 237 } |
238 | 238 |
239 display::DisplayIdList list = display_manager->GetCurrentDisplayIdList(); | 239 display::DisplayIdList list = display_manager->GetCurrentDisplayIdList(); |
240 const display::DisplayLayout& display_layout = | 240 const display::DisplayLayout& display_layout = |
241 display_manager->layout_store()->GetRegisteredDisplayLayout(list); | 241 display_manager->layout_store()->GetRegisteredDisplayLayout(list); |
242 StoreDisplayLayoutPref(list, display_layout); | 242 StoreDisplayLayoutPref(list, display_layout); |
243 } | 243 } |
244 | 244 |
245 void StoreCurrentDisplayProperties() { | 245 void StoreCurrentDisplayProperties() { |
246 ash::DisplayManager* display_manager = GetDisplayManager(); | 246 display::DisplayManager* display_manager = GetDisplayManager(); |
247 PrefService* local_state = g_browser_process->local_state(); | 247 PrefService* local_state = g_browser_process->local_state(); |
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 display::Display& display = display_manager->GetDisplayAt(i); | 254 const display::Display& display = display_manager->GetDisplayAt(i); |
255 int64_t id = display.id(); | 255 int64_t id = display.id(); |
256 display::ManagedDisplayInfo info = display_manager->GetDisplayInfo(id); | 256 display::ManagedDisplayInfo info = display_manager->GetDisplayInfo(id); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 const display::DisplayLayout& layout) { | 394 const display::DisplayLayout& layout) { |
395 StoreDisplayLayoutPref(list, layout); | 395 StoreDisplayLayoutPref(list, layout); |
396 } | 396 } |
397 | 397 |
398 // Stores the given |power_state|. | 398 // Stores the given |power_state|. |
399 void StoreDisplayPowerStateForTest(DisplayPowerState power_state) { | 399 void StoreDisplayPowerStateForTest(DisplayPowerState power_state) { |
400 StoreDisplayPowerState(power_state); | 400 StoreDisplayPowerState(power_state); |
401 } | 401 } |
402 | 402 |
403 } // namespace chromeos | 403 } // namespace chromeos |
OLD | NEW |