blob: 8eeb5e2223990e70e084273293a4543790f011d1 [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
Melissa Zhang59ca374f2020-07-22 05:55:519#include "chrome/browser/apps/app_service/app_service_proxy_factory.h"
Melissa Zhangff2bca982020-06-24 02:54:4810#include "chrome/browser/profiles/incognito_helpers.h"
11#include "chrome/browser/profiles/profile.h"
12#include "chrome/browser/sharesheet/sharesheet_service.h"
13#include "components/keyed_service/content/browser_context_dependency_manager.h"
14
15#if defined(OS_CHROMEOS)
16#include "chrome/browser/chromeos/profiles/profile_helper.h"
17#endif // OS_CHROMEOS
18
19namespace sharesheet {
20
21// static
22SharesheetService* SharesheetServiceFactory::GetForProfile(Profile* profile) {
Melissa Zhangff2bca982020-06-24 02:54:4823 return static_cast<SharesheetService*>(
24 SharesheetServiceFactory::GetInstance()->GetServiceForBrowserContext(
25 profile, true /* create */));
26}
27
28// static
29SharesheetServiceFactory* SharesheetServiceFactory::GetInstance() {
30 return base::Singleton<SharesheetServiceFactory>::get();
31}
32
33SharesheetServiceFactory::SharesheetServiceFactory()
34 : BrowserContextKeyedServiceFactory(
35 "SharesheetService",
Melissa Zhang59ca374f2020-07-22 05:55:5136 BrowserContextDependencyManager::GetInstance()) {
37 DependsOn(apps::AppServiceProxyFactory::GetInstance());
38}
Melissa Zhangff2bca982020-06-24 02:54:4839
40SharesheetServiceFactory::~SharesheetServiceFactory() = default;
41
42KeyedService* SharesheetServiceFactory::BuildServiceInstanceFor(
43 content::BrowserContext* context) const {
44 return new SharesheetService(Profile::FromBrowserContext(context));
45}
46
47content::BrowserContext* SharesheetServiceFactory::GetBrowserContextToUse(
48 content::BrowserContext* context) const {
49 Profile* const profile = Profile::FromBrowserContext(context);
50 if (!profile || profile->IsSystemProfile()) {
51 return nullptr;
52 }
53
54#if defined(OS_CHROMEOS)
55 if (chromeos::ProfileHelper::IsSigninProfile(profile)) {
56 return nullptr;
57 }
58
Melissa Zhang52cbd3b62020-10-21 00:13:3459 // We allow sharing in guest mode or incognito mode..
Melissa Zhangff2bca982020-06-24 02:54:4860 if (profile->IsGuestSession()) {
61 return chrome::GetBrowserContextOwnInstanceInIncognito(context);
62 }
63#endif // OS_CHROMEOS
64
Melissa Zhang52cbd3b62020-10-21 00:13:3465 return chrome::GetBrowserContextRedirectedInIncognito(context);
Melissa Zhangff2bca982020-06-24 02:54:4866}
67
68bool SharesheetServiceFactory::ServiceIsCreatedWithBrowserContext() const {
69 return true;
70}
71
72} // namespace sharesheet