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_ALBUMS_INDEXER_H_ |
6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_PICASA_ALBUM_TABLE_READER_H_ | 6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_PICASA_ALBUMS_INDEXER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "chrome/common/media_galleries/picasa_types.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" | 14 #include "content/public/browser/utility_process_host_client.h" |
16 | 15 |
17 namespace base { | 16 namespace base { |
18 class FilePath; | 17 class FilePath; |
19 } | 18 } |
20 | 19 |
21 namespace IPC { | 20 namespace IPC { |
22 class Message; | 21 class Message; |
23 } | 22 } |
24 | 23 |
25 namespace picasa { | 24 namespace picasa { |
26 | 25 |
27 // SafePicasaAlbumTableReader parses the given Picasa PMP Album Table safely | 26 // SafePicasaAlbumsIndexer indexes the contents of Picasa Albums by parsing the |
28 // via a utility process. The SafePicasaAlbumTableReader object is ref-counted | 27 // INI files fond in Folders. The SafePicasaAlbumsIndexer object is ref-counted |
Lei Zhang
2013/07/02 22:08:17
typo
tommycli
2013/07/03 00:58:28
Done.
| |
29 // and kept alive after Start() is called until the ParserCallback is called. | 28 // and kept alive after Start() is called until the ParserCallback is called. |
30 // The ParserCallback is guaranteed to be called eventually either when the | 29 // The ParserCallback is guaranteed to be called eventually either when the |
31 // utility process replies or when it dies. | 30 // utility process replies or when it dies. |
32 class SafePicasaAlbumTableReader : public content::UtilityProcessHostClient { | 31 class SafePicasaAlbumsIndexer : public content::UtilityProcessHostClient { |
33 public: | 32 public: |
34 typedef base::Callback<void(bool, | 33 typedef base::Callback<void(picasa::AlbumImagesMap)> ParserCallback; |
35 const std::vector<AlbumInfo>&, | |
36 const std::vector<AlbumInfo>&)> ParserCallback; | |
37 | 34 |
38 SafePicasaAlbumTableReader(const AlbumTableFiles& album_table_files, | 35 SafePicasaAlbumsIndexer(const AlbumMap& albums, |
39 const ParserCallback& callback); | 36 const AlbumMap& folders, |
37 const ParserCallback& callback); | |
40 | 38 |
41 void Start(); | 39 void Start(); |
42 | 40 |
43 private: | 41 private: |
44 enum ParserState { | 42 enum ParserState { |
45 INITIAL_STATE, | 43 INITIAL_STATE, |
46 PINGED_UTILITY_PROCESS_STATE, | |
47 STARTED_PARSING_STATE, | 44 STARTED_PARSING_STATE, |
48 FINISHED_PARSING_STATE, | 45 FINISHED_PARSING_STATE, |
49 }; | 46 }; |
50 | 47 |
51 // Private because content::UtilityProcessHostClient is ref-counted. | 48 // Private because content::UtilityProcessHostClient is ref-counted. |
52 virtual ~SafePicasaAlbumTableReader(); | 49 virtual ~SafePicasaAlbumsIndexer(); |
53 | 50 |
54 // Launches the utility process. Must run on the IO thread. | 51 // Launches the utility process. Must run on the IO thread. |
55 void StartWorkOnIOThread(); | 52 void StartWorkOnIOThread(); |
56 | 53 |
57 // Notification that the utility process is running, and we can now get its | 54 // Notification from the utility process when it finshes indexing all the |
58 // process handle. | 55 // album contents. On error will return an empty map. |
59 // Runs on the IO thread. | 56 // Runs on the IO thread. |
60 void OnProcessStarted(); | 57 void OnIndexPicasaAlbumsContentsFinished(const AlbumImagesMap& albums_images); |
61 | |
62 // Notification from the utility process when it finshes parsing the PMP | |
63 // database. This is received even if PMP parsing fails. | |
64 // Runs on the IO thread. | |
65 void OnParsePicasaPMPDatabaseFinished(bool parse_success, | |
66 const std::vector<AlbumInfo>& albums, | |
67 const std::vector<AlbumInfo>& folders); | |
68 | 58 |
69 // UtilityProcessHostClient implementation. | 59 // UtilityProcessHostClient implementation. |
70 // Runs on the IO thread. | 60 // Runs on the IO thread. |
71 virtual void OnProcessCrashed(int exit_code) OVERRIDE; | 61 virtual void OnProcessCrashed(int exit_code) OVERRIDE; |
72 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 62 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
73 | 63 |
74 const AlbumTableFiles album_table_files_; | 64 AlbumUIDSet album_uids_; |
75 | 65 std::set<base::FilePath> folder_paths_; |
76 // Only accessed on the IO thread. | |
77 base::WeakPtr<content::UtilityProcessHost> utility_process_host_; | |
78 | 66 |
79 // Only accessed on the Media Task Runner. | 67 // Only accessed on the Media Task Runner. |
80 const ParserCallback callback_; | 68 const ParserCallback callback_; |
81 | 69 |
82 // Verifies the messages from the utility process came at the right time. | 70 // 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. | 71 // Initialized on the Media Task Runner, but only accessed on the IO thread. |
84 ParserState parser_state_; | 72 ParserState parser_state_; |
85 | 73 |
86 DISALLOW_COPY_AND_ASSIGN(SafePicasaAlbumTableReader); | 74 DISALLOW_COPY_AND_ASSIGN(SafePicasaAlbumsIndexer); |
87 }; | 75 }; |
88 | 76 |
89 } // namespace picasa | 77 } // namespace picasa |
90 | 78 |
91 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_PICASA_ALBUM_TABLE_READER _H_ | 79 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_PICASA_ALBUMS_INDEXER_H_ |
OLD | NEW |