blob: c8935c0925cbfe59e1add65a2798fbcea1fa4d2f [file] [log] [blame]
// Copyright 2017 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 <map>
#include "base/macros.h"
#include "base/optional.h"
#include "base/time/time.h"
#include "content/public/browser/web_contents_observer.h"
namespace base {
class TickClock;
namespace extensions {
class AppWindow;
namespace lock_screen_apps {
// Helper for tracking metrics for lock screen app window launches.
class AppWindowMetricsTracker : public content::WebContentsObserver {
explicit AppWindowMetricsTracker(const base::TickClock* clock);
~AppWindowMetricsTracker() override;
// Register app launch request.
void AppLaunchRequested();
// Registers the app window created for lock screen action - the class
// will begin observing the app window state as a result.
void AppWindowCreated(extensions::AppWindow* app_window);
// Updates metrics state for app window being moved to foreground.
void MovedToForeground();
// Updates metrics state for app window being moved to background.
void MovedToBackground();
// Stops tracking current app window state, and resets collected timestamps.
void Reset();
// content::WebContentsObserver:
void RenderViewCreated(content::RenderViewHost* render_view_host) override;
void DocumentOnLoadCompletedInMainFrame() override;
// NOTE: Used in histograms - do not change order, or remove entries.
// Also, update LockScreenAppSessionState enum.
enum class State {
kInitial = 0,
kLaunchRequested = 1,
kWindowCreated = 2,
kWindowShown = 3,
kForeground = 4,
kBackground = 5,
void SetState(State state);
const base::TickClock* clock_;
State state_ = State::kInitial;
// Maps states to their last occurrence time.
std::map<State, base::TimeTicks> time_stamps_;
// Number of times app launch was requested during the
int app_launch_count_ = 0;
// The state to which the metrics tracker should move after
// the window contents is loaded.
// Should be either kForeground or kBackground.
base::Optional<State> state_after_window_contents_load_ = State::kForeground;
} // namespace lock_screen_apps