Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / extensions / signin / gaia_auth_extension_loader.cc
blobfdb59c287000e875d65f092fb5809519032a9984
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 "base/file_util.h"
24 #include "chrome/browser/chromeos/system/input_device_settings.h"
25 #include "chromeos/chromeos_constants.h"
26 #include "chromeos/chromeos_switches.h"
27 #endif
29 using content::BrowserContext;
30 using content::BrowserThread;
32 namespace {
34 extensions::ComponentLoader* GetComponentLoader(BrowserContext* context) {
35 extensions::ExtensionSystem* extension_system =
36 extensions::ExtensionSystem::Get(context);
37 ExtensionService* extension_service = extension_system->extension_service();
38 return extension_service->component_loader();
41 void LoadGaiaAuthExtension(BrowserContext* context) {
42 DCHECK_CURRENTLY_ON(BrowserThread::UI);
44 extensions::ComponentLoader* component_loader = GetComponentLoader(context);
45 const CommandLine* command_line = CommandLine::ForCurrentProcess();
46 if (command_line->HasSwitch(switches::kAuthExtensionPath)) {
47 base::FilePath auth_extension_path =
48 command_line->GetSwitchValuePath(switches::kAuthExtensionPath);
49 component_loader->Add(IDR_GAIA_AUTH_MANIFEST, auth_extension_path);
50 return;
53 #if defined(OS_CHROMEOS)
54 int manifest_resource_id = IDR_GAIA_AUTH_MANIFEST;
55 if (chromeos::system::InputDeviceSettings::Get()
56 ->ForceKeyboardDrivenUINavigation()) {
57 manifest_resource_id = IDR_GAIA_AUTH_KEYBOARD_MANIFEST;
58 } else if (!command_line->HasSwitch(chromeos::switches::kDisableSamlSignin)) {
59 manifest_resource_id = IDR_GAIA_AUTH_SAML_MANIFEST;
61 #else
62 int manifest_resource_id = IDR_GAIA_AUTH_SAML_MANIFEST;
63 #endif
65 component_loader->Add(manifest_resource_id,
66 base::FilePath(FILE_PATH_LITERAL("gaia_auth")));
69 void UnloadGaiaAuthExtension(BrowserContext* context) {
70 DCHECK_CURRENTLY_ON(BrowserThread::UI);
72 content::StoragePartition* partition =
73 content::BrowserContext::GetStoragePartitionForSite(
74 context, GURL(chrome::kChromeUIChromeSigninURL));
75 if (partition) {
76 partition->ClearData(
77 content::StoragePartition::REMOVE_DATA_MASK_ALL,
78 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL,
79 GURL(),
80 content::StoragePartition::OriginMatcherFunction(),
81 base::Time(),
82 base::Time::Max(),
83 base::Bind(&base::DoNothing));
86 const char kGaiaAuthId[] = "mfffpogegjflfpflabcdkioaeobkgjik";
87 GetComponentLoader(context)->Remove(kGaiaAuthId);
90 } // namespace
92 namespace extensions {
94 GaiaAuthExtensionLoader::GaiaAuthExtensionLoader(BrowserContext* context)
95 : browser_context_(context), load_count_(0) {}
97 GaiaAuthExtensionLoader::~GaiaAuthExtensionLoader() {
98 DCHECK_EQ(0, load_count_);
101 void GaiaAuthExtensionLoader::LoadIfNeeded() {
102 if (load_count_ == 0)
103 LoadGaiaAuthExtension(browser_context_);
104 ++load_count_;
107 void GaiaAuthExtensionLoader::UnloadIfNeeded() {
108 --load_count_;
109 if (load_count_ == 0)
110 UnloadGaiaAuthExtension(browser_context_);
113 void GaiaAuthExtensionLoader::Shutdown() {
114 if (load_count_ > 0) {
115 UnloadGaiaAuthExtension(browser_context_);
116 load_count_ = 0;
120 // static
121 GaiaAuthExtensionLoader* GaiaAuthExtensionLoader::Get(BrowserContext* context) {
122 return BrowserContextKeyedAPIFactory<GaiaAuthExtensionLoader>::Get(context);
125 static base::LazyInstance<
126 BrowserContextKeyedAPIFactory<GaiaAuthExtensionLoader> > g_factory =
127 LAZY_INSTANCE_INITIALIZER;
129 // static
130 BrowserContextKeyedAPIFactory<GaiaAuthExtensionLoader>*
131 GaiaAuthExtensionLoader::GetFactoryInstance() {
132 return g_factory.Pointer();
135 } // namespace extensions