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_ALBUMS_INDEXER_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_PICASA_ALBUMS_INDEXER_H_ |
6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_PICASA_ALBUMS_INDEXER_H_ | 6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_PICASA_ALBUMS_INDEXER_H_ |
7 | 7 |
8 #include <queue> | 8 #include <queue> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/memory/ref_counted.h" |
13 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
14 #include "chrome/common/media_galleries/picasa_types.h" | 15 #include "chrome/common/media_galleries/picasa_types.h" |
| 16 #include "content/public/browser/utility_process_host.h" |
15 #include "content/public/browser/utility_process_host_client.h" | 17 #include "content/public/browser/utility_process_host_client.h" |
16 | 18 |
17 namespace base { | 19 namespace base { |
18 class FilePath; | 20 class FilePath; |
19 } | 21 } |
20 | 22 |
21 namespace IPC { | 23 namespace IPC { |
22 class Message; | 24 class Message; |
23 } | 25 } |
24 | 26 |
25 namespace picasa { | 27 namespace picasa { |
26 | 28 |
27 // SafePicasaAlbumsIndexer indexes the contents of Picasa Albums by parsing the | 29 // SafePicasaAlbumsIndexer indexes the contents of Picasa Albums by parsing the |
28 // INI files found in Folders. The SafePicasaAlbumsIndexer object is ref-counted | 30 // INI files found in Folders. The SafePicasaAlbumsIndexer object is ref-counted |
29 // and kept alive after Start() is called until the ParserCallback is called. | 31 // and kept alive after Start() is called until the ParserCallback is called. |
30 // The ParserCallback is guaranteed to be called eventually either when the | 32 // The ParserCallback is guaranteed to be called eventually either when the |
31 // utility process replies or when it dies. | 33 // utility process replies or when it dies. |
32 class SafePicasaAlbumsIndexer : public content::UtilityProcessHostClient { | 34 class SafePicasaAlbumsIndexer : public content::UtilityProcessHostClient { |
33 public: | 35 public: |
34 typedef base::Callback<void(const picasa::AlbumImagesMap&)> DoneCallback; | 36 // Callback includes a refptr to itself to guarantee that this object |
| 37 // survives past the execution of its last posted callback. |
| 38 typedef base::Callback<void(scoped_refptr<SafePicasaAlbumsIndexer>, |
| 39 const picasa::AlbumImagesMap&)> DoneCallback; |
35 | 40 |
36 SafePicasaAlbumsIndexer(const AlbumMap& albums, | 41 SafePicasaAlbumsIndexer(const AlbumMap& albums, |
37 const AlbumMap& folders, | 42 const AlbumMap& folders, |
38 const DoneCallback& callback); | 43 const DoneCallback& callback); |
39 | 44 |
40 void Start(); | 45 void Start(); |
41 | 46 |
42 private: | 47 private: |
43 enum ParserState { | 48 enum ParserState { |
44 INITIAL_STATE, | 49 INITIAL_STATE, |
(...skipping 22 matching lines...) Expand all Loading... |
67 virtual void OnProcessCrashed(int exit_code) OVERRIDE; | 72 virtual void OnProcessCrashed(int exit_code) OVERRIDE; |
68 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 73 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
69 | 74 |
70 AlbumUIDSet album_uids_; | 75 AlbumUIDSet album_uids_; |
71 | 76 |
72 // List of folders that still need their INI files read. | 77 // List of folders that still need their INI files read. |
73 std::queue<base::FilePath> folders_queue_; | 78 std::queue<base::FilePath> folders_queue_; |
74 | 79 |
75 std::vector<picasa::FolderINIContents> folders_inis_; | 80 std::vector<picasa::FolderINIContents> folders_inis_; |
76 | 81 |
| 82 // Only accessed on the IO thread. |
| 83 base::WeakPtr<content::UtilityProcessHost> utility_process_host_; |
| 84 |
77 // Only accessed on the Media Task Runner. | 85 // Only accessed on the Media Task Runner. |
78 const DoneCallback callback_; | 86 const DoneCallback callback_; |
79 | 87 |
80 // Verifies the messages from the utility process came at the right time. | 88 // Verifies the messages from the utility process came at the right time. |
81 // Initialized on the Media Task Runner, but only accessed on the IO thread. | 89 // Initialized on the Media Task Runner, but only accessed on the IO thread. |
82 ParserState parser_state_; | 90 ParserState parser_state_; |
83 | 91 |
84 base::WeakPtrFactory<SafePicasaAlbumsIndexer> weak_factory_; | 92 base::WeakPtrFactory<SafePicasaAlbumsIndexer> weak_factory_; |
85 | 93 |
86 DISALLOW_COPY_AND_ASSIGN(SafePicasaAlbumsIndexer); | 94 DISALLOW_COPY_AND_ASSIGN(SafePicasaAlbumsIndexer); |
87 }; | 95 }; |
88 | 96 |
89 } // namespace picasa | 97 } // namespace picasa |
90 | 98 |
91 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_PICASA_ALBUMS_INDEXER_H_ | 99 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_PICASA_ALBUMS_INDEXER_H_ |
OLD | NEW |