| 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 "extensions/browser/updater/safe_manifest_parser.h" | 5 #include "extensions/browser/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 "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 12 #include "content/public/browser/utility_process_host.h" | 12 #include "content/public/browser/utility_process_host.h" |
| 13 #include "content/public/common/content_switches.h" | 13 #include "content/public/common/content_switches.h" |
| 14 #include "extensions/common/extension_utility_messages.h" | 14 #include "extensions/common/extension_utility_messages.h" |
| 15 #include "ipc/ipc_message_macros.h" | 15 #include "ipc/ipc_message_macros.h" |
| 16 #include "grit/extensions_strings.h" |
| 17 #include "ui/base/l10n/l10n_util.h" |
| 16 | 18 |
| 17 using content::BrowserThread; | 19 using content::BrowserThread; |
| 18 | 20 |
| 19 namespace extensions { | 21 namespace extensions { |
| 20 | 22 |
| 21 SafeManifestParser::SafeManifestParser(const std::string& xml, | 23 SafeManifestParser::SafeManifestParser(const std::string& xml, |
| 22 const ResultsCallback& results_callback) | 24 const ResultsCallback& results_callback) |
| 23 : xml_(xml), results_callback_(results_callback) { | 25 : xml_(xml), results_callback_(results_callback) { |
| 24 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 26 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 25 } | 27 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 38 // If we're using UtilityProcessHost, we may not be destroyed on | 40 // If we're using UtilityProcessHost, we may not be destroyed on |
| 39 // the UI or IO thread. | 41 // the UI or IO thread. |
| 40 } | 42 } |
| 41 | 43 |
| 42 void SafeManifestParser::ParseInSandbox() { | 44 void SafeManifestParser::ParseInSandbox() { |
| 43 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 45 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 44 | 46 |
| 45 content::UtilityProcessHost* host = content::UtilityProcessHost::Create( | 47 content::UtilityProcessHost* host = content::UtilityProcessHost::Create( |
| 46 this, | 48 this, |
| 47 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI).get()); | 49 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI).get()); |
| 50 host->SetName( |
| 51 l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_MANIFEST_PARSER_NAME)); |
| 48 host->Send(new ExtensionUtilityMsg_ParseUpdateManifest(xml_)); | 52 host->Send(new ExtensionUtilityMsg_ParseUpdateManifest(xml_)); |
| 49 } | 53 } |
| 50 | 54 |
| 51 bool SafeManifestParser::OnMessageReceived(const IPC::Message& message) { | 55 bool SafeManifestParser::OnMessageReceived(const IPC::Message& message) { |
| 52 bool handled = true; | 56 bool handled = true; |
| 53 IPC_BEGIN_MESSAGE_MAP(SafeManifestParser, message) | 57 IPC_BEGIN_MESSAGE_MAP(SafeManifestParser, message) |
| 54 IPC_MESSAGE_HANDLER(ExtensionUtilityHostMsg_ParseUpdateManifest_Succeeded, | 58 IPC_MESSAGE_HANDLER(ExtensionUtilityHostMsg_ParseUpdateManifest_Succeeded, |
| 55 OnParseUpdateManifestSucceeded) | 59 OnParseUpdateManifestSucceeded) |
| 56 IPC_MESSAGE_HANDLER(ExtensionUtilityHostMsg_ParseUpdateManifest_Failed, | 60 IPC_MESSAGE_HANDLER(ExtensionUtilityHostMsg_ParseUpdateManifest_Failed, |
| 57 OnParseUpdateManifestFailed) | 61 OnParseUpdateManifestFailed) |
| 58 IPC_MESSAGE_UNHANDLED(handled = false) | 62 IPC_MESSAGE_UNHANDLED(handled = false) |
| 59 IPC_END_MESSAGE_MAP() | 63 IPC_END_MESSAGE_MAP() |
| 60 return handled; | 64 return handled; |
| 61 } | 65 } |
| 62 | 66 |
| 63 void SafeManifestParser::OnParseUpdateManifestSucceeded( | 67 void SafeManifestParser::OnParseUpdateManifestSucceeded( |
| 64 const UpdateManifest::Results& results) { | 68 const UpdateManifest::Results& results) { |
| 65 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 69 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 66 results_callback_.Run(&results); | 70 results_callback_.Run(&results); |
| 67 } | 71 } |
| 68 | 72 |
| 69 void SafeManifestParser::OnParseUpdateManifestFailed( | 73 void SafeManifestParser::OnParseUpdateManifestFailed( |
| 70 const std::string& error_message) { | 74 const std::string& error_message) { |
| 71 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 75 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 72 LOG(WARNING) << "Error parsing update manifest:\n" << error_message; | 76 LOG(WARNING) << "Error parsing update manifest:\n" << error_message; |
| 73 results_callback_.Run(NULL); | 77 results_callback_.Run(NULL); |
| 74 } | 78 } |
| 75 | 79 |
| 76 } // namespace extensions | 80 } // namespace extensions |
| OLD | NEW |