OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/signin/gaia_auth_extension_loader.h" | 5 #include "chrome/browser/extensions/signin/gaia_auth_extension_loader.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "chrome/browser/extensions/component_loader.h" | 12 #include "chrome/browser/extensions/component_loader.h" |
13 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
14 #include "chrome/browser/profiles/profile.h" | |
15 #include "chrome/common/chrome_constants.h" | 14 #include "chrome/common/chrome_constants.h" |
16 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 16 #include "content/public/browser/browser_context.h" |
17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
18 #include "extensions/browser/extension_system.h" | 18 #include "extensions/browser/extension_system.h" |
19 #include "grit/browser_resources.h" | 19 #include "grit/browser_resources.h" |
20 | 20 |
21 #if defined(OS_CHROMEOS) | 21 #if defined(OS_CHROMEOS) |
22 #include "base/file_util.h" | 22 #include "base/file_util.h" |
23 #include "chrome/browser/chromeos/system/input_device_settings.h" | 23 #include "chrome/browser/chromeos/system/input_device_settings.h" |
24 #include "chromeos/chromeos_constants.h" | 24 #include "chromeos/chromeos_constants.h" |
25 #include "chromeos/chromeos_switches.h" | 25 #include "chromeos/chromeos_switches.h" |
26 #endif | 26 #endif |
27 | 27 |
| 28 using content::BrowserContext; |
28 using content::BrowserThread; | 29 using content::BrowserThread; |
29 | 30 |
30 namespace { | 31 namespace { |
31 | 32 |
32 extensions::ComponentLoader* GetComponentLoader(Profile* profile) { | 33 extensions::ComponentLoader* GetComponentLoader(BrowserContext* context) { |
33 extensions::ExtensionSystem* extension_system = | 34 extensions::ExtensionSystem* extension_system = |
34 extensions::ExtensionSystem::Get(profile); | 35 extensions::ExtensionSystem::Get(context); |
35 ExtensionService* extension_service = extension_system->extension_service(); | 36 ExtensionService* extension_service = extension_system->extension_service(); |
36 return extension_service->component_loader(); | 37 return extension_service->component_loader(); |
37 } | 38 } |
38 | 39 |
39 void LoadGaiaAuthExtension(Profile* profile) { | 40 void LoadGaiaAuthExtension(BrowserContext* context) { |
40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
41 | 42 |
42 extensions::ComponentLoader* component_loader = GetComponentLoader(profile); | 43 extensions::ComponentLoader* component_loader = GetComponentLoader(context); |
43 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 44 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
44 if (command_line->HasSwitch(switches::kAuthExtensionPath)) { | 45 if (command_line->HasSwitch(switches::kAuthExtensionPath)) { |
45 base::FilePath auth_extension_path = | 46 base::FilePath auth_extension_path = |
46 command_line->GetSwitchValuePath(switches::kAuthExtensionPath); | 47 command_line->GetSwitchValuePath(switches::kAuthExtensionPath); |
47 component_loader->Add(IDR_GAIA_AUTH_MANIFEST, auth_extension_path); | 48 component_loader->Add(IDR_GAIA_AUTH_MANIFEST, auth_extension_path); |
48 return; | 49 return; |
49 } | 50 } |
50 | 51 |
51 #if defined(OS_CHROMEOS) | 52 #if defined(OS_CHROMEOS) |
52 if (command_line->HasSwitch(chromeos::switches::kGAIAAuthExtensionManifest)) { | 53 if (command_line->HasSwitch(chromeos::switches::kGAIAAuthExtensionManifest)) { |
(...skipping 15 matching lines...) Expand all Loading... |
68 manifest_resource_id = IDR_GAIA_AUTH_SAML_MANIFEST; | 69 manifest_resource_id = IDR_GAIA_AUTH_SAML_MANIFEST; |
69 } | 70 } |
70 #else | 71 #else |
71 int manifest_resource_id = IDR_GAIA_AUTH_DESKTOP_MANIFEST; | 72 int manifest_resource_id = IDR_GAIA_AUTH_DESKTOP_MANIFEST; |
72 #endif | 73 #endif |
73 | 74 |
74 component_loader->Add(manifest_resource_id, | 75 component_loader->Add(manifest_resource_id, |
75 base::FilePath(FILE_PATH_LITERAL("gaia_auth"))); | 76 base::FilePath(FILE_PATH_LITERAL("gaia_auth"))); |
76 } | 77 } |
77 | 78 |
78 void UnloadGaiaAuthExtension(Profile* profile) { | 79 void UnloadGaiaAuthExtension(BrowserContext* context) { |
79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
80 | 81 |
81 const char kGaiaAuthId[] = "mfffpogegjflfpflabcdkioaeobkgjik"; | 82 const char kGaiaAuthId[] = "mfffpogegjflfpflabcdkioaeobkgjik"; |
82 GetComponentLoader(profile)->Remove(kGaiaAuthId); | 83 GetComponentLoader(context)->Remove(kGaiaAuthId); |
83 } | 84 } |
84 | 85 |
85 } // namespace | 86 } // namespace |
86 | 87 |
87 namespace extensions { | 88 namespace extensions { |
88 | 89 |
89 GaiaAuthExtensionLoader::GaiaAuthExtensionLoader(Profile* profile) | 90 GaiaAuthExtensionLoader::GaiaAuthExtensionLoader(BrowserContext* context) |
90 : profile_(profile), load_count_(0) {} | 91 : browser_context_(context), load_count_(0) {} |
91 | 92 |
92 GaiaAuthExtensionLoader::~GaiaAuthExtensionLoader() { | 93 GaiaAuthExtensionLoader::~GaiaAuthExtensionLoader() { |
93 DCHECK_EQ(0, load_count_); | 94 DCHECK_EQ(0, load_count_); |
94 } | 95 } |
95 | 96 |
96 void GaiaAuthExtensionLoader::LoadIfNeeded() { | 97 void GaiaAuthExtensionLoader::LoadIfNeeded() { |
97 if (load_count_ == 0) | 98 if (load_count_ == 0) |
98 LoadGaiaAuthExtension(profile_); | 99 LoadGaiaAuthExtension(browser_context_); |
99 ++load_count_; | 100 ++load_count_; |
100 } | 101 } |
101 | 102 |
102 void GaiaAuthExtensionLoader::UnloadIfNeeded() { | 103 void GaiaAuthExtensionLoader::UnloadIfNeeded() { |
103 --load_count_; | 104 --load_count_; |
104 if (load_count_ == 0) | 105 if (load_count_ == 0) |
105 UnloadGaiaAuthExtension(profile_); | 106 UnloadGaiaAuthExtension(browser_context_); |
106 } | 107 } |
107 | 108 |
108 void GaiaAuthExtensionLoader::Shutdown() { | 109 void GaiaAuthExtensionLoader::Shutdown() { |
109 if (load_count_ > 0) { | 110 if (load_count_ > 0) { |
110 UnloadGaiaAuthExtension(profile_); | 111 UnloadGaiaAuthExtension(browser_context_); |
111 load_count_ = 0; | 112 load_count_ = 0; |
112 } | 113 } |
113 } | 114 } |
114 | 115 |
115 // static | 116 // static |
116 GaiaAuthExtensionLoader* GaiaAuthExtensionLoader::Get(Profile* profile) { | 117 GaiaAuthExtensionLoader* GaiaAuthExtensionLoader::Get(BrowserContext* context) { |
117 return ProfileKeyedAPIFactory<GaiaAuthExtensionLoader>::GetForProfile( | 118 return ProfileKeyedAPIFactory<GaiaAuthExtensionLoader>::GetForProfile( |
118 profile); | 119 context); |
119 } | 120 } |
120 | 121 |
121 static base::LazyInstance<ProfileKeyedAPIFactory<GaiaAuthExtensionLoader> > | 122 static base::LazyInstance<ProfileKeyedAPIFactory<GaiaAuthExtensionLoader> > |
122 g_factory = LAZY_INSTANCE_INITIALIZER; | 123 g_factory = LAZY_INSTANCE_INITIALIZER; |
123 | 124 |
124 // static | 125 // static |
125 ProfileKeyedAPIFactory<GaiaAuthExtensionLoader>* | 126 ProfileKeyedAPIFactory<GaiaAuthExtensionLoader>* |
126 GaiaAuthExtensionLoader::GetFactoryInstance() { | 127 GaiaAuthExtensionLoader::GetFactoryInstance() { |
127 return g_factory.Pointer(); | 128 return g_factory.Pointer(); |
128 } | 129 } |
129 | 130 |
130 } // namespace extensions | 131 } // namespace extensions |
OLD | NEW |