Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(561)

Side by Side Diff: ash/common/wm/maximize_mode/maximize_mode_controller.cc

Issue 2770723002: Fix MaximizeModeController startup race (Closed)
Patch Set: Verified on Device Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "ash/common/wm/maximize_mode/maximize_mode_controller.h" 5 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "ash/common/ash_switches.h" 9 #include "ash/common/ash_switches.h"
10 #include "ash/common/wm/maximize_mode/maximize_mode_window_manager.h" 10 #include "ash/common/wm/maximize_mode/maximize_mode_window_manager.h"
11 #include "ash/common/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard .h" 11 #include "ash/common/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard .h"
12 #include "ash/common/wm_shell.h" 12 #include "ash/common/wm_shell.h"
13 #include "ash/shell.h" 13 #include "ash/shell.h"
14 #include "base/bind.h"
14 #include "base/command_line.h" 15 #include "base/command_line.h"
15 #include "base/metrics/histogram_macros.h" 16 #include "base/metrics/histogram_macros.h"
16 #include "base/time/default_tick_clock.h" 17 #include "base/time/default_tick_clock.h"
17 #include "base/time/tick_clock.h" 18 #include "base/time/tick_clock.h"
18 #include "chromeos/dbus/dbus_thread_manager.h" 19 #include "chromeos/dbus/dbus_thread_manager.h"
19 #include "ui/base/accelerators/accelerator.h" 20 #include "ui/base/accelerators/accelerator.h"
20 #include "ui/chromeos/accelerometer/accelerometer_util.h" 21 #include "ui/chromeos/accelerometer/accelerometer_util.h"
21 #include "ui/display/display.h" 22 #include "ui/display/display.h"
22 #include "ui/events/event.h" 23 #include "ui/events/event.h"
23 #include "ui/events/keycodes/keyboard_codes.h" 24 #include "ui/events/keycodes/keyboard_codes.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 } 86 }
86 87
87 } // namespace 88 } // namespace
88 89
89 MaximizeModeController::MaximizeModeController() 90 MaximizeModeController::MaximizeModeController()
90 : have_seen_accelerometer_data_(false), 91 : have_seen_accelerometer_data_(false),
91 can_detect_lid_angle_(false), 92 can_detect_lid_angle_(false),
92 touchview_usage_interval_start_time_(base::Time::Now()), 93 touchview_usage_interval_start_time_(base::Time::Now()),
93 tick_clock_(new base::DefaultTickClock()), 94 tick_clock_(new base::DefaultTickClock()),
94 tablet_mode_switch_is_on_(false), 95 tablet_mode_switch_is_on_(false),
95 lid_is_closed_(false) { 96 lid_is_closed_(false),
97 weak_factory_(this) {
96 Shell::GetInstance()->AddShellObserver(this); 98 Shell::GetInstance()->AddShellObserver(this);
97 WmShell::Get()->RecordUserMetricsAction(UMA_MAXIMIZE_MODE_INITIALLY_DISABLED); 99 WmShell::Get()->RecordUserMetricsAction(UMA_MAXIMIZE_MODE_INITIALLY_DISABLED);
98 100
99 // TODO(jonross): Do not create MaximizeModeController if the flag is 101 // TODO(jonross): Do not create MaximizeModeController if the flag is
100 // unavailable. This will require refactoring 102 // unavailable. This will require refactoring
101 // IsMaximizeModeWindowManagerEnabled to check for the existance of the 103 // IsMaximizeModeWindowManagerEnabled to check for the existance of the
102 // controller. 104 // controller.
103 if (IsEnabled()) { 105 if (IsEnabled()) {
104 WmShell::Get()->AddDisplayObserver(this); 106 WmShell::Get()->AddDisplayObserver(this);
105 chromeos::AccelerometerReader::GetInstance()->AddObserver(this); 107 chromeos::AccelerometerReader::GetInstance()->AddObserver(this);
106 } 108 }
107 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver( 109 chromeos::PowerManagerClient* power_manager_client =
108 this); 110 chromeos::DBusThreadManager::Get()->GetPowerManagerClient();
111 power_manager_client->AddObserver(this);
112 power_manager_client->GetSwitchStates(base::Bind(
113 &MaximizeModeController::OnGetSwitchStates, weak_factory_.GetWeakPtr()));
109 } 114 }
110 115
111 MaximizeModeController::~MaximizeModeController() { 116 MaximizeModeController::~MaximizeModeController() {
112 Shell::GetInstance()->RemoveShellObserver(this); 117 Shell::GetInstance()->RemoveShellObserver(this);
113 118
114 if (IsEnabled()) { 119 if (IsEnabled()) {
115 WmShell::Get()->RemoveDisplayObserver(this); 120 WmShell::Get()->RemoveDisplayObserver(this);
116 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this); 121 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this);
117 } 122 }
118 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver( 123 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 base::TimeDelta total_runtime = 417 base::TimeDelta total_runtime =
413 total_touchview_time_ + total_non_touchview_time_; 418 total_touchview_time_ + total_non_touchview_time_;
414 if (total_runtime.InSeconds() > 0) { 419 if (total_runtime.InSeconds() > 0) {
415 UMA_HISTOGRAM_PERCENTAGE( 420 UMA_HISTOGRAM_PERCENTAGE(
416 "Ash.TouchView.TouchViewActivePercentage", 421 "Ash.TouchView.TouchViewActivePercentage",
417 100 * total_touchview_time_.InSeconds() / total_runtime.InSeconds()); 422 100 * total_touchview_time_.InSeconds() / total_runtime.InSeconds());
418 } 423 }
419 } 424 }
420 } 425 }
421 426
427 void MaximizeModeController::OnGetSwitchStates(
428 chromeos::PowerManagerClient::LidState lid_state,
429 chromeos::PowerManagerClient::TabletMode tablet_mode) {
430 LidEventReceived(lid_state, base::TimeTicks::Now());
431 TabletModeEventReceived(tablet_mode, base::TimeTicks::Now());
432 }
433
422 bool MaximizeModeController::WasLidOpenedRecently() const { 434 bool MaximizeModeController::WasLidOpenedRecently() const {
423 if (last_lid_open_time_.is_null()) 435 if (last_lid_open_time_.is_null())
424 return false; 436 return false;
425 437
426 base::TimeTicks now = tick_clock_->NowTicks(); 438 base::TimeTicks now = tick_clock_->NowTicks();
427 DCHECK(now >= last_lid_open_time_); 439 DCHECK(now >= last_lid_open_time_);
428 base::TimeDelta elapsed_time = now - last_lid_open_time_; 440 base::TimeDelta elapsed_time = now - last_lid_open_time_;
429 return elapsed_time.InSeconds() <= kLidRecentlyOpenedDurationSeconds; 441 return elapsed_time.InSeconds() <= kLidRecentlyOpenedDurationSeconds;
430 } 442 }
431 443
432 void MaximizeModeController::SetTickClockForTest( 444 void MaximizeModeController::SetTickClockForTest(
433 std::unique_ptr<base::TickClock> tick_clock) { 445 std::unique_ptr<base::TickClock> tick_clock) {
434 DCHECK(tick_clock_); 446 DCHECK(tick_clock_);
435 tick_clock_ = std::move(tick_clock); 447 tick_clock_ = std::move(tick_clock);
436 } 448 }
437 449
438 } // namespace ash 450 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/wm/maximize_mode/maximize_mode_controller.h ('k') | ash/wm/maximize_mode/maximize_mode_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698