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/signin/signin_global_error_factory.h"
6
7#include "chrome/browser/browser_process.h"
8#include "chrome/browser/profiles/profile.h"
9#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
10#include "chrome/browser/signin/signin_global_error.h"
11#include "chrome/browser/ui/global_error/global_error_service_factory.h"
12#include "components/keyed_service/content/browser_context_dependency_manager.h"
13#include "components/signin/core/browser/profile_oauth2_token_service.h"
14
15#if defined(USE_ASH)
16#include "ash/shell.h"
17#endif
18
19SigninGlobalErrorFactory::SigninGlobalErrorFactory()
20    : BrowserContextKeyedServiceFactory(
21        "SigninGlobalError",
22        BrowserContextDependencyManager::GetInstance()) {
23  DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance());
24  DependsOn(GlobalErrorServiceFactory::GetInstance());
25}
26
27SigninGlobalErrorFactory::~SigninGlobalErrorFactory() {}
28
29// static
30SigninGlobalError* SigninGlobalErrorFactory::GetForProfile(
31    Profile* profile) {
32  return static_cast<SigninGlobalError*>(
33      GetInstance()->GetServiceForBrowserContext(profile, true));
34}
35
36// static
37SigninGlobalErrorFactory* SigninGlobalErrorFactory::GetInstance() {
38  return Singleton<SigninGlobalErrorFactory>::get();
39}
40
41KeyedService* SigninGlobalErrorFactory::BuildServiceInstanceFor(
42    content::BrowserContext* context) const {
43#if defined(USE_ASH)
44  if (ash::Shell::HasInstance())
45    return NULL;
46#endif
47
48  Profile* profile = static_cast<Profile*>(context);
49
50  SigninErrorController* controller =
51      ProfileOAuth2TokenServiceFactory::GetForProfile(profile)->
52      signin_error_controller();
53
54  return new SigninGlobalError(controller, profile);
55}
56