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