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 "content/public/utility/utility_thread.h"
9 #include "extensions/common/extension.h"
10 #include "extensions/common/extension_l10n_util.h"
11 #include "extensions/common/extension_utility_messages.h"
12 #include "extensions/common/update_manifest.h"
13 #include "ipc/ipc_message.h"
14 #include "ipc/ipc_message_macros.h"
15 #include "ui/base/ui_base_switches.h"
17 namespace extensions
{
21 bool Send(IPC::Message
* message
) {
22 return content::UtilityThread::Get()->Send(message
);
25 void ReleaseProcessIfNeeded() {
26 content::UtilityThread::Get()->ReleaseProcessIfNeeded();
31 UtilityHandler::UtilityHandler() {
34 UtilityHandler::~UtilityHandler() {
38 void UtilityHandler::UtilityThreadStarted() {
39 base::CommandLine
* command_line
= base::CommandLine::ForCurrentProcess();
40 std::string lang
= command_line
->GetSwitchValueASCII(switches::kLang
);
42 extension_l10n_util::SetProcessLocale(lang
);
45 bool UtilityHandler::OnMessageReceived(const IPC::Message
& message
) {
47 IPC_BEGIN_MESSAGE_MAP(UtilityHandler
, message
)
48 IPC_MESSAGE_HANDLER(ExtensionUtilityMsg_ParseUpdateManifest
,
49 OnParseUpdateManifest
)
50 IPC_MESSAGE_UNHANDLED(handled
= false)
55 void UtilityHandler::OnParseUpdateManifest(const std::string
& xml
) {
56 UpdateManifest manifest
;
57 if (!manifest
.Parse(xml
)) {
58 Send(new ExtensionUtilityHostMsg_ParseUpdateManifest_Failed(
61 Send(new ExtensionUtilityHostMsg_ParseUpdateManifest_Succeeded(
64 ReleaseProcessIfNeeded();
67 } // namespace extensions