Skip to content

Commit

Permalink
[Session restore] Add DontRestoreBackgroundTabs group to collect stats.
Browse files Browse the repository at this point in the history
BUG=

Review URL: https://codereview.chromium.org/1137033004

Cr-Commit-Position: refs/heads/master@{#329245}
  • Loading branch information
georgesak authored and Commit bot committed May 11, 2015
1 parent e226596 commit 1912f4a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
22 changes: 20 additions & 2 deletions chrome/browser/sessions/session_restore_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "chrome/browser/sessions/session_restore_stats_collector.h"
#include "chrome/browser/sessions/tab_loader.h"
#include "chrome/common/url_constants.h"
#include "components/favicon/content/content_favicon_driver.h"
#include "content/public/browser/web_contents.h"

namespace {
Expand Down Expand Up @@ -64,6 +65,23 @@ bool SessionRestoreDelegate::RestoredTab::operator<(
void SessionRestoreDelegate::RestoreTabs(
const std::vector<RestoredTab>& tabs,
const base::TimeTicks& restore_started) {
SessionRestoreStatsCollector::TrackTabs(tabs, restore_started);
TabLoader::RestoreTabs(tabs, restore_started);
// This experiment allows us to have comparative numbers for session restore
// metrics. It will be removed once those numbers are obtained.
// TODO(georgesak): Remove this experiment when stats are collected.
base::FieldTrial* trial =
base::FieldTrialList::Find("IntelligentSessionRestore");
if (!trial || trial->group_name() != "DontRestoreBackgroundTabs") {
SessionRestoreStatsCollector::TrackTabs(tabs, restore_started);
TabLoader::RestoreTabs(tabs, restore_started);
} else {
SessionRestoreStatsCollector::TrackActiveTabs(tabs, restore_started);
for (auto& restored_tab : tabs) {
if (!restored_tab.is_active()) {
favicon::ContentFaviconDriver* favicon_driver =
favicon::ContentFaviconDriver::FromWebContents(
restored_tab.contents());
favicon_driver->FetchFavicon(favicon_driver->GetActiveURL());
}
}
}
}
15 changes: 15 additions & 0 deletions chrome/browser/sessions/session_restore_stats_collector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ void SessionRestoreStatsCollector::TrackTabs(
shared_collector_->AddTabs(tabs);
}

// static
void SessionRestoreStatsCollector::TrackActiveTabs(
const std::vector<SessionRestoreDelegate::RestoredTab>& tabs,
const base::TimeTicks& restore_started) {
if (!shared_collector_)
shared_collector_ = new SessionRestoreStatsCollector(restore_started);

std::vector<SessionRestoreDelegate::RestoredTab> active_tabs;
for (auto tab : tabs) {
if (tab.is_active())
active_tabs.push_back(tab);
}
shared_collector_->AddTabs(active_tabs);
}

SessionRestoreStatsCollector::SessionRestoreStatsCollector(
const base::TimeTicks& restore_started)
: got_first_foreground_load_(false),
Expand Down
6 changes: 6 additions & 0 deletions chrome/browser/sessions/session_restore_stats_collector.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ class SessionRestoreStatsCollector
const std::vector<SessionRestoreDelegate::RestoredTab>& tabs,
const base::TimeTicks& restore_started);

// Called to start tracking only active tabs. If a restore is already
// occuring, the tabs are added to the existing list of tracked tabs.
static void TrackActiveTabs(
const std::vector<SessionRestoreDelegate::RestoredTab>& tabs,
const base::TimeTicks& restore_started);

private:
friend class base::RefCounted<SessionRestoreStatsCollector>;

Expand Down

0 comments on commit 1912f4a

Please sign in to comment.