chrome_ssl_host_state_delegate_factory.cc revision 5f1c94371a64b3196d4be9466099bb892df9b88e
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.
4
5#include "chrome/browser/ssl/chrome_ssl_host_state_delegate_factory.h"
6
7#include "base/memory/scoped_ptr.h"
8#include "chrome/browser/profiles/incognito_helpers.h"
9#include "chrome/browser/profiles/profile.h"
10#include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h"
11#include "components/keyed_service/content/browser_context_dependency_manager.h"
12#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
13
14namespace {
15
16class Service : public KeyedService {
17 public:
18  explicit Service(Profile* profile)
19      : decisions_(new ChromeSSLHostStateDelegate(profile)) {}
20
21  ChromeSSLHostStateDelegate* decisions() { return decisions_.get(); }
22
23  virtual void Shutdown() OVERRIDE { decisions_->ShutdownOnUIThread(); }
24
25 private:
26  scoped_ptr<ChromeSSLHostStateDelegate> decisions_;
27
28  DISALLOW_COPY_AND_ASSIGN(Service);
29};
30
31}  // namespace
32
33// static
34ChromeSSLHostStateDelegate* ChromeSSLHostStateDelegateFactory::GetForProfile(
35    Profile* profile) {
36  return static_cast<Service*>(GetInstance()->GetServiceForBrowserContext(
37                                   profile, true))->decisions();
38}
39
40// static
41ChromeSSLHostStateDelegateFactory*
42ChromeSSLHostStateDelegateFactory::GetInstance() {
43  return Singleton<ChromeSSLHostStateDelegateFactory>::get();
44}
45
46ChromeSSLHostStateDelegateFactory::ChromeSSLHostStateDelegateFactory()
47    : BrowserContextKeyedServiceFactory(
48          "ChromeSSLHostStateDelegate",
49          BrowserContextDependencyManager::GetInstance()) {
50}
51
52ChromeSSLHostStateDelegateFactory::~ChromeSSLHostStateDelegateFactory() {
53}
54
55KeyedService* ChromeSSLHostStateDelegateFactory::BuildServiceInstanceFor(
56    content::BrowserContext* profile) const {
57  return new Service(static_cast<Profile*>(profile));
58}
59
60void ChromeSSLHostStateDelegateFactory::RegisterProfilePrefs(
61    user_prefs::PrefRegistrySyncable* registry) {
62}
63
64content::BrowserContext*
65ChromeSSLHostStateDelegateFactory::GetBrowserContextToUse(
66    content::BrowserContext* context) const {
67  return chrome::GetBrowserContextOwnInstanceInIncognito(context);
68}
69