Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(385)

Side by Side Diff: chrome/browser/media_galleries/fileapi/safe_picasa_albums_indexer.h

Issue 18562007: Media Galleries API Picasa: Put INI indexing step into sandboxed utility process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@0035-picasa-import-sandbox-pmp-reading
Patch Set: Add success flag that's false when utility process crashes. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <queue>
9 #include <vector>
9 10
10 #include "base/callback.h" 11 #include "base/callback.h"
11 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
12 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
13 #include "chrome/common/media_galleries/picasa_types.h" 14 #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" 15 #include "content/public/browser/utility_process_host_client.h"
16 16
17 namespace base { 17 namespace base {
18 class FilePath; 18 class FilePath;
19 } 19 }
20 20
21 namespace IPC { 21 namespace IPC {
22 class Message; 22 class Message;
23 } 23 }
24 24
25 namespace picasa { 25 namespace picasa {
26 26
27 // SafePicasaAlbumTableReader parses the given Picasa PMP Album Table safely 27 // SafePicasaAlbumsIndexer indexes the contents of Picasa Albums by parsing the
28 // via a utility process. The SafePicasaAlbumTableReader object is ref-counted 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. 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 SafePicasaAlbumsIndexer : public content::UtilityProcessHostClient {
33 public: 33 public:
34 typedef base::Callback<void(bool, 34 typedef base::Callback<void(bool success,
Lei Zhang 2013/07/22 21:02:44 You should either name both callback parameters or
tommycli 2013/07/25 17:02:51 Done.
35 const std::vector<AlbumInfo>&, 35 const picasa::AlbumImagesMap&)> DoneCallback;
36 const std::vector<AlbumInfo>&)> ParserCallback;
37 36
38 SafePicasaAlbumTableReader(const AlbumTableFiles& album_table_files, 37 SafePicasaAlbumsIndexer(const AlbumMap& albums,
39 const ParserCallback& callback); 38 const AlbumMap& folders,
39 const DoneCallback& callback);
40 40
41 void Start(); 41 void Start();
42 42
43 private: 43 private:
44 enum ParserState { 44 enum ParserState {
45 INITIAL_STATE, 45 INITIAL_STATE,
46 PINGED_UTILITY_PROCESS_STATE, 46 STARTED_READING_INI_FILES_STATE,
47 FINISHED_READING_INI_FILES_STATE,
47 STARTED_PARSING_STATE, 48 STARTED_PARSING_STATE,
48 FINISHED_PARSING_STATE, 49 FINISHED_PARSING_STATE,
49 }; 50 };
50 51
51 // Private because content::UtilityProcessHostClient is ref-counted. 52 // Private because content::UtilityProcessHostClient is ref-counted.
52 virtual ~SafePicasaAlbumTableReader(); 53 virtual ~SafePicasaAlbumsIndexer();
54
55 // Processes a batch of folders. Reposts itself until done, then starts IPC.
56 void ProcessFoldersBatch();
53 57
54 // Launches the utility process. Must run on the IO thread. 58 // Launches the utility process. Must run on the IO thread.
55 void StartWorkOnIOThread(); 59 void StartWorkOnIOThread();
56 60
57 // Notification that the utility process is running, and we can now get its 61 // Notification from the utility process when it finshes indexing all the
58 // process handle. 62 // album contents. On error will return an empty map.
59 // Runs on the IO thread. 63 // Runs on the IO thread.
60 void OnProcessStarted(); 64 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 65
69 // UtilityProcessHostClient implementation. 66 // UtilityProcessHostClient implementation.
70 // Runs on the IO thread. 67 // Runs on the IO thread.
71 virtual void OnProcessCrashed(int exit_code) OVERRIDE; 68 virtual void OnProcessCrashed(int exit_code) OVERRIDE;
72 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 69 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
73 70
74 const AlbumTableFiles album_table_files_; 71 AlbumUIDSet album_uids_;
75 72
76 // Only accessed on the IO thread. 73 // List of folders that still need their INI files read.
77 base::WeakPtr<content::UtilityProcessHost> utility_process_host_; 74 std::queue<base::FilePath> folders_queue_;
75
76 std::vector<picasa::FolderINIContents> folders_inis_;
78 77
79 // Only accessed on the Media Task Runner. 78 // Only accessed on the Media Task Runner.
80 const ParserCallback callback_; 79 const DoneCallback callback_;
81 80
82 // Verifies the messages from the utility process came at the right time. 81 // 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. 82 // Initialized on the Media Task Runner, but only accessed on the IO thread.
Lei Zhang 2013/07/22 21:02:44 This comment is no longer true. |parser_state_| is
tommycli 2013/07/25 17:02:51 Done.
84 ParserState parser_state_; 83 ParserState parser_state_;
85 84
86 DISALLOW_COPY_AND_ASSIGN(SafePicasaAlbumTableReader); 85 base::WeakPtrFactory<SafePicasaAlbumsIndexer> weak_factory_;
86
87 DISALLOW_COPY_AND_ASSIGN(SafePicasaAlbumsIndexer);
87 }; 88 };
88 89
89 } // namespace picasa 90 } // namespace picasa
90 91
91 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_PICASA_ALBUM_TABLE_READER _H_ 92 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_PICASA_ALBUMS_INDEXER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698