| Index: chrome/browser/ui/tabs/tab_strip_model_stats_recorder.h
|
| diff --git a/chrome/browser/ui/tabs/tab_strip_model_stats_recorder.h b/chrome/browser/ui/tabs/tab_strip_model_stats_recorder.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..9bd9ab0ab85b0fa996a05cd4d465f0cb1cb16789
|
| --- /dev/null
|
| +++ b/chrome/browser/ui/tabs/tab_strip_model_stats_recorder.h
|
| @@ -0,0 +1,80 @@
|
| +// Copyright 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.
|
| +
|
| +#ifndef CHROME_BROWSER_UI_TABS_TAB_STRIP_MODEL_STATS_RECORDER_H_
|
| +#define CHROME_BROWSER_UI_TABS_TAB_STRIP_MODEL_STATS_RECORDER_H_
|
| +
|
| +#include <list>
|
| +
|
| +#include "base/containers/hash_tables.h"
|
| +#include "base/time/time.h"
|
| +#include "chrome/browser/ui/browser_list_observer.h"
|
| +#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
|
| +
|
| +namespace content {
|
| +class WebContents;
|
| +}
|
| +
|
| +namespace chrome {
|
| +
|
| +// TabStripModelStatsRecorder records user tab interaction stats.
|
| +// In particular, we record tab's lifetime and state transition probability to
|
| +// study user interaction with background tabs. (crbug.com/517335)
|
| +class TabStripModelStatsRecorder : public BrowserListObserver,
|
| + public TabStripModelObserver {
|
| + public:
|
| + TabStripModelStatsRecorder();
|
| + ~TabStripModelStatsRecorder() override;
|
| +
|
| + // chrome::BrowserListObserver implementation.
|
| + void OnBrowserAdded(Browser* browser) override;
|
| + void OnBrowserRemoved(Browser* browser) override;
|
| + void OnBrowserSetLastActive(Browser* browser) override {}
|
| +
|
| + // TabStripModelObserver implementation.
|
| + void TabInsertedAt(content::WebContents* contents,
|
| + int index,
|
| + bool foreground) override;
|
| + void TabClosingAt(TabStripModel* tab_strip_model,
|
| + content::WebContents* contents,
|
| + int index) override;
|
| + void TabDetachedAt(content::WebContents* contents, int index) override;
|
| + void ActiveTabChanged(content::WebContents* old_contents,
|
| + content::WebContents* new_contents,
|
| + int index,
|
| + int reason) override;
|
| + void TabReplacedAt(TabStripModel* tab_strip_model,
|
| + content::WebContents* old_contents,
|
| + content::WebContents* new_contents,
|
| + int index) override;
|
| +
|
| + class TabInfo {
|
| + public:
|
| + enum class State {
|
| + INITIAL = 0,
|
| + ACTIVE,
|
| + INACTIVE,
|
| + DETACHED,
|
| + CLOSED,
|
| + MAX,
|
| + };
|
| +
|
| + void UpdateState(State new_state);
|
| +
|
| + State state() const { return current_state_; }
|
| +
|
| + private:
|
| + State current_state_ = State::INITIAL;
|
| + base::Time last_state_modified_;
|
| + };
|
| +
|
| + private:
|
| + base::hash_map<content::WebContents*, TabInfo> tab_info_map_;
|
| + int last_active_index_ = 0;
|
| + std::list<content::WebContents*> active_tab_history_;
|
| +};
|
| +
|
| +} // namespace chrome
|
| +
|
| +#endif // CHROME_BROWSER_UI_TABS_TAB_STRIP_MODEL_STATS_RECORDER_H_
|
|
|