Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / media_galleries / fileapi / safe_itunes_pref_parser_win.cc
blob92721ffcd023cb424fe4942dad297fa01d3012db
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 "chrome/common/chrome_utility_messages.h"
8 #include "content/public/browser/browser_thread.h"
9 #include "content/public/browser/utility_process_host.h"
11 using content::BrowserThread;
12 using content::UtilityProcessHost;
14 namespace itunes {
16 SafeITunesPrefParserWin::SafeITunesPrefParserWin(
17 const std::string& unsafe_xml,
18 const ParserCallback& callback)
19 : unsafe_xml_(unsafe_xml),
20 callback_(callback),
21 parser_state_(INITIAL_STATE) {
22 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
23 DCHECK(!callback_.is_null());
26 void SafeITunesPrefParserWin::Start() {
27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
28 BrowserThread::PostTask(
29 BrowserThread::IO,
30 FROM_HERE,
31 base::Bind(&SafeITunesPrefParserWin::StartWorkOnIOThread, this));
34 SafeITunesPrefParserWin::~SafeITunesPrefParserWin() {
37 void SafeITunesPrefParserWin::StartWorkOnIOThread() {
38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
39 DCHECK_EQ(INITIAL_STATE, parser_state_);
41 UtilityProcessHost* host =
42 UtilityProcessHost::Create(this, base::MessageLoopProxy::current());
43 host->Send(new ChromeUtilityMsg_ParseITunesPrefXml(unsafe_xml_));
44 parser_state_ = STARTED_PARSING_STATE;
47 void SafeITunesPrefParserWin::OnGotITunesDirectory(
48 const base::FilePath& library_file) {
49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
51 if (parser_state_ != STARTED_PARSING_STATE)
52 return;
53 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
54 base::Bind(callback_, library_file));
55 parser_state_ = FINISHED_PARSING_STATE;
58 void SafeITunesPrefParserWin::OnProcessCrashed(int exit_code) {
59 OnGotITunesDirectory(base::FilePath());
62 bool SafeITunesPrefParserWin::OnMessageReceived(
63 const IPC::Message& message) {
64 bool handled = true;
65 IPC_BEGIN_MESSAGE_MAP(SafeITunesPrefParserWin, message)
66 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GotITunesDirectory,
67 OnGotITunesDirectory)
68 IPC_MESSAGE_UNHANDLED(handled = false)
69 IPC_END_MESSAGE_MAP()
70 return handled;
73 } // namespace itunes