OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/sessions/chrome_tab_restore_service_client.h" | 5 #include "chrome/browser/sessions/chrome_tab_restore_service_client.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/sessions/session_service.h" | 9 #include "chrome/browser/sessions/session_service.h" |
10 #include "chrome/browser/sessions/session_service_factory.h" | 10 #include "chrome/browser/sessions/session_service_factory.h" |
11 #include "chrome/common/url_constants.h" | 11 #include "chrome/common/url_constants.h" |
12 #include "components/sessions/content/content_live_tab.h" | 12 #include "components/sessions/content/content_live_tab.h" |
13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
14 | 14 |
15 #if defined(ENABLE_EXTENSIONS) | 15 #if defined(ENABLE_EXTENSIONS) |
16 #include "chrome/browser/extensions/tab_helper.h" | 16 #include "chrome/browser/extensions/tab_helper.h" |
17 #include "chrome/common/extensions/extension_constants.h" | 17 #include "chrome/common/extensions/extension_constants.h" |
18 #include "chrome/common/extensions/extension_metrics.h" | 18 #include "chrome/common/extensions/extension_metrics.h" |
19 #include "extensions/browser/extension_registry.h" | 19 #include "extensions/browser/extension_registry.h" |
20 #include "extensions/common/extension.h" | 20 #include "extensions/common/extension.h" |
21 #include "extensions/common/extension_set.h" | 21 #include "extensions/common/extension_set.h" |
22 #endif | 22 #endif |
23 | 23 |
24 #if !defined(OS_ANDROID) | 24 #if !defined(OS_ANDROID) |
25 #include "chrome/browser/ui/browser_live_tab_context.h" | 25 #include "chrome/browser/ui/browser_live_tab_context.h" |
| 26 #else |
| 27 #include "chrome/browser/ui/android/tab_model/android_live_tab_context.h" |
26 #endif | 28 #endif |
27 | 29 |
28 namespace { | 30 namespace { |
29 | 31 |
30 void RecordAppLaunch(Profile* profile, const GURL& url) { | 32 void RecordAppLaunch(Profile* profile, const GURL& url) { |
31 #if defined(ENABLE_EXTENSIONS) | 33 #if defined(ENABLE_EXTENSIONS) |
32 const extensions::Extension* extension = | 34 const extensions::Extension* extension = |
33 extensions::ExtensionRegistry::Get(profile) | 35 extensions::ExtensionRegistry::Get(profile) |
34 ->enabled_extensions() | 36 ->enabled_extensions() |
35 .GetAppByURL(url); | 37 .GetAppByURL(url); |
36 if (!extension) | 38 if (!extension) |
37 return; | 39 return; |
38 | 40 |
39 extensions::RecordAppLaunchType( | 41 extensions::RecordAppLaunchType( |
40 extension_misc::APP_LAUNCH_NTP_RECENTLY_CLOSED, extension->GetType()); | 42 extension_misc::APP_LAUNCH_NTP_RECENTLY_CLOSED, extension->GetType()); |
41 #endif // defined(ENABLE_EXTENSIONS) | 43 #endif // defined(ENABLE_EXTENSIONS) |
42 } | 44 } |
43 | 45 |
44 } // namespace | 46 } // namespace |
45 | 47 |
46 ChromeTabRestoreServiceClient::ChromeTabRestoreServiceClient(Profile* profile) | 48 ChromeTabRestoreServiceClient::ChromeTabRestoreServiceClient(Profile* profile) |
47 : profile_(profile) {} | 49 : profile_(profile) {} |
48 | 50 |
49 ChromeTabRestoreServiceClient::~ChromeTabRestoreServiceClient() {} | 51 ChromeTabRestoreServiceClient::~ChromeTabRestoreServiceClient() {} |
50 | 52 |
51 sessions::LiveTabContext* ChromeTabRestoreServiceClient::CreateLiveTabContext( | 53 sessions::LiveTabContext* ChromeTabRestoreServiceClient::CreateLiveTabContext( |
52 const std::string& app_name) { | 54 const std::string& app_name) { |
53 #if defined(OS_ANDROID) | 55 #if defined(OS_ANDROID) |
54 // Android does not support LiveTabContext, as tab persistence | 56 // Android does not support creating a LiveTabContext here. |
55 // is implemented on the Java side. | 57 NOTREACHED(); |
56 return nullptr; | 58 return nullptr; |
57 #else | 59 #else |
58 return BrowserLiveTabContext::Create(profile_, app_name); | 60 return BrowserLiveTabContext::Create(profile_, app_name); |
59 #endif | 61 #endif |
60 } | 62 } |
61 | 63 |
62 sessions::LiveTabContext* | 64 sessions::LiveTabContext* |
63 ChromeTabRestoreServiceClient::FindLiveTabContextForTab( | 65 ChromeTabRestoreServiceClient::FindLiveTabContextForTab( |
64 const sessions::LiveTab* tab) { | 66 const sessions::LiveTab* tab) { |
65 #if defined(OS_ANDROID) | 67 #if defined(OS_ANDROID) |
66 // Android does not support LiveTabContext, as tab persistence | 68 return AndroidLiveTabContext::FindContextForWebContents( |
67 // is implemented on the Java side. | 69 static_cast<const sessions::ContentLiveTab*>(tab)->web_contents()); |
68 return nullptr; | |
69 #else | 70 #else |
70 return BrowserLiveTabContext::FindContextForWebContents( | 71 return BrowserLiveTabContext::FindContextForWebContents( |
71 static_cast<const sessions::ContentLiveTab*>(tab)->web_contents()); | 72 static_cast<const sessions::ContentLiveTab*>(tab)->web_contents()); |
72 #endif | 73 #endif |
73 } | 74 } |
74 | 75 |
75 sessions::LiveTabContext* | 76 sessions::LiveTabContext* |
76 ChromeTabRestoreServiceClient::FindLiveTabContextWithID( | 77 ChromeTabRestoreServiceClient::FindLiveTabContextWithID( |
77 SessionID::id_type desired_id) { | 78 SessionID::id_type desired_id) { |
78 #if defined(OS_ANDROID) | 79 #if defined(OS_ANDROID) |
79 // Android does not support LiveTabContext, as tab persistence | 80 return AndroidLiveTabContext::FindContextWithID(desired_id);; |
80 // is implemented on the Java side. | |
81 return nullptr; | |
82 #else | 81 #else |
83 return BrowserLiveTabContext::FindContextWithID(desired_id); | 82 return BrowserLiveTabContext::FindContextWithID(desired_id); |
84 #endif | 83 #endif |
85 } | 84 } |
86 | 85 |
87 bool ChromeTabRestoreServiceClient::ShouldTrackURLForRestore(const GURL& url) { | 86 bool ChromeTabRestoreServiceClient::ShouldTrackURLForRestore(const GURL& url) { |
88 return ::ShouldTrackURLForRestore(url); | 87 return ::ShouldTrackURLForRestore(url); |
89 } | 88 } |
90 | 89 |
91 std::string ChromeTabRestoreServiceClient::GetExtensionAppIDForTab( | 90 std::string ChromeTabRestoreServiceClient::GetExtensionAppIDForTab( |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 DCHECK(HasLastSession()); | 143 DCHECK(HasLastSession()); |
145 #if defined(ENABLE_SESSION_SERVICE) | 144 #if defined(ENABLE_SESSION_SERVICE) |
146 SessionServiceFactory::GetForProfile(profile_) | 145 SessionServiceFactory::GetForProfile(profile_) |
147 ->GetLastSession(callback, tracker); | 146 ->GetLastSession(callback, tracker); |
148 #endif | 147 #endif |
149 } | 148 } |
150 | 149 |
151 void ChromeTabRestoreServiceClient::OnTabRestored(const GURL& url) { | 150 void ChromeTabRestoreServiceClient::OnTabRestored(const GURL& url) { |
152 RecordAppLaunch(profile_, url); | 151 RecordAppLaunch(profile_, url); |
153 } | 152 } |
OLD | NEW |