Blink roll 25b6bd3a7a131ffe68d809546ad1a20707915cdc:3a503f41ae42e5b79cfcd2ff10e65afde...
[chromium-blink-merge.git] / extensions / utility / utility_handler.cc
blob1298933336cd2ca80818d6ec51a1231f1d04a5f4
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 {
19 namespace {
21 bool Send(IPC::Message* message) {
22 return content::UtilityThread::Get()->Send(message);
25 void ReleaseProcessIfNeeded() {
26 content::UtilityThread::Get()->ReleaseProcessIfNeeded();
29 } // namespace
31 UtilityHandler::UtilityHandler() {
34 UtilityHandler::~UtilityHandler() {
37 // static
38 void UtilityHandler::UtilityThreadStarted() {
39 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
40 std::string lang = command_line->GetSwitchValueASCII(switches::kLang);
41 if (!lang.empty())
42 extension_l10n_util::SetProcessLocale(lang);
45 bool UtilityHandler::OnMessageReceived(const IPC::Message& message) {
46 bool handled = true;
47 IPC_BEGIN_MESSAGE_MAP(UtilityHandler, message)
48 IPC_MESSAGE_HANDLER(ExtensionUtilityMsg_ParseUpdateManifest,
49 OnParseUpdateManifest)
50 IPC_MESSAGE_UNHANDLED(handled = false)
51 IPC_END_MESSAGE_MAP()
52 return handled;
55 void UtilityHandler::OnParseUpdateManifest(const std::string& xml) {
56 UpdateManifest manifest;
57 if (!manifest.Parse(xml)) {
58 Send(new ExtensionUtilityHostMsg_ParseUpdateManifest_Failed(
59 manifest.errors()));
60 } else {
61 Send(new ExtensionUtilityHostMsg_ParseUpdateManifest_Succeeded(
62 manifest.results()));
64 ReleaseProcessIfNeeded();
67 } // namespace extensions