diff options
author | rockot <rockot@chromium.org> | 2014-09-24 13:31:53 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-24 20:32:06 +0000 |
commit | eb6d47fab5dc127b474363d488aa1b6ccbfa7b48 (patch) | |
tree | 76d490eece9de85345c3c1cf31e5a6f8fb9e24dc /extensions/browser/updater | |
parent | 1b241325584a8612ff035c809ecfdeefa08063c5 (diff) | |
download | chromium_src-eb6d47fab5dc127b474363d488aa1b6ccbfa7b48.zip chromium_src-eb6d47fab5dc127b474363d488aa1b6ccbfa7b48.tar.gz chromium_src-eb6d47fab5dc127b474363d488aa1b6ccbfa7b48.tar.bz2 |
Move SafeManifestParser to //extensions
This moves SafeManifestParser to extensions_browser.
Also creates a new ExtensionUtility IPC message class in which
to define extensions utility process messages. The relevant
manifest parsing messages have been moved into this class.
BUG=398671
Review URL: https://codereview.chromium.org/464613002
Cr-Commit-Position: refs/heads/master@{#296508}
Diffstat (limited to 'extensions/browser/updater')
-rw-r--r-- | extensions/browser/updater/safe_manifest_parser.cc | 79 | ||||
-rw-r--r-- | extensions/browser/updater/safe_manifest_parser.h | 58 |
2 files changed, 137 insertions, 0 deletions
diff --git a/extensions/browser/updater/safe_manifest_parser.cc b/extensions/browser/updater/safe_manifest_parser.cc new file mode 100644 index 0000000..2ab9a05 --- /dev/null +++ b/extensions/browser/updater/safe_manifest_parser.cc @@ -0,0 +1,79 @@ +// Copyright (c) 2012 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/browser/updater/safe_manifest_parser.h" + +#include "base/bind.h" +#include "base/command_line.h" +#include "base/location.h" +#include "base/logging.h" +#include "content/public/browser/browser_thread.h" +#include "content/public/browser/utility_process_host.h" +#include "content/public/common/content_switches.h" +#include "extensions/common/extension_utility_messages.h" +#include "ipc/ipc_message_macros.h" + +using content::BrowserThread; + +namespace extensions { + +SafeManifestParser::SafeManifestParser(const std::string& xml, + ManifestFetchData* fetch_data, + const UpdateCallback& update_callback) + : xml_(xml), fetch_data_(fetch_data), update_callback_(update_callback) { + DCHECK_CURRENTLY_ON(BrowserThread::UI); +} + +void SafeManifestParser::Start() { + DCHECK_CURRENTLY_ON(BrowserThread::UI); + if (!BrowserThread::PostTask( + BrowserThread::IO, + FROM_HERE, + base::Bind(&SafeManifestParser::ParseInSandbox, this))) { + NOTREACHED(); + } +} + +SafeManifestParser::~SafeManifestParser() { + // If we're using UtilityProcessHost, we may not be destroyed on + // the UI or IO thread. +} + +void SafeManifestParser::ParseInSandbox() { + DCHECK_CURRENTLY_ON(BrowserThread::IO); + + content::UtilityProcessHost* host = content::UtilityProcessHost::Create( + this, + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI).get()); + host->Send(new ExtensionUtilityMsg_ParseUpdateManifest(xml_)); +} + +bool SafeManifestParser::OnMessageReceived(const IPC::Message& message) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(SafeManifestParser, message) + IPC_MESSAGE_HANDLER(ExtensionUtilityHostMsg_ParseUpdateManifest_Succeeded, + OnParseUpdateManifestSucceeded) + IPC_MESSAGE_HANDLER(ExtensionUtilityHostMsg_ParseUpdateManifest_Failed, + OnParseUpdateManifestFailed) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; +} + +void SafeManifestParser::OnParseUpdateManifestSucceeded( + const UpdateManifest::Results& results) { + VLOG(2) << "parsing manifest succeeded (" << fetch_data_->full_url() << ")"; + DCHECK_CURRENTLY_ON(BrowserThread::UI); + update_callback_.Run(*fetch_data_, &results); +} + +void SafeManifestParser::OnParseUpdateManifestFailed( + const std::string& error_message) { + VLOG(2) << "parsing manifest failed (" << fetch_data_->full_url() << ")"; + DCHECK_CURRENTLY_ON(BrowserThread::UI); + LOG(WARNING) << "Error parsing update manifest:\n" << error_message; + update_callback_.Run(*fetch_data_, NULL); +} + +} // namespace extensions diff --git a/extensions/browser/updater/safe_manifest_parser.h b/extensions/browser/updater/safe_manifest_parser.h new file mode 100644 index 0000000..278cd97 --- /dev/null +++ b/extensions/browser/updater/safe_manifest_parser.h @@ -0,0 +1,58 @@ +// Copyright (c) 2012 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_BROWSER_UPDATER_SAFE_MANIFEST_PARSER_H_ +#define EXTENSIONS_BROWSER_UPDATER_SAFE_MANIFEST_PARSER_H_ + +#include <string> + +#include "base/basictypes.h" +#include "base/callback.h" +#include "base/memory/scoped_ptr.h" +#include "content/public/browser/utility_process_host_client.h" +#include "extensions/browser/updater/manifest_fetch_data.h" +#include "extensions/common/update_manifest.h" + +namespace extensions { + +// Utility class to handle doing xml parsing in a sandboxed utility process. +class SafeManifestParser : public content::UtilityProcessHostClient { + public: + // Callback that is invoked when the manifest results are ready. + typedef base::Callback<void(const ManifestFetchData&, + const UpdateManifest::Results*)> UpdateCallback; + + // Takes ownership of |fetch_data|. + SafeManifestParser(const std::string& xml, + ManifestFetchData* fetch_data, + const UpdateCallback& update_callback); + + // Posts a task over to the IO loop to start the parsing of xml_ in a + // utility process. + void Start(); + + private: + virtual ~SafeManifestParser(); + + // Creates the sandboxed utility process and tells it to start parsing. + void ParseInSandbox(); + + // content::UtilityProcessHostClient implementation. + virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; + + void OnParseUpdateManifestSucceeded(const UpdateManifest::Results& results); + void OnParseUpdateManifestFailed(const std::string& error_message); + + const std::string xml_; + + // Should be accessed only on UI thread. + scoped_ptr<ManifestFetchData> fetch_data_; + UpdateCallback update_callback_; + + DISALLOW_COPY_AND_ASSIGN(SafeManifestParser); +}; + +} // namespace extensions + +#endif // EXTENSIONS_BROWSER_UPDATER_SAFE_MANIFEST_PARSER_H_ |