Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / chrome / browser / media_galleries / fileapi / safe_picasa_album_table_reader.h
blob139f17f90b773bf6abdbcc93c5bf11a247b38034
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_PICASA_ALBUM_TABLE_READER_H_
6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_PICASA_ALBUM_TABLE_READER_H_
8 #include <string>
10 #include "base/callback.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/weak_ptr.h"
13 #include "chrome/common/media_galleries/picasa_types.h"
14 #include "content/public/browser/utility_process_host.h"
15 #include "content/public/browser/utility_process_host_client.h"
17 namespace base {
18 class FilePath;
21 namespace IPC {
22 class Message;
25 namespace picasa {
27 // SafePicasaAlbumTableReader parses the given Picasa PMP Album Table safely
28 // via a utility process. The SafePicasaAlbumTableReader object is ref-counted
29 // and kept alive after Start() is called until the ParserCallback is called.
30 // The ParserCallback is guaranteed to be called eventually either when the
31 // utility process replies or when it dies.
32 class SafePicasaAlbumTableReader : public content::UtilityProcessHostClient {
33 public:
34 typedef base::Callback<void(bool parse_success,
35 const std::vector<AlbumInfo>&,
36 const std::vector<AlbumInfo>&)>
37 ParserCallback;
39 // This class takes ownership of |album_table_files| and will close them.
40 explicit SafePicasaAlbumTableReader(AlbumTableFiles album_table_files);
42 void Start(const ParserCallback& callback);
44 private:
45 enum ParserState {
46 INITIAL_STATE,
47 PINGED_UTILITY_PROCESS_STATE,
48 STARTED_PARSING_STATE,
49 FINISHED_PARSING_STATE,
52 // Private because content::UtilityProcessHostClient is ref-counted.
53 ~SafePicasaAlbumTableReader() override;
55 // Launches the utility process. Must run on the IO thread.
56 void StartWorkOnIOThread();
58 // Notification that the utility process is running, and we can now get its
59 // process handle.
60 // Runs on the IO thread.
61 void OnProcessStarted();
63 // Notification from the utility process when it finshes parsing the PMP
64 // database. This is received even if PMP parsing fails.
65 // Runs on the IO thread.
66 void OnParsePicasaPMPDatabaseFinished(bool parse_success,
67 const std::vector<AlbumInfo>& albums,
68 const std::vector<AlbumInfo>& folders);
70 // UtilityProcessHostClient implementation.
71 // Runs on the IO thread.
72 void OnProcessCrashed(int exit_code) override;
73 bool OnMessageReceived(const IPC::Message& message) override;
75 AlbumTableFiles album_table_files_;
77 // Only accessed on the IO thread.
78 base::WeakPtr<content::UtilityProcessHost> utility_process_host_;
80 // Only accessed on the Media Task Runner.
81 ParserCallback callback_;
83 // Verifies the messages from the utility process came at the right time.
84 // Initialized on the Media Task Runner, but only accessed on the IO thread.
85 ParserState parser_state_;
87 DISALLOW_COPY_AND_ASSIGN(SafePicasaAlbumTableReader);
90 } // namespace picasa
92 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_PICASA_ALBUM_TABLE_READER_H_