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 "base/files/file_path.h"
9 #include "base/lazy_instance.h"
10 #include "base/logging.h"
11 #include "chrome/browser/extensions/component_loader.h"
12 #include "chrome/browser/extensions/extension_service.h"
13 #include "chrome/common/chrome_constants.h"
14 #include "chrome/common/chrome_switches.h"
15 #include "chrome/common/url_constants.h"
16 #include "content/public/browser/browser_context.h"
17 #include "content/public/browser/browser_thread.h"
18 #include "content/public/browser/storage_partition.h"
19 #include "extensions/browser/extension_system.h"
20 #include "grit/browser_resources.h"
22 #if defined(OS_CHROMEOS)
23 #include "chrome/browser/chromeos/system/input_device_settings.h"
26 using content::BrowserContext
;
27 using content::BrowserThread
;
31 extensions::ComponentLoader
* GetComponentLoader(BrowserContext
* context
) {
32 extensions::ExtensionSystem
* extension_system
=
33 extensions::ExtensionSystem::Get(context
);
34 ExtensionService
* extension_service
= extension_system
->extension_service();
35 return extension_service
->component_loader();
38 void LoadGaiaAuthExtension(BrowserContext
* context
) {
39 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
41 extensions::ComponentLoader
* component_loader
= GetComponentLoader(context
);
42 const CommandLine
* command_line
= CommandLine::ForCurrentProcess();
43 if (command_line
->HasSwitch(switches::kAuthExtensionPath
)) {
44 base::FilePath auth_extension_path
=
45 command_line
->GetSwitchValuePath(switches::kAuthExtensionPath
);
46 component_loader
->Add(IDR_GAIA_AUTH_MANIFEST
, auth_extension_path
);
50 int manifest_resource_id
= IDR_GAIA_AUTH_MANIFEST
;
52 #if defined(OS_CHROMEOS)
53 if (chromeos::system::InputDeviceSettings::Get()
54 ->ForceKeyboardDrivenUINavigation()) {
55 manifest_resource_id
= IDR_GAIA_AUTH_KEYBOARD_MANIFEST
;
59 component_loader
->Add(manifest_resource_id
,
60 base::FilePath(FILE_PATH_LITERAL("gaia_auth")));
63 void UnloadGaiaAuthExtension(BrowserContext
* context
) {
64 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
66 content::StoragePartition
* partition
=
67 content::BrowserContext::GetStoragePartitionForSite(
68 context
, GURL(chrome::kChromeUIChromeSigninURL
));
71 content::StoragePartition::REMOVE_DATA_MASK_ALL
,
72 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL
,
74 content::StoragePartition::OriginMatcherFunction(),
77 base::Bind(&base::DoNothing
));
80 const char kGaiaAuthId
[] = "mfffpogegjflfpflabcdkioaeobkgjik";
81 GetComponentLoader(context
)->Remove(kGaiaAuthId
);
86 namespace extensions
{
88 GaiaAuthExtensionLoader::GaiaAuthExtensionLoader(BrowserContext
* context
)
89 : browser_context_(context
), load_count_(0) {}
91 GaiaAuthExtensionLoader::~GaiaAuthExtensionLoader() {
92 DCHECK_EQ(0, load_count_
);
95 void GaiaAuthExtensionLoader::LoadIfNeeded() {
97 LoadGaiaAuthExtension(browser_context_
);
101 void GaiaAuthExtensionLoader::UnloadIfNeeded() {
103 if (load_count_
== 0)
104 UnloadGaiaAuthExtension(browser_context_
);
107 void GaiaAuthExtensionLoader::Shutdown() {
108 if (load_count_
> 0) {
109 UnloadGaiaAuthExtension(browser_context_
);
115 GaiaAuthExtensionLoader
* GaiaAuthExtensionLoader::Get(BrowserContext
* context
) {
116 return BrowserContextKeyedAPIFactory
<GaiaAuthExtensionLoader
>::Get(context
);
119 static base::LazyInstance
<
120 BrowserContextKeyedAPIFactory
<GaiaAuthExtensionLoader
> > g_factory
=
121 LAZY_INSTANCE_INITIALIZER
;
124 BrowserContextKeyedAPIFactory
<GaiaAuthExtensionLoader
>*
125 GaiaAuthExtensionLoader::GetFactoryInstance() {
126 return g_factory
.Pointer();
129 } // namespace extensions