Commit 9080af5f authored by Tatiana Gornak's avatar Tatiana Gornak Committed by Commit Bot

Instance ID profile service factory for ios

Bug: 801985
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I8fb33bc8db8e1add26c630d1a8e1c66bfb4fd265
Reviewed-on: https://chromium-review.googlesource.com/1023419
Commit-Queue: Tatiana Gornak <melandory@chromium.org>
Reviewed-by: default avatarFilip Gorski <fgorski@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#554397}
parent 2a40a234
# Copyright 2018 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.
source_set("instance_id") {
sources = [
"ios_chrome_instance_id_profile_service_factory.cc",
"ios_chrome_instance_id_profile_service_factory.h",
]
deps = [
"//base",
"//components/gcm_driver",
"//components/keyed_service/ios",
"//ios/chrome/browser/browser_state:browser_state",
"//ios/chrome/browser/services/gcm",
"//ios/web",
]
}
// Copyright 2018 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 "ios/chrome/browser/services/gcm/instance_id/ios_chrome_instance_id_profile_service_factory.h"
#include "base/memory/ptr_util.h"
#include "base/memory/singleton.h"
#include "components/gcm_driver/gcm_profile_service.h"
#include "components/gcm_driver/instance_id/instance_id_profile_service.h"
#include "components/keyed_service/ios/browser_state_dependency_manager.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/services/gcm/ios_chrome_gcm_profile_service_factory.h"
// static
instance_id::InstanceIDProfileService*
IOSChromeInstanceIDProfileServiceFactory::GetForBrowserState(
ios::ChromeBrowserState* browser_state) {
return static_cast<instance_id::InstanceIDProfileService*>(
GetInstance()->GetServiceForBrowserState(browser_state, true));
}
// static
IOSChromeInstanceIDProfileServiceFactory*
IOSChromeInstanceIDProfileServiceFactory::GetInstance() {
return base::Singleton<IOSChromeInstanceIDProfileServiceFactory>::get();
}
IOSChromeInstanceIDProfileServiceFactory::
IOSChromeInstanceIDProfileServiceFactory()
: BrowserStateKeyedServiceFactory(
"InstanceIDProfileService",
BrowserStateDependencyManager::GetInstance()) {
DependsOn(IOSChromeGCMProfileServiceFactory::GetInstance());
}
IOSChromeInstanceIDProfileServiceFactory::
~IOSChromeInstanceIDProfileServiceFactory() {}
std::unique_ptr<KeyedService>
IOSChromeInstanceIDProfileServiceFactory::BuildServiceInstanceFor(
web::BrowserState* context) const {
DCHECK(!context->IsOffTheRecord());
ios::ChromeBrowserState* browser_state =
ios::ChromeBrowserState::FromBrowserState(context);
return std::make_unique<instance_id::InstanceIDProfileService>(
IOSChromeGCMProfileServiceFactory::GetForBrowserState(browser_state)
->driver(),
browser_state->IsOffTheRecord());
}
// Copyright 2018 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.
#ifndef IOS_CHROME_BROWSER_SERVICES_GCM_INSTANCE_ID_IOS_CHROME_INSTANCE_ID_PROFILE_SERVICE_FACTORY_H_
#define IOS_CHROME_BROWSER_SERVICES_GCM_INSTANCE_ID_IOS_CHROME_INSTANCE_ID_PROFILE_SERVICE_FACTORY_H_
#include <memory>
#include "base/macros.h"
#include "components/keyed_service/ios/browser_state_keyed_service_factory.h"
namespace base {
template <typename T>
struct DefaultSingletonTraits;
}
namespace instance_id {
class InstanceIDProfileService;
}
namespace ios {
class ChromeBrowserState;
}
// Singleton that owns all InstanceIDProfileService and associates them with
// ios::ChromeBrowserState.
class IOSChromeInstanceIDProfileServiceFactory
: public BrowserStateKeyedServiceFactory {
public:
static instance_id::InstanceIDProfileService* GetForBrowserState(
ios::ChromeBrowserState* browser_state);
static IOSChromeInstanceIDProfileServiceFactory* GetInstance();
private:
friend struct base::DefaultSingletonTraits<
IOSChromeInstanceIDProfileServiceFactory>;
IOSChromeInstanceIDProfileServiceFactory();
~IOSChromeInstanceIDProfileServiceFactory() override;
// BrowserStateKeyedServiceFactory:
std::unique_ptr<KeyedService> BuildServiceInstanceFor(
web::BrowserState* context) const override;
DISALLOW_COPY_AND_ASSIGN(IOSChromeInstanceIDProfileServiceFactory);
};
#endif // IOS_CHROME_BROWSER_SERVICES_GCM_INSTANCE_ID_IOS_CHROME_INSTANCE_ID_PROFILE_SERVICE_FACTORY_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment