1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/gcm/instance_id/instance_id_profile_service_factory.h"
#include <memory>
#include "chrome/browser/gcm/gcm_profile_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "components/gcm_driver/gcm_profile_service.h"
#include "components/gcm_driver/instance_id/instance_id_profile_service.h"
namespace instance_id {
// static
InstanceIDProfileService* InstanceIDProfileServiceFactory::GetForProfile(
content::BrowserContext* profile) {
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
// On desktop, the guest profile is actually the primary OTR profile of
// the "regular" guest profile. The regular guest profile is never used
// directly by users. Also, user are not able to create child OTR profiles
// from guest profiles, the menu item "New incognito window" is not
// available. So, if this is a guest session, allow it only if it is a
// child OTR profile as well.
bool is_profile_supported =
!Profile::FromBrowserContext(profile)->IsIncognitoProfile();
#else
bool is_profile_supported = !profile->IsOffTheRecord();
#endif
// Instance ID is not supported in incognito mode.
if (!is_profile_supported) {
return nullptr;
}
return static_cast<InstanceIDProfileService*>(
GetInstance()->GetServiceForBrowserContext(profile, true));
}
// static
InstanceIDProfileServiceFactory*
InstanceIDProfileServiceFactory::GetInstance() {
static base::NoDestructor<InstanceIDProfileServiceFactory> instance;
return instance.get();
}
InstanceIDProfileServiceFactory::InstanceIDProfileServiceFactory()
: ProfileKeyedServiceFactory(
"InstanceIDProfileService",
ProfileSelections::Builder()
.WithRegular(ProfileSelection::kOwnInstance)
.WithGuest(ProfileSelection::kOwnInstance)
// TODO(crbug.com/41488885): Check if this service is needed for
// Ash Internals.
.WithAshInternals(ProfileSelection::kOwnInstance)
.Build()) {
// GCM is needed for device ID.
DependsOn(gcm::GCMProfileServiceFactory::GetInstance());
}
InstanceIDProfileServiceFactory::~InstanceIDProfileServiceFactory() = default;
std::unique_ptr<KeyedService>
InstanceIDProfileServiceFactory::BuildServiceInstanceForBrowserContext(
content::BrowserContext* context) const {
Profile* profile = Profile::FromBrowserContext(context);
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
// On desktop, incognito profiles are checked with IsIncognitoProfile().
// It's possible for non-incognito profiles to also be off-the-record.
bool is_incognito = profile->IsIncognitoProfile();
#else
bool is_incognito = profile->IsOffTheRecord();
#endif
return std::make_unique<InstanceIDProfileService>(
gcm::GCMProfileServiceFactory::GetForProfile(profile)->driver(),
is_incognito);
}
} // namespace instance_id
|