Only send _NET_ACTIVE_WINDOW hint if the chromium window is not already active.
[chromium-blink-merge.git] / components / keyed_service / ios / refcounted_browser_state_keyed_service_factory.cc
blob3de6b2f8e2129c5a0797c9795bfcf71b82ad09ab
1 // Copyright 2014 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.
5 #include "components/keyed_service/ios/refcounted_browser_state_keyed_service_factory.h"
7 #include "base/logging.h"
8 #include "components/keyed_service/core/refcounted_keyed_service.h"
9 #include "components/keyed_service/ios/browser_state_context_converter.h"
10 #include "components/keyed_service/ios/browser_state_dependency_manager.h"
11 #include "ios/web/public/browser_state.h"
13 void RefcountedBrowserStateKeyedServiceFactory::SetTestingFactory(
14 web::BrowserState* context,
15 TestingFactoryFunction testing_factory) {
16 RefcountedKeyedServiceFactory::SetTestingFactory(
17 context,
18 reinterpret_cast<RefcountedKeyedServiceFactory::TestingFactoryFunction>(
19 testing_factory));
22 scoped_refptr<RefcountedKeyedService>
23 RefcountedBrowserStateKeyedServiceFactory::SetTestingFactoryAndUse(
24 web::BrowserState* context,
25 TestingFactoryFunction testing_factory) {
26 return RefcountedKeyedServiceFactory::SetTestingFactoryAndUse(
27 context,
28 reinterpret_cast<RefcountedKeyedServiceFactory::TestingFactoryFunction>(
29 testing_factory));
32 RefcountedBrowserStateKeyedServiceFactory::
33 RefcountedBrowserStateKeyedServiceFactory(
34 const char* name,
35 /*BrowserState*/DependencyManager* manager)
36 : RefcountedKeyedServiceFactory(name, manager) {
39 RefcountedBrowserStateKeyedServiceFactory::
40 ~RefcountedBrowserStateKeyedServiceFactory() {
43 scoped_refptr<RefcountedKeyedService>
44 RefcountedBrowserStateKeyedServiceFactory::GetServiceForBrowserState(
45 web::BrowserState* context,
46 bool create) {
47 return RefcountedKeyedServiceFactory::GetServiceForContext(context, create);
50 web::BrowserState*
51 RefcountedBrowserStateKeyedServiceFactory::GetBrowserStateToUse(
52 web::BrowserState* context) const {
53 DCHECK(CalledOnValidThread());
55 #ifndef NDEBUG
56 AssertContextWasntDestroyed(context);
57 #endif
59 // Safe default for Incognito mode: no service.
60 if (context->IsOffTheRecord())
61 return nullptr;
63 return context;
66 bool RefcountedBrowserStateKeyedServiceFactory::
67 ServiceIsCreatedWithBrowserState() const {
68 return KeyedServiceBaseFactory::ServiceIsCreatedWithContext();
71 bool RefcountedBrowserStateKeyedServiceFactory::ServiceIsNULLWhileTesting()
72 const {
73 return KeyedServiceBaseFactory::ServiceIsNULLWhileTesting();
76 void RefcountedBrowserStateKeyedServiceFactory::BrowserStateShutdown(
77 web::BrowserState* context) {
78 RefcountedKeyedServiceFactory::ContextShutdown(context);
81 void RefcountedBrowserStateKeyedServiceFactory::BrowserStateDestroyed(
82 web::BrowserState* context) {
83 RefcountedKeyedServiceFactory::ContextDestroyed(context);
86 scoped_refptr<RefcountedKeyedService>
87 RefcountedBrowserStateKeyedServiceFactory::BuildServiceInstanceFor(
88 base::SupportsUserData* context) const {
89 return BuildServiceInstanceFor(static_cast<web::BrowserState*>(context));
92 bool RefcountedBrowserStateKeyedServiceFactory::IsOffTheRecord(
93 base::SupportsUserData* context) const {
94 return static_cast<web::BrowserState*>(context)->IsOffTheRecord();
97 #if defined(OS_IOS)
98 base::SupportsUserData*
99 RefcountedBrowserStateKeyedServiceFactory::GetTypedContext(
100 base::SupportsUserData* context) const {
101 if (context) {
102 BrowserStateContextConverter* context_converter =
103 BrowserStateContextConverter::GetInstance();
104 if (context_converter) {
105 context = context_converter->GetBrowserStateForContext(context);
106 DCHECK(context);
109 return context;
112 base::SupportsUserData*
113 RefcountedBrowserStateKeyedServiceFactory::GetContextForDependencyManager(
114 base::SupportsUserData* context) const {
115 if (context) {
116 BrowserStateContextConverter* context_converter =
117 BrowserStateContextConverter::GetInstance();
118 if (context_converter) {
119 context = context_converter->GetBrowserContextForContext(context);
120 DCHECK(context);
123 return context;
125 #endif // defined(OS_IOS)
127 base::SupportsUserData*
128 RefcountedBrowserStateKeyedServiceFactory::GetContextToUse(
129 base::SupportsUserData* context) const {
130 return GetBrowserStateToUse(static_cast<web::BrowserState*>(context));
133 bool RefcountedBrowserStateKeyedServiceFactory::ServiceIsCreatedWithContext()
134 const {
135 return ServiceIsCreatedWithBrowserState();
138 void RefcountedBrowserStateKeyedServiceFactory::ContextShutdown(
139 base::SupportsUserData* context) {
140 BrowserStateShutdown(static_cast<web::BrowserState*>(context));
143 void RefcountedBrowserStateKeyedServiceFactory::ContextDestroyed(
144 base::SupportsUserData* context) {
145 BrowserStateDestroyed(static_cast<web::BrowserState*>(context));
148 void RefcountedBrowserStateKeyedServiceFactory::RegisterPrefs(
149 user_prefs::PrefRegistrySyncable* registry) {
150 RegisterBrowserStatePrefs(registry);