blob: 769287690fdc4322d40fcb4e2b11a6a2040c1940 [file] [log] [blame]
Melissa Zhangff2bca982020-06-24 02:54:481// Copyright 2020 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/sharesheet/sharesheet_service_factory.h"
6
7#include <memory>
8
Yuta Hijikata235fc62b2020-12-08 03:48:329#include "build/chromeos_buildflags.h"
Melissa Zhang59ca374f2020-07-22 05:55:5110#include "chrome/browser/apps/app_service/app_service_proxy_factory.h"
Melissa Zhangff2bca982020-06-24 02:54:4811#include "chrome/browser/profiles/incognito_helpers.h"
12#include "chrome/browser/profiles/profile.h"
13#include "chrome/browser/sharesheet/sharesheet_service.h"
14#include "components/keyed_service/content/browser_context_dependency_manager.h"
15
Yuta Hijikata235fc62b2020-12-08 03:48:3216#if BUILDFLAG(IS_CHROMEOS_ASH)
Yeunjoo Choi15ab1ac2021-02-04 17:15:0717#include "chrome/browser/ash/profiles/profile_helper.h"
Yuta Hijikata235fc62b2020-12-08 03:48:3218#endif // BUILDFLAG(IS_CHROMEOS_ASH)
Melissa Zhangff2bca982020-06-24 02:54:4819
20namespace sharesheet {
21
22// static
23SharesheetService* SharesheetServiceFactory::GetForProfile(Profile* profile) {
Melissa Zhangff2bca982020-06-24 02:54:4824 return static_cast<SharesheetService*>(
25 SharesheetServiceFactory::GetInstance()->GetServiceForBrowserContext(
26 profile, true /* create */));
27}
28
29// static
30SharesheetServiceFactory* SharesheetServiceFactory::GetInstance() {
31 return base::Singleton<SharesheetServiceFactory>::get();
32}
33
34SharesheetServiceFactory::SharesheetServiceFactory()
35 : BrowserContextKeyedServiceFactory(
36 "SharesheetService",
Melissa Zhang59ca374f2020-07-22 05:55:5137 BrowserContextDependencyManager::GetInstance()) {
38 DependsOn(apps::AppServiceProxyFactory::GetInstance());
39}
Melissa Zhangff2bca982020-06-24 02:54:4840
41SharesheetServiceFactory::~SharesheetServiceFactory() = default;
42
43KeyedService* SharesheetServiceFactory::BuildServiceInstanceFor(
44 content::BrowserContext* context) const {
45 return new SharesheetService(Profile::FromBrowserContext(context));
46}
47
48content::BrowserContext* SharesheetServiceFactory::GetBrowserContextToUse(
49 content::BrowserContext* context) const {
50 Profile* const profile = Profile::FromBrowserContext(context);
51 if (!profile || profile->IsSystemProfile()) {
52 return nullptr;
53 }
54
Yuta Hijikata235fc62b2020-12-08 03:48:3255#if BUILDFLAG(IS_CHROMEOS_ASH)
Yeunjoo Choi36f21d542022-01-13 03:12:3356 if (ash::ProfileHelper::IsSigninProfile(profile)) {
Melissa Zhangff2bca982020-06-24 02:54:4857 return nullptr;
58 }
59
Melissa Zhang52cbd3b62020-10-21 00:13:3460 // We allow sharing in guest mode or incognito mode..
Melissa Zhangff2bca982020-06-24 02:54:4861 if (profile->IsGuestSession()) {
62 return chrome::GetBrowserContextOwnInstanceInIncognito(context);
63 }
Yuta Hijikata235fc62b2020-12-08 03:48:3264#endif // BUILDFLAG(IS_CHROMEOS_ASH)
Melissa Zhangff2bca982020-06-24 02:54:4865
Melissa Zhang52cbd3b62020-10-21 00:13:3466 return chrome::GetBrowserContextRedirectedInIncognito(context);
Melissa Zhangff2bca982020-06-24 02:54:4867}
68
69bool SharesheetServiceFactory::ServiceIsCreatedWithBrowserContext() const {
70 return true;
71}
72
73} // namespace sharesheet