Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / chrome / browser / media_galleries / fileapi / safe_itunes_pref_parser_win.cc
bloba4d224a1d342d08cfc474ce91ebded75bb6c58b6
1 // Copyright 2013 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 "chrome/browser/media_galleries/fileapi/safe_itunes_pref_parser_win.h"
7 #include "base/single_thread_task_runner.h"
8 #include "base/thread_task_runner_handle.h"
9 #include "chrome/common/extensions/chrome_utility_extensions_messages.h"
10 #include "chrome/grit/generated_resources.h"
11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/utility_process_host.h"
13 #include "ui/base/l10n/l10n_util.h"
15 using content::BrowserThread;
16 using content::UtilityProcessHost;
18 namespace itunes {
20 SafeITunesPrefParserWin::SafeITunesPrefParserWin(
21 const std::string& unsafe_xml,
22 const ParserCallback& callback)
23 : unsafe_xml_(unsafe_xml),
24 callback_(callback),
25 parser_state_(INITIAL_STATE) {
26 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
27 DCHECK(!callback_.is_null());
30 void SafeITunesPrefParserWin::Start() {
31 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
32 BrowserThread::PostTask(
33 BrowserThread::IO,
34 FROM_HERE,
35 base::Bind(&SafeITunesPrefParserWin::StartWorkOnIOThread, this));
38 SafeITunesPrefParserWin::~SafeITunesPrefParserWin() {
41 void SafeITunesPrefParserWin::StartWorkOnIOThread() {
42 DCHECK_CURRENTLY_ON(BrowserThread::IO);
43 DCHECK_EQ(INITIAL_STATE, parser_state_);
45 UtilityProcessHost* host =
46 UtilityProcessHost::Create(this, base::ThreadTaskRunnerHandle::Get());
47 host->SetName(l10n_util::GetStringUTF16(
48 IDS_UTILITY_PROCESS_MEDIA_LIBRARY_FILE_CHECKER_NAME));
49 host->Send(new ChromeUtilityMsg_ParseITunesPrefXml(unsafe_xml_));
50 parser_state_ = STARTED_PARSING_STATE;
53 void SafeITunesPrefParserWin::OnGotITunesDirectory(
54 const base::FilePath& library_file) {
55 DCHECK_CURRENTLY_ON(BrowserThread::IO);
57 if (parser_state_ != STARTED_PARSING_STATE)
58 return;
59 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
60 base::Bind(callback_, library_file));
61 parser_state_ = FINISHED_PARSING_STATE;
64 void SafeITunesPrefParserWin::OnProcessCrashed(int exit_code) {
65 OnGotITunesDirectory(base::FilePath());
68 bool SafeITunesPrefParserWin::OnMessageReceived(
69 const IPC::Message& message) {
70 bool handled = true;
71 IPC_BEGIN_MESSAGE_MAP(SafeITunesPrefParserWin, message)
72 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GotITunesDirectory,
73 OnGotITunesDirectory)
74 IPC_MESSAGE_UNHANDLED(handled = false)
75 IPC_END_MESSAGE_MAP()
76 return handled;
79 } // namespace itunes