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
;
20 SafeITunesPrefParserWin::SafeITunesPrefParserWin(
21 const std::string
& unsafe_xml
,
22 const ParserCallback
& callback
)
23 : unsafe_xml_(unsafe_xml
),
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(
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
)
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
) {
71 IPC_BEGIN_MESSAGE_MAP(SafeITunesPrefParserWin
, message
)
72 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GotITunesDirectory
,
74 IPC_MESSAGE_UNHANDLED(handled
= false)