| 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 "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
| 8 #include "chrome/browser/sessions/session_service.h" | 8 #include "chrome/browser/sessions/session_service.h" |
| 9 #include "chrome/browser/sessions/session_service_factory.h" | 9 #include "chrome/browser/sessions/session_service_factory.h" |
| 10 #include "chrome/common/url_constants.h" | 10 #include "chrome/common/url_constants.h" |
| 11 #include "components/sessions/content/content_live_tab.h" |
| 11 #include "components/sessions/content/content_tab_client_data.h" | 12 #include "components/sessions/content/content_tab_client_data.h" |
| 12 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 13 | 14 |
| 14 #if defined(ENABLE_EXTENSIONS) | 15 #if defined(ENABLE_EXTENSIONS) |
| 15 #include "chrome/browser/extensions/tab_helper.h" | 16 #include "chrome/browser/extensions/tab_helper.h" |
| 16 #include "chrome/common/extensions/extension_constants.h" | 17 #include "chrome/common/extensions/extension_constants.h" |
| 17 #include "chrome/common/extensions/extension_metrics.h" | 18 #include "chrome/common/extensions/extension_metrics.h" |
| 18 #include "extensions/browser/extension_registry.h" | 19 #include "extensions/browser/extension_registry.h" |
| 19 #include "extensions/common/extension.h" | 20 #include "extensions/common/extension.h" |
| 20 #include "extensions/common/extension_set.h" | 21 #include "extensions/common/extension_set.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 // is implemented on the Java side. | 57 // is implemented on the Java side. |
| 57 return nullptr; | 58 return nullptr; |
| 58 #else | 59 #else |
| 59 return BrowserTabRestoreServiceDelegate::Create( | 60 return BrowserTabRestoreServiceDelegate::Create( |
| 60 profile_, static_cast<chrome::HostDesktopType>(host_desktop_type), | 61 profile_, static_cast<chrome::HostDesktopType>(host_desktop_type), |
| 61 app_name); | 62 app_name); |
| 62 #endif | 63 #endif |
| 63 } | 64 } |
| 64 | 65 |
| 65 TabRestoreServiceDelegate* | 66 TabRestoreServiceDelegate* |
| 66 ChromeTabRestoreServiceClient::FindTabRestoreServiceDelegateForWebContents( | 67 ChromeTabRestoreServiceClient::FindTabRestoreServiceDelegateForTab( |
| 67 const content::WebContents* contents) { | 68 const sessions::LiveTab* tab) { |
| 68 #if defined(OS_ANDROID) | 69 #if defined(OS_ANDROID) |
| 69 // Android does not support TabRestoreServiceDelegate, as tab persistence | 70 // Android does not support TabRestoreServiceDelegate, as tab persistence |
| 70 // is implemented on the Java side. | 71 // is implemented on the Java side. |
| 71 return nullptr; | 72 return nullptr; |
| 72 #else | 73 #else |
| 73 return BrowserTabRestoreServiceDelegate::FindDelegateForWebContents(contents); | 74 return BrowserTabRestoreServiceDelegate::FindDelegateForWebContents( |
| 75 static_cast<const sessions::ContentLiveTab*>(tab)->web_contents()); |
| 74 #endif | 76 #endif |
| 75 } | 77 } |
| 76 | 78 |
| 77 TabRestoreServiceDelegate* | 79 TabRestoreServiceDelegate* |
| 78 ChromeTabRestoreServiceClient::FindTabRestoreServiceDelegateWithID( | 80 ChromeTabRestoreServiceClient::FindTabRestoreServiceDelegateWithID( |
| 79 SessionID::id_type desired_id, | 81 SessionID::id_type desired_id, |
| 80 int host_desktop_type) { | 82 int host_desktop_type) { |
| 81 #if defined(OS_ANDROID) | 83 #if defined(OS_ANDROID) |
| 82 // Android does not support TabRestoreServiceDelegate, as tab persistence | 84 // Android does not support TabRestoreServiceDelegate, as tab persistence |
| 83 // is implemented on the Java side. | 85 // is implemented on the Java side. |
| 84 return nullptr; | 86 return nullptr; |
| 85 #else | 87 #else |
| 86 return BrowserTabRestoreServiceDelegate::FindDelegateWithID( | 88 return BrowserTabRestoreServiceDelegate::FindDelegateWithID( |
| 87 desired_id, static_cast<chrome::HostDesktopType>(host_desktop_type)); | 89 desired_id, static_cast<chrome::HostDesktopType>(host_desktop_type)); |
| 88 #endif | 90 #endif |
| 89 } | 91 } |
| 90 | 92 |
| 91 bool ChromeTabRestoreServiceClient::ShouldTrackURLForRestore(const GURL& url) { | 93 bool ChromeTabRestoreServiceClient::ShouldTrackURLForRestore(const GURL& url) { |
| 92 return ::ShouldTrackURLForRestore(url); | 94 return ::ShouldTrackURLForRestore(url); |
| 93 } | 95 } |
| 94 | 96 |
| 95 std::string ChromeTabRestoreServiceClient::GetExtensionAppIDForWebContents( | 97 std::string ChromeTabRestoreServiceClient::GetExtensionAppIDForTab( |
| 96 content::WebContents* web_contents) { | 98 sessions::LiveTab* tab) { |
| 97 std::string extension_app_id; | 99 std::string extension_app_id; |
| 98 | 100 |
| 99 #if defined(ENABLE_EXTENSIONS) | 101 #if defined(ENABLE_EXTENSIONS) |
| 100 extensions::TabHelper* extensions_tab_helper = | 102 extensions::TabHelper* extensions_tab_helper = |
| 101 extensions::TabHelper::FromWebContents(web_contents); | 103 extensions::TabHelper::FromWebContents( |
| 104 static_cast<sessions::ContentLiveTab*>(tab)->web_contents()); |
| 102 // extensions_tab_helper is NULL in some browser tests. | 105 // extensions_tab_helper is NULL in some browser tests. |
| 103 if (extensions_tab_helper) { | 106 if (extensions_tab_helper) { |
| 104 const extensions::Extension* extension = | 107 const extensions::Extension* extension = |
| 105 extensions_tab_helper->extension_app(); | 108 extensions_tab_helper->extension_app(); |
| 106 if (extension) | 109 if (extension) |
| 107 extension_app_id = extension->id(); | 110 extension_app_id = extension->id(); |
| 108 } | 111 } |
| 109 #endif | 112 #endif |
| 110 | 113 |
| 111 return extension_app_id; | 114 return extension_app_id; |
| 112 } | 115 } |
| 113 | 116 |
| 114 scoped_ptr<sessions::TabClientData> | 117 scoped_ptr<sessions::TabClientData> |
| 115 ChromeTabRestoreServiceClient::GetTabClientDataForWebContents( | 118 ChromeTabRestoreServiceClient::GetTabClientDataForTab(sessions::LiveTab* tab) { |
| 116 content::WebContents* web_contents) { | 119 return make_scoped_ptr(new sessions::ContentTabClientData( |
| 117 return make_scoped_ptr(new sessions::ContentTabClientData(web_contents)); | 120 static_cast<sessions::ContentLiveTab*>(tab)->web_contents())); |
| 118 } | 121 } |
| 119 | 122 |
| 120 base::SequencedWorkerPool* ChromeTabRestoreServiceClient::GetBlockingPool() { | 123 base::SequencedWorkerPool* ChromeTabRestoreServiceClient::GetBlockingPool() { |
| 121 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 124 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 122 return content::BrowserThread::GetBlockingPool(); | 125 return content::BrowserThread::GetBlockingPool(); |
| 123 } | 126 } |
| 124 | 127 |
| 125 base::FilePath ChromeTabRestoreServiceClient::GetPathToSaveTo() { | 128 base::FilePath ChromeTabRestoreServiceClient::GetPathToSaveTo() { |
| 126 return profile_->GetPath(); | 129 return profile_->GetPath(); |
| 127 } | 130 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 153 DCHECK(HasLastSession()); | 156 DCHECK(HasLastSession()); |
| 154 #if defined(ENABLE_SESSION_SERVICE) | 157 #if defined(ENABLE_SESSION_SERVICE) |
| 155 SessionServiceFactory::GetForProfile(profile_) | 158 SessionServiceFactory::GetForProfile(profile_) |
| 156 ->GetLastSession(callback, tracker); | 159 ->GetLastSession(callback, tracker); |
| 157 #endif | 160 #endif |
| 158 } | 161 } |
| 159 | 162 |
| 160 void ChromeTabRestoreServiceClient::OnTabRestored(const GURL& url) { | 163 void ChromeTabRestoreServiceClient::OnTabRestored(const GURL& url) { |
| 161 RecordAppLaunch(profile_, url); | 164 RecordAppLaunch(profile_, url); |
| 162 } | 165 } |
| OLD | NEW |