OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/macros.h" | 5 #include "base/macros.h" |
| 6 #include "base/metrics/user_metrics.h" |
6 #include "base/metrics/user_metrics_action.h" | 7 #include "base/metrics/user_metrics_action.h" |
7 #include "base/supports_user_data.h" | 8 #include "base/supports_user_data.h" |
8 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 10 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
10 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/browser_commands.h" | 12 #include "chrome/browser/ui/browser_commands.h" |
12 #include "chrome/browser/ui/browser_list.h" | 13 #include "chrome/browser/ui/browser_list.h" |
13 #include "chrome/browser/ui/browser_list_observer.h" | 14 #include "chrome/browser/ui/browser_list_observer.h" |
14 #include "chrome/browser/ui/browser_live_tab_context.h" | 15 #include "chrome/browser/ui/browser_live_tab_context.h" |
15 #include "components/sessions/core/tab_restore_service.h" | 16 #include "components/sessions/core/tab_restore_service.h" |
16 #include "components/sessions/core/tab_restore_service_observer.h" | 17 #include "components/sessions/core/tab_restore_service_observer.h" |
17 #include "content/public/browser/user_metrics.h" | |
18 | 18 |
19 namespace chrome { | 19 namespace chrome { |
20 namespace { | 20 namespace { |
21 | 21 |
22 const char kBrowserTabRestorerKey[] = "BrowserTabRestorer"; | 22 const char kBrowserTabRestorerKey[] = "BrowserTabRestorer"; |
23 | 23 |
24 // BrowserTabRestorer is responsible for restoring a tab when the | 24 // BrowserTabRestorer is responsible for restoring a tab when the |
25 // sessions::TabRestoreService finishes loading. A TabRestoreService is | 25 // sessions::TabRestoreService finishes loading. A TabRestoreService is |
26 // associated with a | 26 // associated with a |
27 // single Browser and deletes itself if the Browser is destroyed. | 27 // single Browser and deletes itself if the Browser is destroyed. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 } | 94 } |
95 | 95 |
96 void BrowserTabRestorer::OnBrowserRemoved(Browser* browser) { | 96 void BrowserTabRestorer::OnBrowserRemoved(Browser* browser) { |
97 // This deletes us. | 97 // This deletes us. |
98 browser_->profile()->SetUserData(kBrowserTabRestorerKey, NULL); | 98 browser_->profile()->SetUserData(kBrowserTabRestorerKey, NULL); |
99 } | 99 } |
100 | 100 |
101 } // namespace | 101 } // namespace |
102 | 102 |
103 void RestoreTab(Browser* browser) { | 103 void RestoreTab(Browser* browser) { |
104 content::RecordAction(base::UserMetricsAction("RestoreTab")); | 104 base::RecordAction(base::UserMetricsAction("RestoreTab")); |
105 sessions::TabRestoreService* service = | 105 sessions::TabRestoreService* service = |
106 TabRestoreServiceFactory::GetForProfile(browser->profile()); | 106 TabRestoreServiceFactory::GetForProfile(browser->profile()); |
107 if (!service) | 107 if (!service) |
108 return; | 108 return; |
109 | 109 |
110 if (service->IsLoaded()) { | 110 if (service->IsLoaded()) { |
111 service->RestoreMostRecentEntry(browser->live_tab_context()); | 111 service->RestoreMostRecentEntry(browser->live_tab_context()); |
112 return; | 112 return; |
113 } | 113 } |
114 | 114 |
115 BrowserTabRestorer::CreateIfNecessary(browser); | 115 BrowserTabRestorer::CreateIfNecessary(browser); |
116 } | 116 } |
117 | 117 |
118 } // namespace chrome | 118 } // namespace chrome |
OLD | NEW |