blob: 1e6d1b0d346cc675de5ab24428e9286d3bdd1489 [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 <memory>
#include "base/sequence_checker.h"
class PrefService;
namespace metrics {
// The data store that keeps track of all the information that the
// TabStatsTracker wants to track.
class TabStatsDataStore {
// Houses all of the statistics gathered by the TabStatsTracker.
struct TabsStats {
// Constructor, initializes everything to zero.
// The total number of tabs opened across all the windows.
size_t total_tab_count;
// The maximum total number of tabs that has been opened across all the
// windows at the same time.
size_t total_tab_count_max;
// The maximum total number of tabs that has been opened at the same time in
// a single window.
size_t max_tab_per_window;
// The total number of windows opened.
size_t window_count;
// The maximum total number of windows opened at the same time.
size_t window_count_max;
explicit TabStatsDataStore(PrefService* pref_service);
~TabStatsDataStore() {}
// Functions used to update the window/tab count.
void OnWindowAdded();
void OnWindowRemoved();
void OnTabsAdded(size_t tab_count);
void OnTabsRemoved(size_t tab_count);
// Update the maximum number of tabs in a single window if |value| exceeds
// this.
// TODO(sebmarchand): Store a list of windows in this class and track the
// number of tabs per window.
void UpdateMaxTabsPerWindowIfNeeded(size_t value);
// Reset all the maximum values to the current state, to be used once the
// metrics have been reported.
void ResetMaximumsToCurrentState();
const TabsStats& tab_stats() const { return tab_stats_; }
// Update the maximums metrics if needed.
void UpdateTotalTabCountMaxIfNeeded();
void UpdateWindowCountMaxIfNeeded();
// The tabs stats.
TabsStats tab_stats_;
// A raw pointer to the PrefService used to read and write the statistics.
PrefService* pref_service_;
} // namespace metrics