OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/policy/display_rotation_default_handler.h" | 5 #include "chrome/browser/chromeos/policy/display_rotation_default_handler.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "ash/common/wm_shell.h" | |
10 #include "ash/shell.h" | 9 #include "ash/shell.h" |
11 #include "base/bind.h" | 10 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
13 #include "base/location.h" | 12 #include "base/location.h" |
14 #include "base/logging.h" | 13 #include "base/logging.h" |
15 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
16 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
17 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
18 #include "chromeos/settings/cros_settings_names.h" | 17 #include "chromeos/settings/cros_settings_names.h" |
19 #include "ui/display/manager/display_manager.h" | 18 #include "ui/display/manager/display_manager.h" |
20 | 19 |
21 namespace policy { | 20 namespace policy { |
22 | 21 |
23 DisplayRotationDefaultHandler::DisplayRotationDefaultHandler() { | 22 DisplayRotationDefaultHandler::DisplayRotationDefaultHandler() { |
24 ash::Shell::GetInstance()->window_tree_host_manager()->AddObserver(this); | 23 ash::Shell::GetInstance()->window_tree_host_manager()->AddObserver(this); |
25 ash::WmShell::Get()->AddShellObserver(this); | 24 ash::Shell::GetInstance()->AddShellObserver(this); |
26 settings_observer_ = chromeos::CrosSettings::Get()->AddSettingsObserver( | 25 settings_observer_ = chromeos::CrosSettings::Get()->AddSettingsObserver( |
27 chromeos::kDisplayRotationDefault, | 26 chromeos::kDisplayRotationDefault, |
28 base::Bind(&DisplayRotationDefaultHandler::OnCrosSettingsChanged, | 27 base::Bind(&DisplayRotationDefaultHandler::OnCrosSettingsChanged, |
29 base::Unretained(this))); | 28 base::Unretained(this))); |
30 } | 29 } |
31 | 30 |
32 DisplayRotationDefaultHandler::~DisplayRotationDefaultHandler() { | 31 DisplayRotationDefaultHandler::~DisplayRotationDefaultHandler() { |
33 } | 32 } |
34 | 33 |
35 void DisplayRotationDefaultHandler::OnShellInitialized() { | 34 void DisplayRotationDefaultHandler::OnShellInitialized() { |
36 UpdateFromCrosSettings(); | 35 UpdateFromCrosSettings(); |
37 RotateDisplays(); | 36 RotateDisplays(); |
38 } | 37 } |
39 | 38 |
40 void DisplayRotationDefaultHandler::OnDisplayConfigurationChanged() { | 39 void DisplayRotationDefaultHandler::OnDisplayConfigurationChanged() { |
41 RotateDisplays(); | 40 RotateDisplays(); |
42 } | 41 } |
43 | 42 |
44 void DisplayRotationDefaultHandler::OnWindowTreeHostManagerShutdown() { | 43 void DisplayRotationDefaultHandler::OnWindowTreeHostManagerShutdown() { |
45 ash::Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this); | 44 ash::Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this); |
46 ash::WmShell::Get()->RemoveShellObserver(this); | 45 ash::Shell::GetInstance()->RemoveShellObserver(this); |
47 settings_observer_.reset(); | 46 settings_observer_.reset(); |
48 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); | 47 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); |
49 } | 48 } |
50 | 49 |
51 void DisplayRotationDefaultHandler::OnCrosSettingsChanged() { | 50 void DisplayRotationDefaultHandler::OnCrosSettingsChanged() { |
52 if (!UpdateFromCrosSettings()) | 51 if (!UpdateFromCrosSettings()) |
53 return; | 52 return; |
54 // Policy changed, so reset all displays. | 53 // Policy changed, so reset all displays. |
55 rotated_displays_.clear(); | 54 rotated_displays_.clear(); |
56 RotateDisplays(); | 55 RotateDisplays(); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 (new_policy_enabled && | 102 (new_policy_enabled && |
104 new_display_rotation_default != display_rotation_default_)) { | 103 new_display_rotation_default != display_rotation_default_)) { |
105 policy_enabled_ = new_policy_enabled; | 104 policy_enabled_ = new_policy_enabled; |
106 display_rotation_default_ = new_display_rotation_default; | 105 display_rotation_default_ = new_display_rotation_default; |
107 return true; | 106 return true; |
108 } | 107 } |
109 return false; | 108 return false; |
110 } | 109 } |
111 | 110 |
112 } // namespace policy | 111 } // namespace policy |
OLD | NEW |