OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "chrome/browser/extensions/updater/safe_manifest_parser.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/command_line.h" | |
9 #include "base/location.h" | |
10 #include "base/logging.h" | |
11 #include "chrome/common/extensions/chrome_utility_extensions_messages.h" | |
12 #include "content/public/browser/browser_thread.h" | |
13 #include "content/public/browser/utility_process_host.h" | |
14 #include "content/public/common/content_switches.h" | |
15 #include "ipc/ipc_message_macros.h" | |
16 | |
17 using content::BrowserThread; | |
18 | |
19 namespace extensions { | |
20 | |
21 SafeManifestParser::SafeManifestParser(const std::string& xml, | |
22 ManifestFetchData* fetch_data, | |
23 const UpdateCallback& update_callback) | |
24 : xml_(xml), | |
25 fetch_data_(fetch_data), | |
26 update_callback_(update_callback) { | |
27 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
28 } | |
29 | |
30 void SafeManifestParser::Start() { | |
31 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
32 if (!BrowserThread::PostTask( | |
33 BrowserThread::IO, FROM_HERE, | |
34 base::Bind(&SafeManifestParser::ParseInSandbox, this))) { | |
35 NOTREACHED(); | |
36 } | |
37 } | |
38 | |
39 SafeManifestParser::~SafeManifestParser() { | |
40 // If we're using UtilityProcessHost, we may not be destroyed on | |
41 // the UI or IO thread. | |
42 } | |
43 | |
44 void SafeManifestParser::ParseInSandbox() { | |
45 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
46 | |
47 content::UtilityProcessHost* host = content::UtilityProcessHost::Create( | |
48 this, | |
49 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI).get()); | |
50 host->Send(new ChromeUtilityMsg_ParseUpdateManifest(xml_)); | |
51 } | |
52 | |
53 bool SafeManifestParser::OnMessageReceived(const IPC::Message& message) { | |
54 bool handled = true; | |
55 IPC_BEGIN_MESSAGE_MAP(SafeManifestParser, message) | |
56 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ParseUpdateManifest_Succeeded, | |
57 OnParseUpdateManifestSucceeded) | |
58 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ParseUpdateManifest_Failed, | |
59 OnParseUpdateManifestFailed) | |
60 IPC_MESSAGE_UNHANDLED(handled = false) | |
61 IPC_END_MESSAGE_MAP() | |
62 return handled; | |
63 } | |
64 | |
65 void SafeManifestParser::OnParseUpdateManifestSucceeded( | |
66 const UpdateManifest::Results& results) { | |
67 VLOG(2) << "parsing manifest succeeded (" << fetch_data_->full_url() << ")"; | |
68 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
69 update_callback_.Run(*fetch_data_, &results); | |
70 } | |
71 | |
72 void SafeManifestParser::OnParseUpdateManifestFailed( | |
73 const std::string& error_message) { | |
74 VLOG(2) << "parsing manifest failed (" << fetch_data_->full_url() << ")"; | |
75 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
76 LOG(WARNING) << "Error parsing update manifest:\n" << error_message; | |
77 update_callback_.Run(*fetch_data_, NULL); | |
78 } | |
79 | |
80 } // namespace extensions | |
OLD | NEW |