1a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 2a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// found in the LICENSE file. 4a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 5a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/browser/signin/signin_global_error_factory.h" 6a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 7a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/browser/browser_process.h" 8a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/browser/profiles/profile.h" 9a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 10a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/browser/signin/signin_global_error.h" 11a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/browser/ui/global_error/global_error_service_factory.h" 12a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "components/keyed_service/content/browser_context_dependency_manager.h" 13effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "components/signin/core/browser/profile_oauth2_token_service.h" 14a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 15a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#if defined(USE_ASH) 16a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ash/shell.h" 17a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#endif 18a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 19a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)SigninGlobalErrorFactory::SigninGlobalErrorFactory() 20a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) : BrowserContextKeyedServiceFactory( 21a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) "SigninGlobalError", 22a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) BrowserContextDependencyManager::GetInstance()) { 23a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); 24a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) DependsOn(GlobalErrorServiceFactory::GetInstance()); 25a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 26a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 27a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)SigninGlobalErrorFactory::~SigninGlobalErrorFactory() {} 28a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 29a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// static 30a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)SigninGlobalError* SigninGlobalErrorFactory::GetForProfile( 31a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Profile* profile) { 32a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return static_cast<SigninGlobalError*>( 33a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GetInstance()->GetServiceForBrowserContext(profile, true)); 34a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 35a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 36a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// static 37a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)SigninGlobalErrorFactory* SigninGlobalErrorFactory::GetInstance() { 38a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return Singleton<SigninGlobalErrorFactory>::get(); 39a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 40a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 41a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)KeyedService* SigninGlobalErrorFactory::BuildServiceInstanceFor( 42a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) content::BrowserContext* context) const { 43a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#if defined(USE_ASH) 44a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (ash::Shell::HasInstance()) 45a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return NULL; 46a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#endif 47a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 48a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Profile* profile = static_cast<Profile*>(context); 49a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 50a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) SigninErrorController* controller = 51a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ProfileOAuth2TokenServiceFactory::GetForProfile(profile)-> 52a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) signin_error_controller(); 53a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 54a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return new SigninGlobalError(controller, profile); 55a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 56