| Index: content/browser/media/capture/ui_activity_tracker_aura.cc
|
| diff --git a/content/browser/media/capture/ui_activity_tracker_aura.cc b/content/browser/media/capture/ui_activity_tracker_aura.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..56d397f39199cdc32c5bb91764aaf3ba0acfad7e
|
| --- /dev/null
|
| +++ b/content/browser/media/capture/ui_activity_tracker_aura.cc
|
| @@ -0,0 +1,71 @@
|
| +// Copyright (c) 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "content/browser/media/capture/ui_activity_tracker_aura.h"
|
| +
|
| +#include "base/logging.h"
|
| +#include "ui/aura/window.h"
|
| +#include "ui/aura/window_tree_host.h"
|
| +#include "ui/events/event_utils.h"
|
| +
|
| +namespace content {
|
| +
|
| +namespace {
|
| +// The time period within which a triggered UI event is considered
|
| +// currently active.
|
| +const int kTimePeriodUiEventMicros = 100000; // 100 ms
|
| +
|
| +// Minimum number of user interactions before we consider the user to be in
|
| +// interactive mode. The goal is to prevent user interactions to launch
|
| +// animated content from causing target playout time flip-flop.
|
| +const int kMinUserInteractions = 5;
|
| +} // namespace
|
| +
|
| +UiActivityTrackerAura::UiActivityTrackerAura(aura::Window* window)
|
| + : window_(window),
|
| + last_time_ui_event_detected_(base::TimeTicks()),
|
| + ui_events_count_(0),
|
| + weak_factory_(this) {
|
| + if (window_) {
|
| + window_->AddObserver(this);
|
| + window_->AddPreTargetHandler(this);
|
| + }
|
| +}
|
| +
|
| +UiActivityTrackerAura::~UiActivityTrackerAura() {
|
| + if (window_) {
|
| + window_->RemoveObserver(this);
|
| + window_->RemovePreTargetHandler(this);
|
| + }
|
| +}
|
| +
|
| +base::WeakPtr<UiActivityTracker> UiActivityTrackerAura::GetWeakPtr() {
|
| + return weak_factory_.GetWeakPtr();
|
| +}
|
| +
|
| +bool UiActivityTrackerAura::uiInteractionActive() const {
|
| + return ui_events_count_ > kMinUserInteractions;
|
| +}
|
| +
|
| +void UiActivityTrackerAura::reset() {
|
| + ui_events_count_ = 0;
|
| + last_time_ui_event_detected_ = base::TimeTicks();
|
| +}
|
| +
|
| +void UiActivityTrackerAura::OnEvent(ui::Event* event) {
|
| + if (base::TimeTicks::Now() - last_time_ui_event_detected_ >
|
| + base::TimeDelta::FromMicroseconds(kTimePeriodUiEventMicros)) {
|
| + ui_events_count_++;
|
| + }
|
| + last_time_ui_event_detected_ = base::TimeTicks::Now();
|
| +}
|
| +
|
| +void UiActivityTrackerAura::OnWindowDestroying(aura::Window* window) {
|
| + DCHECK_EQ(window_, window);
|
| + window_->RemovePreTargetHandler(this);
|
| + window_->RemoveObserver(this);
|
| + window_ = nullptr;
|
| +}
|
| +
|
| +} // namespace content
|
|
|