1 // Copyright 2013 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 "chrome/browser/extensions/signin/gaia_auth_extension_loader.h"
7 #include "base/command_line.h"
8 #include "chrome/browser/extensions/component_loader.h"
9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/extensions/extension_system.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/common/chrome_constants.h"
13 #include "chrome/common/chrome_switches.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "grit/browser_resources.h"
17 #if defined(OS_CHROMEOS)
18 #include "chrome/browser/chromeos/system/input_device_settings.h"
19 #include "chromeos/chromeos_constants.h"
20 #include "chromeos/chromeos_switches.h"
23 using content::BrowserThread
;
27 extensions::ComponentLoader
* GetComponentLoader(Profile
* profile
) {
28 extensions::ExtensionSystem
* extension_system
=
29 extensions::ExtensionSystem::Get(profile
);
30 ExtensionService
* extension_service
= extension_system
->extension_service();
31 return extension_service
->component_loader();
34 void LoadGaiaAuthExtension(Profile
* profile
) {
35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
37 extensions::ComponentLoader
* component_loader
= GetComponentLoader(profile
);
38 const CommandLine
* command_line
= CommandLine::ForCurrentProcess();
39 if (command_line
->HasSwitch(switches::kAuthExtensionPath
)) {
40 base::FilePath auth_extension_path
=
41 command_line
->GetSwitchValuePath(switches::kAuthExtensionPath
);
42 component_loader
->Add(IDR_GAIA_AUTH_MANIFEST
, auth_extension_path
);
46 int manifest_resource_id
= IDR_GAIA_AUTH_MANIFEST
;
48 #if defined(OS_CHROMEOS)
49 if (chromeos::system::keyboard_settings::ForceKeyboardDrivenUINavigation())
50 manifest_resource_id
= IDR_GAIA_AUTH_KEYBOARD_MANIFEST
;
51 else if (command_line
->HasSwitch(chromeos::switches::kEnableSamlSignin
))
52 manifest_resource_id
= IDR_GAIA_AUTH_SAML_MANIFEST
;
54 manifest_resource_id
= IDR_GAIA_AUTH_INLINE_MANIFEST
;
57 component_loader
->Add(manifest_resource_id
,
58 base::FilePath(FILE_PATH_LITERAL("gaia_auth")));
61 void UnloadGaiaAuthExtension(Profile
* profile
) {
62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
64 const char kGaiaAuthId
[] = "mfffpogegjflfpflabcdkioaeobkgjik";
65 GetComponentLoader(profile
)->Remove(kGaiaAuthId
);
70 namespace extensions
{
72 GaiaAuthExtensionLoader::GaiaAuthExtensionLoader(Profile
* profile
)
73 : profile_(profile
), load_count_(0) {}
75 GaiaAuthExtensionLoader::~GaiaAuthExtensionLoader() {
76 if (load_count_
> 0) {
77 UnloadGaiaAuthExtension(profile_
);
82 void GaiaAuthExtensionLoader::LoadIfNeeded() {
84 LoadGaiaAuthExtension(profile_
);
88 void GaiaAuthExtensionLoader::UnloadIfNeeded() {
91 UnloadGaiaAuthExtension(profile_
);
95 GaiaAuthExtensionLoader
* GaiaAuthExtensionLoader::Get(Profile
* profile
) {
96 return ProfileKeyedAPIFactory
<GaiaAuthExtensionLoader
>::GetForProfile(
100 static base::LazyInstance
<ProfileKeyedAPIFactory
<GaiaAuthExtensionLoader
> >
101 g_factory
= LAZY_INSTANCE_INITIALIZER
;
104 ProfileKeyedAPIFactory
<GaiaAuthExtensionLoader
>*
105 GaiaAuthExtensionLoader::GetFactoryInstance() {
106 return &g_factory
.Get();
109 } // namespace extensions