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_ALBUMS_INDEXER_H_
6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_PICASA_ALBUMS_INDEXER_H_
11 #include "base/callback.h"
12 #include "base/compiler_specific.h"
13 #include "base/memory/weak_ptr.h"
14 #include "chrome/common/media_galleries/picasa_types.h"
15 #include "content/public/browser/utility_process_host_client.h"
27 // SafePicasaAlbumsIndexer indexes the contents of Picasa Albums by parsing the
28 // INI files found in Folders. The SafePicasaAlbumsIndexer 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 SafePicasaAlbumsIndexer
: public content::UtilityProcessHostClient
{
34 typedef base::Callback
<
35 void(bool parse_success
, const picasa::AlbumImagesMap
&)>
38 SafePicasaAlbumsIndexer(const AlbumMap
& albums
, const AlbumMap
& folders
);
40 void Start(const DoneCallback
& callback
);
45 STARTED_PARSING_STATE
,
46 FINISHED_PARSING_STATE
,
49 // Private because content::UtilityProcessHostClient is ref-counted.
50 virtual ~SafePicasaAlbumsIndexer();
52 // Processes a batch of folders. Reposts itself until done, then starts IPC.
53 void ProcessFoldersBatch();
55 // Launches the utility process. Must run on the IO thread.
56 void StartWorkOnIOThread();
58 // Notification from the utility process when it finshes indexing all the
59 // album contents. On error will return an empty map.
60 // Runs on the IO thread.
61 void OnIndexPicasaAlbumsContentsFinished(const AlbumImagesMap
& albums_images
);
63 // UtilityProcessHostClient implementation.
64 // Runs on the IO thread.
65 virtual void OnProcessCrashed(int exit_code
) OVERRIDE
;
66 virtual bool OnMessageReceived(const IPC::Message
& message
) OVERRIDE
;
68 AlbumUIDSet album_uids_
;
70 // List of folders that still need their INI files read.
71 std::queue
<base::FilePath
> folders_queue_
;
73 std::vector
<picasa::FolderINIContents
> folders_inis_
;
75 // Only accessed on the Media Task Runner.
76 DoneCallback callback_
;
78 // Verifies the messages from the utility process came at the right time.
79 // Initialized on the Media Task Runner, but only accessed on the IO thread.
80 ParserState parser_state_
;
82 DISALLOW_COPY_AND_ASSIGN(SafePicasaAlbumsIndexer
);
87 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_PICASA_ALBUMS_INDEXER_H_