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"
17 using content::BrowserThread
;
19 namespace extensions
{
21 SafeManifestParser::SafeManifestParser(const std::string
& xml
,
22 ManifestFetchData
* fetch_data
,
23 const UpdateCallback
& update_callback
)
24 : xml_(xml
), fetch_data_(fetch_data
), update_callback_(update_callback
) {
25 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
28 void SafeManifestParser::Start() {
29 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
30 if (!BrowserThread::PostTask(
33 base::Bind(&SafeManifestParser::ParseInSandbox
, this))) {
38 SafeManifestParser::~SafeManifestParser() {
39 // If we're using UtilityProcessHost, we may not be destroyed on
40 // the UI or IO thread.
43 void SafeManifestParser::ParseInSandbox() {
44 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
46 content::UtilityProcessHost
* host
= content::UtilityProcessHost::Create(
48 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI
).get());
49 host
->Send(new ExtensionUtilityMsg_ParseUpdateManifest(xml_
));
52 bool SafeManifestParser::OnMessageReceived(const IPC::Message
& message
) {
54 IPC_BEGIN_MESSAGE_MAP(SafeManifestParser
, message
)
55 IPC_MESSAGE_HANDLER(ExtensionUtilityHostMsg_ParseUpdateManifest_Succeeded
,
56 OnParseUpdateManifestSucceeded
)
57 IPC_MESSAGE_HANDLER(ExtensionUtilityHostMsg_ParseUpdateManifest_Failed
,
58 OnParseUpdateManifestFailed
)
59 IPC_MESSAGE_UNHANDLED(handled
= false)
64 void SafeManifestParser::OnParseUpdateManifestSucceeded(
65 const UpdateManifest::Results
& results
) {
66 VLOG(2) << "parsing manifest succeeded (" << fetch_data_
->full_url() << ")";
67 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
68 update_callback_
.Run(*fetch_data_
, &results
);
71 void SafeManifestParser::OnParseUpdateManifestFailed(
72 const std::string
& error_message
) {
73 VLOG(2) << "parsing manifest failed (" << fetch_data_
->full_url() << ")";
74 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
75 LOG(WARNING
) << "Error parsing update manifest:\n" << error_message
;
76 update_callback_
.Run(*fetch_data_
, NULL
);
79 } // namespace extensions