1 // Copyright (c) 2012 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/browser/updater/safe_manifest_parser.h"
8 #include "base/command_line.h"
9 #include "base/location.h"
10 #include "base/logging.h"
11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/utility_process_host.h"
13 #include "content/public/common/content_switches.h"
14 #include "extensions/common/extension_utility_messages.h"
15 #include "ipc/ipc_message_macros.h"
16 #include "grit/extensions_strings.h"
17 #include "ui/base/l10n/l10n_util.h"
19 using content::BrowserThread
;
21 namespace extensions
{
23 SafeManifestParser::SafeManifestParser(const std::string
& xml
,
24 const ResultsCallback
& results_callback
)
25 : xml_(xml
), results_callback_(results_callback
) {
26 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
29 void SafeManifestParser::Start() {
30 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
31 if (!BrowserThread::PostTask(
34 base::Bind(&SafeManifestParser::ParseInSandbox
, this))) {
39 SafeManifestParser::~SafeManifestParser() {
40 // If we're using UtilityProcessHost, we may not be destroyed on
41 // the UI or IO thread.
44 void SafeManifestParser::ParseInSandbox() {
45 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
47 content::UtilityProcessHost
* host
= content::UtilityProcessHost::Create(
49 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI
).get());
51 l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_MANIFEST_PARSER_NAME
));
52 host
->Send(new ExtensionUtilityMsg_ParseUpdateManifest(xml_
));
55 bool SafeManifestParser::OnMessageReceived(const IPC::Message
& message
) {
57 IPC_BEGIN_MESSAGE_MAP(SafeManifestParser
, message
)
58 IPC_MESSAGE_HANDLER(ExtensionUtilityHostMsg_ParseUpdateManifest_Succeeded
,
59 OnParseUpdateManifestSucceeded
)
60 IPC_MESSAGE_HANDLER(ExtensionUtilityHostMsg_ParseUpdateManifest_Failed
,
61 OnParseUpdateManifestFailed
)
62 IPC_MESSAGE_UNHANDLED(handled
= false)
67 void SafeManifestParser::OnParseUpdateManifestSucceeded(
68 const UpdateManifest::Results
& results
) {
69 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
70 results_callback_
.Run(&results
);
73 void SafeManifestParser::OnParseUpdateManifestFailed(
74 const std::string
& error_message
) {
75 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
76 LOG(WARNING
) << "Error parsing update manifest:\n" << error_message
;
77 results_callback_
.Run(NULL
);
80 } // namespace extensions