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 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_ITUNES_PREF_PARSER_WIN_H_
6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_ITUNES_PREF_PARSER_WIN_H_
10 #include "base/callback.h"
11 #include "base/compiler_specific.h"
12 #include "content/public/browser/utility_process_host_client.h"
24 // SafeITunesPrefParserWin parses the given iTunes preferences XML data safely
25 // via a utility process. The SafeITunesPrefParserWin object is ref-counted and
26 // kept alive after Start() is called until the ParserCallback is called.
27 // The ParserCallback is guaranteed to be called eventually either when the
28 // utility process replies or when it dies.
29 class SafeITunesPrefParserWin
: public content::UtilityProcessHostClient
{
31 typedef base::Callback
<void(const base::FilePath
&)> ParserCallback
;
33 SafeITunesPrefParserWin(const std::string
& unsafe_xml
,
34 const ParserCallback
& callback
);
41 STARTED_PARSING_STATE
,
42 FINISHED_PARSING_STATE
,
45 // Private because content::UtilityProcessHostClient is ref-counted.
46 virtual ~SafeITunesPrefParserWin();
48 void StartWorkOnIOThread();
50 // Handles the results from OnProcessCrashed() and OnMessageReceived() on
52 void OnGotITunesDirectory(const base::FilePath
& library_file
);
54 // UtilityProcessHostClient implementation.
55 virtual void OnProcessCrashed(int exit_code
) OVERRIDE
;
56 virtual bool OnMessageReceived(const IPC::Message
& message
) OVERRIDE
;
58 const std::string unsafe_xml_
;
59 const ParserCallback callback_
;
61 // Verifies the messages from the utility process came at the right time.
62 // Initialized on the FILE thread, but only accessed on the IO thread.
63 ParserState parser_state_
;
65 DISALLOW_COPY_AND_ASSIGN(SafeITunesPrefParserWin
);
70 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_ITUNES_PREF_PARSER_WIN_H_