Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / extensions / utility / utility_handler.cc
blob3add93ed3694a5cb52a718ffe8aecb3db24e4e09
1 // Copyright 2014 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 "extensions/utility/utility_handler.h"
7 #include "base/command_line.h"
8 #include "base/files/file_path.h"
9 #include "content/public/utility/utility_thread.h"
10 #include "extensions/common/extension.h"
11 #include "extensions/common/extension_l10n_util.h"
12 #include "extensions/common/extension_utility_messages.h"
13 #include "extensions/common/extensions_client.h"
14 #include "extensions/common/manifest.h"
15 #include "extensions/common/update_manifest.h"
16 #include "extensions/utility/unpacker.h"
17 #include "ipc/ipc_message.h"
18 #include "ipc/ipc_message_macros.h"
19 #include "ui/base/ui_base_switches.h"
21 namespace extensions {
23 namespace {
25 bool Send(IPC::Message* message) {
26 return content::UtilityThread::Get()->Send(message);
29 void ReleaseProcessIfNeeded() {
30 content::UtilityThread::Get()->ReleaseProcessIfNeeded();
33 } // namespace
35 UtilityHandler::UtilityHandler() {
38 UtilityHandler::~UtilityHandler() {
41 // static
42 void UtilityHandler::UtilityThreadStarted() {
43 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
44 std::string lang = command_line->GetSwitchValueASCII(switches::kLang);
45 if (!lang.empty())
46 extension_l10n_util::SetProcessLocale(lang);
49 bool UtilityHandler::OnMessageReceived(const IPC::Message& message) {
50 bool handled = true;
51 IPC_BEGIN_MESSAGE_MAP(UtilityHandler, message)
52 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_UnpackExtension, OnUnpackExtension)
53 IPC_MESSAGE_HANDLER(ExtensionUtilityMsg_ParseUpdateManifest,
54 OnParseUpdateManifest)
55 IPC_MESSAGE_UNHANDLED(handled = false)
56 IPC_END_MESSAGE_MAP()
57 return handled;
60 void UtilityHandler::OnParseUpdateManifest(const std::string& xml) {
61 UpdateManifest manifest;
62 if (!manifest.Parse(xml)) {
63 Send(new ExtensionUtilityHostMsg_ParseUpdateManifest_Failed(
64 manifest.errors()));
65 } else {
66 Send(new ExtensionUtilityHostMsg_ParseUpdateManifest_Succeeded(
67 manifest.results()));
69 ReleaseProcessIfNeeded();
72 void UtilityHandler::OnUnpackExtension(
73 const base::FilePath& extension_path,
74 const std::string& extension_id,
75 int location,
76 int creation_flags) {
77 CHECK_GT(location, Manifest::INVALID_LOCATION);
78 CHECK_LT(location, Manifest::NUM_LOCATIONS);
79 DCHECK(ExtensionsClient::Get());
80 Unpacker unpacker(extension_path,
81 extension_id,
82 static_cast<Manifest::Location>(location),
83 creation_flags);
84 if (unpacker.Run() && unpacker.DumpImagesToFile() &&
85 unpacker.DumpMessageCatalogsToFile()) {
86 Send(new ChromeUtilityHostMsg_UnpackExtension_Succeeded(
87 *unpacker.parsed_manifest()));
88 } else {
89 Send(new ChromeUtilityHostMsg_UnpackExtension_Failed(
90 unpacker.error_message()));
93 ReleaseProcessIfNeeded();
97 } // namespace extensions