Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / media_galleries / fileapi / safe_itunes_pref_parser_win.h
blob0777c64ab13c6f0db0b2e473f885d1e13af12402
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_
8 #include <string>
10 #include "base/callback.h"
11 #include "base/compiler_specific.h"
12 #include "content/public/browser/utility_process_host_client.h"
14 namespace base {
15 class FilePath;
18 namespace IPC {
19 class Message;
22 namespace itunes {
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 {
30 public:
31 typedef base::Callback<void(const base::FilePath&)> ParserCallback;
33 SafeITunesPrefParserWin(const std::string& unsafe_xml,
34 const ParserCallback& callback);
36 void Start();
38 private:
39 enum ParserState {
40 INITIAL_STATE,
41 STARTED_PARSING_STATE,
42 FINISHED_PARSING_STATE,
45 // Private because content::UtilityProcessHostClient is ref-counted.
46 ~SafeITunesPrefParserWin() override;
48 void StartWorkOnIOThread();
50 // Handles the results from OnProcessCrashed() and OnMessageReceived() on
51 // the IO thread.
52 void OnGotITunesDirectory(const base::FilePath& library_file);
54 // UtilityProcessHostClient implementation.
55 void OnProcessCrashed(int exit_code) override;
56 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);
68 } // namespace itunes
70 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_ITUNES_PREF_PARSER_WIN_H_