blob: 5f016e0dc533692e1d6180d592bb64d9830f9868 [file] [log] [blame]
georgesaka3ae61c72015-04-02 01:04:261// Copyright 2015 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/sessions/session_restore_delegate.h"
6
georgesakfbcd45d2015-04-07 15:08:247#include "base/metrics/field_trial.h"
georgesak98702bbb2015-04-03 17:59:228#include "chrome/browser/sessions/session_restore_stats_collector.h"
georgesaka3ae61c72015-04-02 01:04:269#include "chrome/browser/sessions/tab_loader.h"
georgesak189ed372015-05-08 03:53:3010#include "chrome/common/url_constants.h"
georgesakbf4674a2015-04-13 18:50:3111#include "components/favicon/content/content_favicon_driver.h"
georgesaka3ae61c72015-04-02 01:04:2612
georgesak189ed372015-05-08 03:53:3013namespace {
14
15bool IsInternalPage(const GURL& url) {
16 // There are many chrome:// UI URLs, but only look for the ones that users
17 // are likely to have open. Most of the benefit is from the NTP URL.
18 const char* const kReloadableUrlPrefixes[] = {
19 chrome::kChromeUIDownloadsURL,
20 chrome::kChromeUIHistoryURL,
21 chrome::kChromeUINewTabURL,
22 chrome::kChromeUISettingsURL,
23 };
24 // Prefix-match against the table above. Use strncmp to avoid allocating
25 // memory to convert the URL prefix constants into std::strings.
26 for (size_t i = 0; i < arraysize(kReloadableUrlPrefixes); ++i) {
27 if (!strncmp(url.spec().c_str(), kReloadableUrlPrefixes[i],
28 strlen(kReloadableUrlPrefixes[i])))
29 return true;
30 }
31 return false;
32}
33
34} // namespace
35
36SessionRestoreDelegate::RestoredTab::RestoredTab(content::WebContents* contents,
37 bool is_active,
38 bool is_app,
39 bool is_pinned)
40 : contents_(contents),
41 is_active_(is_active),
42 is_app_(is_app),
43 is_internal_page_(IsInternalPage(contents->GetLastCommittedURL())),
44 is_pinned_(is_pinned) {
45}
46
47bool SessionRestoreDelegate::RestoredTab::operator<(
48 const RestoredTab& right) const {
49 // Tab with internal web UI like NTP or Settings are good choices to
50 // defer loading.
51 if (is_internal_page_ != right.is_internal_page_)
52 return !is_internal_page_;
53 // Pinned tabs should be loaded first.
54 if (is_pinned_ != right.is_pinned_)
55 return is_pinned_;
56 // Apps should be loaded before normal tabs.
57 if (is_app_ != right.is_app_)
58 return is_app_;
59 // TODO(georgesak): Add criterion based on recency.
60 return false;
61}
62
georgesaka3ae61c72015-04-02 01:04:2663// static
georgesakb1881ce2015-05-06 20:22:1164void SessionRestoreDelegate::RestoreTabs(
65 const std::vector<RestoredTab>& tabs,
66 const base::TimeTicks& restore_started) {
67 SessionRestoreStatsCollector::TrackTabs(tabs, restore_started);
68 TabLoader::RestoreTabs(tabs, restore_started);
georgesaka3ae61c72015-04-02 01:04:2669}