From 3813023bde420950c60d9d12a8610510b76da337 Mon Sep 17 00:00:00 2001 From: rockot Date: Thu, 6 Nov 2014 10:50:01 -0800 Subject: Add rudimentary UpdateService to app_shell It can download a CRX from the web store using an ID given at the command line. This wires up utility process support for app_shell and establishes a base for factoring additional extensions utility IPCs out of //chrome in the near future. BUG=398671 TBR=asargent@chromium.org for cloned dependency on omaha_query_params Review URL: https://codereview.chromium.org/693233003 Cr-Commit-Position: refs/heads/master@{#303055} --- extensions/utility/BUILD.gn | 26 ++++++++++++++ extensions/utility/DEPS | 3 ++ extensions/utility/utility_handler.cc | 67 +++++++++++++++++++++++++++++++++++ extensions/utility/utility_handler.h | 37 +++++++++++++++++++ 4 files changed, 133 insertions(+) create mode 100644 extensions/utility/BUILD.gn create mode 100644 extensions/utility/DEPS create mode 100644 extensions/utility/utility_handler.cc create mode 100644 extensions/utility/utility_handler.h (limited to 'extensions/utility') diff --git a/extensions/utility/BUILD.gn b/extensions/utility/BUILD.gn new file mode 100644 index 0000000..ad884a2 --- /dev/null +++ b/extensions/utility/BUILD.gn @@ -0,0 +1,26 @@ +# Copyright 2014 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. + +import("//build/config/features.gni") + +assert(enable_extensions) + +# GYP version: extensions/extensions.gyp:extensions_utility +source_set("utility") { + sources = [ + "utility_handler.cc", + "utility_handler.h", + ] + + deps = [ + "//content/public/utility", + "//extensions/common", + ] + + if (is_win) { + cflags = [ + "/wd4267", # TODO(jschuh): crbug.com/167187 fix size_t to int truncations. + ] + } +} diff --git a/extensions/utility/DEPS b/extensions/utility/DEPS new file mode 100644 index 0000000..8ad521e --- /dev/null +++ b/extensions/utility/DEPS @@ -0,0 +1,3 @@ +include_rules = [ + "+content/public/utility", +] diff --git a/extensions/utility/utility_handler.cc b/extensions/utility/utility_handler.cc new file mode 100644 index 0000000..1298933 --- /dev/null +++ b/extensions/utility/utility_handler.cc @@ -0,0 +1,67 @@ +// Copyright 2014 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 "extensions/utility/utility_handler.h" + +#include "base/command_line.h" +#include "content/public/utility/utility_thread.h" +#include "extensions/common/extension.h" +#include "extensions/common/extension_l10n_util.h" +#include "extensions/common/extension_utility_messages.h" +#include "extensions/common/update_manifest.h" +#include "ipc/ipc_message.h" +#include "ipc/ipc_message_macros.h" +#include "ui/base/ui_base_switches.h" + +namespace extensions { + +namespace { + +bool Send(IPC::Message* message) { + return content::UtilityThread::Get()->Send(message); +} + +void ReleaseProcessIfNeeded() { + content::UtilityThread::Get()->ReleaseProcessIfNeeded(); +} + +} // namespace + +UtilityHandler::UtilityHandler() { +} + +UtilityHandler::~UtilityHandler() { +} + +// static +void UtilityHandler::UtilityThreadStarted() { + base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); + std::string lang = command_line->GetSwitchValueASCII(switches::kLang); + if (!lang.empty()) + extension_l10n_util::SetProcessLocale(lang); +} + +bool UtilityHandler::OnMessageReceived(const IPC::Message& message) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(UtilityHandler, message) + IPC_MESSAGE_HANDLER(ExtensionUtilityMsg_ParseUpdateManifest, + OnParseUpdateManifest) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; +} + +void UtilityHandler::OnParseUpdateManifest(const std::string& xml) { + UpdateManifest manifest; + if (!manifest.Parse(xml)) { + Send(new ExtensionUtilityHostMsg_ParseUpdateManifest_Failed( + manifest.errors())); + } else { + Send(new ExtensionUtilityHostMsg_ParseUpdateManifest_Succeeded( + manifest.results())); + } + ReleaseProcessIfNeeded(); +} + +} // namespace extensions diff --git a/extensions/utility/utility_handler.h b/extensions/utility/utility_handler.h new file mode 100644 index 0000000..0ae31ec --- /dev/null +++ b/extensions/utility/utility_handler.h @@ -0,0 +1,37 @@ +// Copyright 2014 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. + +#ifndef EXTENSIONS_UTILITY_UTILITY_HANDLER_ +#define EXTENSIONS_UTILITY_UTILITY_HANDLER_ + +#include + +#include "base/macros.h" + +namespace IPC { +class Message; +} + +namespace extensions { + +// A handler for extensions-related IPC from within utility processes. +class UtilityHandler { + public: + UtilityHandler(); + ~UtilityHandler(); + + static void UtilityThreadStarted(); + + bool OnMessageReceived(const IPC::Message& message); + + private: + // IPC message handlers. + void OnParseUpdateManifest(const std::string& xml); + + DISALLOW_COPY_AND_ASSIGN(UtilityHandler); +}; + +} // namespace extensions + +#endif // EXTENSIONS_UTILITY_UTILITY_HANDLER_ -- cgit v1.1