OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_PICASA_ALBUM_TABLE_READER_H_ | 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_ | 6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_PICASA_ALBUM_TABLE_READER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 namespace picasa { | 25 namespace picasa { |
26 | 26 |
27 // SafePicasaAlbumTableReader parses the given Picasa PMP Album Table safely | 27 // SafePicasaAlbumTableReader parses the given Picasa PMP Album Table safely |
28 // via a utility process. The SafePicasaAlbumTableReader object is ref-counted | 28 // via a utility process. The SafePicasaAlbumTableReader object is ref-counted |
29 // and kept alive after Start() is called until the ParserCallback is called. | 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 | 30 // The ParserCallback is guaranteed to be called eventually either when the |
31 // utility process replies or when it dies. | 31 // utility process replies or when it dies. |
32 class SafePicasaAlbumTableReader : public content::UtilityProcessHostClient { | 32 class SafePicasaAlbumTableReader : public content::UtilityProcessHostClient { |
33 public: | 33 public: |
34 typedef base::Callback<void(bool, | 34 typedef base::Callback<void(bool parse_success, |
35 const std::vector<AlbumInfo>&, | 35 const std::vector<AlbumInfo>&, |
36 const std::vector<AlbumInfo>&)> ParserCallback; | 36 const std::vector<AlbumInfo>&)> |
| 37 ParserCallback; |
37 | 38 |
38 SafePicasaAlbumTableReader(const AlbumTableFiles& album_table_files, | 39 explicit SafePicasaAlbumTableReader(const AlbumTableFiles& album_table_files); |
39 const ParserCallback& callback); | |
40 | 40 |
41 void Start(); | 41 void Start(const ParserCallback& callback); |
42 | 42 |
43 private: | 43 private: |
44 enum ParserState { | 44 enum ParserState { |
45 INITIAL_STATE, | 45 INITIAL_STATE, |
46 PINGED_UTILITY_PROCESS_STATE, | 46 PINGED_UTILITY_PROCESS_STATE, |
47 STARTED_PARSING_STATE, | 47 STARTED_PARSING_STATE, |
48 FINISHED_PARSING_STATE, | 48 FINISHED_PARSING_STATE, |
49 }; | 49 }; |
50 | 50 |
51 // Private because content::UtilityProcessHostClient is ref-counted. | 51 // Private because content::UtilityProcessHostClient is ref-counted. |
(...skipping 18 matching lines...) Expand all Loading... |
70 // Runs on the IO thread. | 70 // Runs on the IO thread. |
71 virtual void OnProcessCrashed(int exit_code) OVERRIDE; | 71 virtual void OnProcessCrashed(int exit_code) OVERRIDE; |
72 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 72 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
73 | 73 |
74 const AlbumTableFiles album_table_files_; | 74 const AlbumTableFiles album_table_files_; |
75 | 75 |
76 // Only accessed on the IO thread. | 76 // Only accessed on the IO thread. |
77 base::WeakPtr<content::UtilityProcessHost> utility_process_host_; | 77 base::WeakPtr<content::UtilityProcessHost> utility_process_host_; |
78 | 78 |
79 // Only accessed on the Media Task Runner. | 79 // Only accessed on the Media Task Runner. |
80 const ParserCallback callback_; | 80 ParserCallback callback_; |
81 | 81 |
82 // Verifies the messages from the utility process came at the right time. | 82 // Verifies the messages from the utility process came at the right time. |
83 // Initialized on the Media Task Runner, but only accessed on the IO thread. | 83 // Initialized on the Media Task Runner, but only accessed on the IO thread. |
84 ParserState parser_state_; | 84 ParserState parser_state_; |
85 | 85 |
86 DISALLOW_COPY_AND_ASSIGN(SafePicasaAlbumTableReader); | 86 DISALLOW_COPY_AND_ASSIGN(SafePicasaAlbumTableReader); |
87 }; | 87 }; |
88 | 88 |
89 } // namespace picasa | 89 } // namespace picasa |
90 | 90 |
91 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_PICASA_ALBUM_TABLE_READER
_H_ | 91 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_PICASA_ALBUM_TABLE_READER
_H_ |
OLD | NEW |