OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/browser/media/capture/window_activity_tracker_aura.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "ui/aura/window.h" |
| 9 #include "ui/aura/window_tree_host.h" |
| 10 #include "ui/events/event_utils.h" |
| 11 |
| 12 namespace content { |
| 13 |
| 14 namespace { |
| 15 // The time period within which a triggered UI event is considered |
| 16 // currently active. |
| 17 const int kTimePeriodUiEventMicros = 100000; // 100 ms |
| 18 |
| 19 // Minimum number of user interactions before we consider the user to be in |
| 20 // interactive mode. The goal is to prevent user interactions to launch |
| 21 // animated content from causing target playout time flip-flop. |
| 22 const int kMinUserInteractions = 5; |
| 23 } // namespace |
| 24 |
| 25 WindowActivityTrackerAura::WindowActivityTrackerAura(aura::Window* window) |
| 26 : window_(window), |
| 27 last_time_ui_event_detected_(base::TimeTicks()), |
| 28 ui_events_count_(0), |
| 29 weak_factory_(this) { |
| 30 if (window_) { |
| 31 window_->AddObserver(this); |
| 32 window_->AddPreTargetHandler(this); |
| 33 } |
| 34 } |
| 35 |
| 36 WindowActivityTrackerAura::~WindowActivityTrackerAura() { |
| 37 if (window_) { |
| 38 window_->RemoveObserver(this); |
| 39 window_->RemovePreTargetHandler(this); |
| 40 } |
| 41 } |
| 42 |
| 43 base::WeakPtr<WindowActivityTracker> WindowActivityTrackerAura::GetWeakPtr() { |
| 44 return weak_factory_.GetWeakPtr(); |
| 45 } |
| 46 |
| 47 bool WindowActivityTrackerAura::IsUiInteractionActive() const { |
| 48 return ui_events_count_ > kMinUserInteractions; |
| 49 } |
| 50 |
| 51 void WindowActivityTrackerAura::Reset() { |
| 52 ui_events_count_ = 0; |
| 53 last_time_ui_event_detected_ = base::TimeTicks(); |
| 54 } |
| 55 |
| 56 void WindowActivityTrackerAura::OnEvent(ui::Event* event) { |
| 57 if (base::TimeTicks::Now() - last_time_ui_event_detected_ > |
| 58 base::TimeDelta::FromMicroseconds(kTimePeriodUiEventMicros)) { |
| 59 ui_events_count_++; |
| 60 } |
| 61 last_time_ui_event_detected_ = base::TimeTicks::Now(); |
| 62 } |
| 63 |
| 64 void WindowActivityTrackerAura::OnWindowDestroying(aura::Window* window) { |
| 65 DCHECK_EQ(window_, window); |
| 66 window_->RemovePreTargetHandler(this); |
| 67 window_->RemoveObserver(this); |
| 68 window_ = nullptr; |
| 69 } |
| 70 |
| 71 } // namespace content |
OLD | NEW |