Chromium Code Reviews| Index: chrome/browser/media_galleries/fileapi/safe_media_metadata_parser.h |
| diff --git a/chrome/browser/media_galleries/fileapi/safe_media_metadata_parser.h b/chrome/browser/media_galleries/fileapi/safe_media_metadata_parser.h |
| index dd33604372f6502320842c6aff4bd39a9bc57bc2..0d369920b808ab845c904dcdfe8f193a0f2bb548 100644 |
| --- a/chrome/browser/media_galleries/fileapi/safe_media_metadata_parser.h |
| +++ b/chrome/browser/media_galleries/fileapi/safe_media_metadata_parser.h |
| @@ -14,26 +14,23 @@ |
| #include "base/callback.h" |
| #include "base/compiler_specific.h" |
| #include "base/macros.h" |
| -#include "base/memory/weak_ptr.h" |
| +#include "base/memory/ref_counted.h" |
| #include "chrome/common/extensions/api/media_galleries.h" |
| #include "chrome/common/extensions/media_parser.mojom.h" |
| #include "chrome/common/media_galleries/metadata_types.h" |
| -#include "content/public/browser/utility_process_host.h" |
| -#include "content/public/browser/utility_process_host_client.h" |
| - |
| -namespace IPC { |
| -class Message; |
| -} |
| +#include "content/public/browser/utility_process_mojo_client.h" |
| class Profile; |
| namespace metadata { |
| -// Parses the media metadata of a Blob safely in a utility process. This class |
| -// expects the MIME type of the Blob to be already determined. It spawns a |
| -// utility process to do further MIME-type specific metadata extraction. |
| +// Parses the media metadata of a Blob safely in a utility process. This |
| +// class expects the MIME-type of the Blob to be already determined. It |
| +// creates a utility process to do further MIME-type specific metadata |
| +// extraction from the Blob data. |
| // All public methods and callbacks of this class run on the UI thread. |
| -class SafeMediaMetadataParser : public content::UtilityProcessHostClient { |
| +class SafeMediaMetadataParser |
| + : public base::RefCountedThreadSafe<SafeMediaMetadataParser> { |
| public: |
| // |metadata_dictionary| is owned by the callback. |
| typedef base::Callback<void( |
| @@ -51,15 +48,13 @@ class SafeMediaMetadataParser : public content::UtilityProcessHostClient { |
| // Should be called on the UI thread. |callback| also runs on the UI thread. |
| void Start(const DoneCallback& callback); |
| - private: |
| - enum ParserState { |
| - INITIAL_STATE, |
| - STARTED_PARSING_STATE, |
| - FINISHED_PARSING_STATE, |
| - }; |
| + protected: |
| + friend class base::RefCountedThreadSafe<SafeMediaMetadataParser>; |
| - // Private because content::UtilityProcessHostClient is ref-counted. |
| - ~SafeMediaMetadataParser() override; |
| + virtual ~SafeMediaMetadataParser(); |
|
Sam McNally
2017/02/03 22:14:16
Why is this protected and virtual instead of priva
Noel Gordon
2017/02/05 23:45:03
It could be done either way. I picked they way we
Sam McNally
2017/02/06 00:03:38
In this case the destructor appears to be the only
|
| + |
| + private: |
| + class MediaDataSourceImpl; |
| // Launches the utility process. Must run on the IO thread. |
| void StartWorkOnIOThread(const DoneCallback& callback); |
| @@ -77,21 +72,25 @@ class SafeMediaMetadataParser : public content::UtilityProcessHostClient { |
| // Sequence of functions that bounces from the IO thread to the UI thread to |
| // read the blob data, then sends the data back to the utility process. |
| - void OnUtilityProcessRequestBlobBytes(int64_t request_id, |
| - int64_t byte_start, |
| - int64_t length); |
| - void StartBlobReaderOnUIThread(int64_t request_id, |
| - int64_t byte_start, |
| - int64_t length); |
| - void OnBlobReaderDoneOnUIThread(int64_t request_id, |
| - std::unique_ptr<std::string> data, |
| - int64_t /* blob_total_size */); |
| - void FinishRequestBlobBytes(int64_t request_id, |
| - std::unique_ptr<std::string> data); |
| - |
| - // UtilityProcessHostClient implementation. |
| - // Runs on the IO thread. |
| - bool OnMessageReceived(const IPC::Message& message) override; |
| + void ProcessBlobRequest( |
| + const extensions::mojom::MediaDataSource::ReadBlobCallback& callback, |
| + int64_t request_id, |
| + int64_t position, |
| + int64_t length); |
| + void StartBlobReaderOnUIThread( |
| + const extensions::mojom::MediaDataSource::ReadBlobCallback& callback, |
| + int64_t request_id, |
| + int64_t position, |
| + int64_t length); |
| + void BlobReaderDoneOnUIThread( |
| + const extensions::mojom::MediaDataSource::ReadBlobCallback& callback, |
| + int64_t request_id, |
| + std::unique_ptr<std::string> data, |
| + int64_t /* blob_total_size */); |
| + void FinishBlobRequest( |
| + const extensions::mojom::MediaDataSource::ReadBlobCallback& callback, |
| + int64_t request_id, |
| + std::unique_ptr<std::string> data); |
| // All member variables are only accessed on the IO thread. |
| Profile* const profile_; |
| @@ -100,15 +99,13 @@ class SafeMediaMetadataParser : public content::UtilityProcessHostClient { |
| const std::string mime_type_; |
| bool get_attached_images_; |
| - DoneCallback callback_; |
| - |
| - base::WeakPtr<content::UtilityProcessHost> utility_process_host_; |
| + std::unique_ptr< |
| + content::UtilityProcessMojoClient<extensions::mojom::MediaParser>> |
| + utility_process_mojo_client_; |
| - extensions::mojom::MediaParserPtr interface_; |
| + std::unique_ptr<MediaDataSourceImpl> media_data_source_; |
| - // Verifies the messages from the utility process came at the right time. |
| - // Initialized on the UI thread, but only accessed on the IO thread. |
| - ParserState parser_state_; |
| + DoneCallback callback_; |
| DISALLOW_COPY_AND_ASSIGN(SafeMediaMetadataParser); |
| }; |