PageRenderTime 51ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/chrome/browser/signin/easy_unlock_service_factory.cc

https://gitlab.com/jonnialva90/iridium-browser
C++ | 134 lines | 103 code | 21 blank | 10 comment | 5 complexity | 4ba1bec2b3c3c4239b1dd978e21d5072 MD5 | raw file
  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. #include "chrome/browser/signin/easy_unlock_service_factory.h"
  5. #include "base/command_line.h"
  6. #include "base/memory/singleton.h"
  7. #include "chrome/browser/profiles/incognito_helpers.h"
  8. #include "chrome/browser/profiles/profile.h"
  9. #include "chrome/browser/services/gcm/gcm_profile_service_factory.h"
  10. #include "chrome/browser/signin/easy_unlock_app_manager.h"
  11. #include "chrome/browser/signin/easy_unlock_service.h"
  12. #include "chrome/browser/signin/easy_unlock_service_regular.h"
  13. #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
  14. #include "chrome/browser/signin/signin_manager_factory.h"
  15. #include "chrome/common/chrome_switches.h"
  16. #include "components/keyed_service/content/browser_context_dependency_manager.h"
  17. #include "extensions/browser/extension_system.h"
  18. #include "extensions/browser/extension_system_provider.h"
  19. #include "extensions/browser/extensions_browser_client.h"
  20. #include "grit/browser_resources.h"
  21. #if defined(OS_CHROMEOS)
  22. #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager_factory.h"
  23. #include "chrome/browser/chromeos/profiles/profile_helper.h"
  24. #include "chrome/browser/signin/easy_unlock_service_signin_chromeos.h"
  25. #endif
  26. namespace {
  27. // Gets the file path from which easy unlock app should be loaded.
  28. base::FilePath GetEasyUnlockAppPath() {
  29. #if defined(GOOGLE_CHROME_BUILD)
  30. #ifndef NDEBUG
  31. // Only allow app path override switch for debug build.
  32. const base::CommandLine* command_line =
  33. base::CommandLine::ForCurrentProcess();
  34. if (command_line->HasSwitch(switches::kEasyUnlockAppPath))
  35. return command_line->GetSwitchValuePath(switches::kEasyUnlockAppPath);
  36. #endif // !defined(NDEBUG)
  37. #if defined(OS_CHROMEOS)
  38. return base::FilePath("/usr/share/chromeos-assets/easy_unlock");
  39. #endif // defined(OS_CHROMEOS)
  40. #endif // defined(GOOGLE_CHROME_BUILD)
  41. return base::FilePath();
  42. }
  43. } // namespace
  44. // static
  45. EasyUnlockServiceFactory* EasyUnlockServiceFactory::GetInstance() {
  46. return base::Singleton<EasyUnlockServiceFactory>::get();
  47. }
  48. // static
  49. EasyUnlockService* EasyUnlockServiceFactory::GetForBrowserContext(
  50. content::BrowserContext* browser_context) {
  51. return static_cast<EasyUnlockService*>(
  52. EasyUnlockServiceFactory::GetInstance()->GetServiceForBrowserContext(
  53. browser_context, true));
  54. }
  55. EasyUnlockServiceFactory::EasyUnlockServiceFactory()
  56. : BrowserContextKeyedServiceFactory(
  57. "EasyUnlockService",
  58. BrowserContextDependencyManager::GetInstance()) {
  59. DependsOn(
  60. extensions::ExtensionsBrowserClient::Get()->GetExtensionSystemFactory());
  61. DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance());
  62. DependsOn(SigninManagerFactory::GetInstance());
  63. DependsOn(gcm::GCMProfileServiceFactory::GetInstance());
  64. #if defined(OS_CHROMEOS)
  65. DependsOn(EasyUnlockTpmKeyManagerFactory::GetInstance());
  66. #endif
  67. }
  68. EasyUnlockServiceFactory::~EasyUnlockServiceFactory() {
  69. }
  70. KeyedService* EasyUnlockServiceFactory::BuildServiceInstanceFor(
  71. content::BrowserContext* context) const {
  72. EasyUnlockService* service = NULL;
  73. int manifest_id = 0;
  74. #if defined(OS_CHROMEOS)
  75. if (chromeos::ProfileHelper::IsSigninProfile(
  76. Profile::FromBrowserContext(context))) {
  77. if (!context->IsOffTheRecord())
  78. return NULL;
  79. service = new EasyUnlockServiceSignin(Profile::FromBrowserContext(context));
  80. manifest_id = IDR_EASY_UNLOCK_MANIFEST_SIGNIN;
  81. }
  82. #endif
  83. if (!service) {
  84. service =
  85. new EasyUnlockServiceRegular(Profile::FromBrowserContext(context));
  86. manifest_id = IDR_EASY_UNLOCK_MANIFEST;
  87. }
  88. const base::FilePath app_path = app_path_for_testing_.empty()
  89. ? GetEasyUnlockAppPath()
  90. : app_path_for_testing_;
  91. service->Initialize(EasyUnlockAppManager::Create(
  92. extensions::ExtensionSystem::Get(context), manifest_id, app_path));
  93. return service;
  94. }
  95. content::BrowserContext* EasyUnlockServiceFactory::GetBrowserContextToUse(
  96. content::BrowserContext* context) const {
  97. #if defined(OS_CHROMEOS)
  98. if (chromeos::ProfileHelper::IsSigninProfile(
  99. Profile::FromBrowserContext(context))) {
  100. return chrome::GetBrowserContextOwnInstanceInIncognito(context);
  101. }
  102. #endif
  103. return chrome::GetBrowserContextRedirectedInIncognito(context);
  104. }
  105. bool EasyUnlockServiceFactory::ServiceIsCreatedWithBrowserContext() const {
  106. return true;
  107. }
  108. bool EasyUnlockServiceFactory::ServiceIsNULLWhileTesting() const {
  109. // Don't create the service for TestingProfile used in unit_tests because
  110. // EasyUnlockService uses ExtensionSystem::ready().Post, which expects
  111. // a MessageLoop that does not exit in many unit_tests cases.
  112. return true;
  113. }