summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/scoped_gaia_auth_extension.cc
blob: 8e476861b583b4971e96b8231042dccec58baa04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// 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::system::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_);
}