Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / extensions / browser / updater / safe_manifest_parser.cc
blob05c75a955967b7e7560280e96b760136f3a94af2
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"
7 #include "base/bind.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(
32 BrowserThread::IO,
33 FROM_HERE,
34 base::Bind(&SafeManifestParser::ParseInSandbox, this))) {
35 NOTREACHED();
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(
48 this,
49 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI).get());
50 host->SetName(
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) {
56 bool handled = true;
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)
63 IPC_END_MESSAGE_MAP()
64 return handled;
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