| // Copyright 2020 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #include "chrome/browser/sessions/session_tab_helper.h" |
| |
| #if BUILDFLAG(ENABLE_SESSION_SERVICE) |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/sessions/session_service.h" |
| #include "chrome/browser/sessions/session_service_factory.h" |
| #include "content/public/browser/web_contents.h" |
| #endif |
| |
| namespace { |
| |
| #if BUILDFLAG(ENABLE_SESSION_SERVICE) |
| SessionService* GetSessionService(content::WebContents* web_contents) { |
| return SessionServiceFactory::GetForProfile( |
| Profile::FromBrowserContext(web_contents->GetBrowserContext())); |
| } |
| #endif |
| |
| } // namespace |
| |
| void CreateSessionServiceTabHelper(content::WebContents* contents) { |
| if (SessionTabHelper::FromWebContents(contents)) |
| return; |
| |
| #if BUILDFLAG(ENABLE_SESSION_SERVICE) |
| SessionTabHelper::SessionServiceLookup lookup = |
| base::BindRepeating(&GetSessionService); |
| #else |
| SessionTabHelper::SessionServiceLookup lookup; |
| #endif |
| SessionTabHelper::CreateForWebContents(contents, std::move(lookup)); |
| } |