Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / extensions / utility / utility_handler.cc
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.
4
5 #include "extensions/utility/utility_handler.h"
6
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"
16
17 namespace extensions {
18
19 namespace {
20
21 bool Send(IPC::Message* message) {
22   return content::UtilityThread::Get()->Send(message);
23 }
24
25 void ReleaseProcessIfNeeded() {
26   content::UtilityThread::Get()->ReleaseProcessIfNeeded();
27 }
28
29 }  // namespace
30
31 UtilityHandler::UtilityHandler() {
32 }
33
34 UtilityHandler::~UtilityHandler() {
35 }
36
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);
43 }
44
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;
53 }
54
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()));
63   }
64   ReleaseProcessIfNeeded();
65 }
66
67 }  // namespace extensions