diff options
author | tengs@chromium.org <tengs@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-29 18:59:59 +0000 |
---|---|---|
committer | tengs@chromium.org <tengs@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-29 18:59:59 +0000 |
commit | 0154c2bee5ee8c46a43c469bb94bc32a419485f7 (patch) | |
tree | d63fa62bd91916c18a4d97d1b05f954c8190b007 /chrome/browser/extensions/scoped_gaia_auth_extension.cc | |
parent | fe752272420b287bd97512d86668bae1371f0419 (diff) | |
download | chromium_src-0154c2bee5ee8c46a43c469bb94bc32a419485f7.zip chromium_src-0154c2bee5ee8c46a43c469bb94bc32a419485f7.tar.gz chromium_src-0154c2bee5ee8c46a43c469bb94bc32a419485f7.tar.bz2 |
Change loading custom auth extension to load from --auth-ext-path value.
Before, if a custom auth extension is given through the --auth-ext-path flag,
the manifest is loaded from the browser resource rather than the overriden
path. We want to load the manifest from the given path instead.
Also change ComponentLoader::AddOrReplace to return an empty string on failure
for consistency with other ComponentLoader functions.
BUG=239212
TEST=on cros device with custom telemetry auth extension
Review URL: https://chromiumcodereview.appspot.com/15937003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@202926 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/scoped_gaia_auth_extension.cc')
-rw-r--r-- | chrome/browser/extensions/scoped_gaia_auth_extension.cc | 149 |
1 files changed, 78 insertions, 71 deletions
diff --git a/chrome/browser/extensions/scoped_gaia_auth_extension.cc b/chrome/browser/extensions/scoped_gaia_auth_extension.cc index 03e5e72..a08678c 100644 --- a/chrome/browser/extensions/scoped_gaia_auth_extension.cc +++ b/chrome/browser/extensions/scoped_gaia_auth_extension.cc @@ -1,71 +1,78 @@ -// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/extensions/scoped_gaia_auth_extension.h"
-
-#include "base/command_line.h"
-#include "chrome/browser/extensions/component_loader.h"
-#include "chrome/browser/extensions/extension_service.h"
-#include "chrome/browser/extensions/extension_system.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/common/chrome_constants.h"
-#include "chrome/common/chrome_switches.h"
-#include "grit/browser_resources.h"
-
-#if defined(OS_CHROMEOS)
-#include "chrome/browser/chromeos/system/statistics_provider.h"
-#include "chromeos/chromeos_constants.h"
-#include "chromeos/chromeos_switches.h"
-#endif
-
-namespace {
-
-extensions::ComponentLoader* GetComponentLoader(Profile* profile) {
- extensions::ExtensionSystem* extension_system =
- extensions::ExtensionSystem::Get(profile);
- ExtensionService* extension_service = extension_system->extension_service();
- return extension_service->component_loader();
-}
-
-void LoadGaiaAuthExtension(Profile* profile) {
- extensions::ComponentLoader* component_loader = GetComponentLoader(profile);
- const CommandLine* command_line = CommandLine::ForCurrentProcess();
- if (command_line->HasSwitch(switches::kAuthExtensionPath)) {
- base::FilePath auth_extension_path =
- command_line->GetSwitchValuePath(switches::kAuthExtensionPath);
- component_loader->Add(IDR_GAIA_TEST_AUTH_MANIFEST, auth_extension_path);
- return;
- }
-
- bool force_keyboard_oobe = false;
-#if defined(OS_CHROMEOS)
- chromeos::system::StatisticsProvider* provider =
- chromeos::system::StatisticsProvider::GetInstance();
- provider->GetMachineFlag(chromeos::kOemKeyboardDrivenOobeKey,
- &force_keyboard_oobe);
-#endif // OS_CHROMEOS
- if (force_keyboard_oobe) {
- component_loader->Add(IDR_GAIA_AUTH_KEYBOARD_MANIFEST,
- base::FilePath(FILE_PATH_LITERAL("gaia_auth")));
- } else {
- component_loader->Add(IDR_GAIA_AUTH_MANIFEST,
- base::FilePath(FILE_PATH_LITERAL("gaia_auth")));
- }
-}
-
-void UnloadGaiaAuthExtension(Profile* profile) {
- const char kGaiaAuthId[] = "mfffpogegjflfpflabcdkioaeobkgjik";
- GetComponentLoader(profile)->Remove(kGaiaAuthId);
-}
-
-} // namespace
-
-ScopedGaiaAuthExtension::ScopedGaiaAuthExtension(Profile* profile)
- : profile_(profile) {
- LoadGaiaAuthExtension(profile_);
-}
-
-ScopedGaiaAuthExtension::~ScopedGaiaAuthExtension() {
- UnloadGaiaAuthExtension(profile_);
-}
+// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/extensions/scoped_gaia_auth_extension.h" + +#include "base/command_line.h" +#include "chrome/browser/extensions/component_loader.h" +#include "chrome/browser/extensions/extension_service.h" +#include "chrome/browser/extensions/extension_system.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/common/chrome_constants.h" +#include "chrome/common/chrome_switches.h" +#include "grit/browser_resources.h" + +#if defined(OS_CHROMEOS) +#include "chrome/browser/chromeos/system/statistics_provider.h" +#include "chromeos/chromeos_constants.h" +#include "chromeos/chromeos_switches.h" +#endif + +namespace { + +extensions::ComponentLoader* GetComponentLoader(Profile* profile) { + extensions::ExtensionSystem* extension_system = + extensions::ExtensionSystem::Get(profile); + ExtensionService* extension_service = extension_system->extension_service(); + return extension_service->component_loader(); +} + +void LoadGaiaAuthExtension(Profile* profile) { + extensions::ComponentLoader* component_loader = GetComponentLoader(profile); + const CommandLine* command_line = CommandLine::ForCurrentProcess(); + if (command_line->HasSwitch(switches::kAuthExtensionPath)) { + base::FilePath auth_extension_path = + command_line->GetSwitchValuePath(switches::kAuthExtensionPath); + const std::string extension_id = + component_loader->AddOrReplace(auth_extension_path); + + if (extension_id.empty()) { + LOG(ERROR) << "Failed to load custom Gaia auth extension given by the " + << switches::kAuthExtensionPath << " flag: " + << auth_extension_path.value(); + } + return; + } + + bool force_keyboard_oobe = false; +#if defined(OS_CHROMEOS) + chromeos::system::StatisticsProvider* provider = + chromeos::system::StatisticsProvider::GetInstance(); + provider->GetMachineFlag(chromeos::kOemKeyboardDrivenOobeKey, + &force_keyboard_oobe); +#endif // OS_CHROMEOS + if (force_keyboard_oobe) { + component_loader->Add(IDR_GAIA_AUTH_KEYBOARD_MANIFEST, + base::FilePath(FILE_PATH_LITERAL("gaia_auth"))); + } else { + component_loader->Add(IDR_GAIA_AUTH_MANIFEST, + base::FilePath(FILE_PATH_LITERAL("gaia_auth"))); + } +} + +void UnloadGaiaAuthExtension(Profile* profile) { + const char kGaiaAuthId[] = "mfffpogegjflfpflabcdkioaeobkgjik"; + GetComponentLoader(profile)->Remove(kGaiaAuthId); +} + +} // namespace + +ScopedGaiaAuthExtension::ScopedGaiaAuthExtension(Profile* profile) + : profile_(profile) { + LoadGaiaAuthExtension(profile_); +} + +ScopedGaiaAuthExtension::~ScopedGaiaAuthExtension() { + UnloadGaiaAuthExtension(profile_); +} |