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

Unified Diff: chrome/browser/media_galleries/fileapi/safe_media_metadata_parser.h

Issue 103283003: Media Galleries API Metadata: SafeMediaMetadataParser and IPCTunnelDataReader. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix ownership issues Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
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
new file mode 100644
index 0000000000000000000000000000000000000000..31e4496f79154cc72e73aeefde38596876f676b3
--- /dev/null
+++ b/chrome/browser/media_galleries/fileapi/safe_media_metadata_parser.h
@@ -0,0 +1,94 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_MEDIA_METADATA_PARSER_H_
+#define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_MEDIA_METADATA_PARSER_H_
+
+#include "base/callback.h"
+#include "base/compiler_specific.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
+#include "chrome/common/extensions/api/media_galleries.h"
+#include "content/public/browser/utility_process_host.h"
+#include "content/public/browser/utility_process_host_client.h"
+
+namespace IPC {
+class Message;
+}
+
+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.
+// All public methods and callbacks of this class run on the UI thread.
+class SafeMediaMetadataParser : public content::UtilityProcessHostClient {
+ public:
+ typedef extensions::api::media_galleries::MediaMetadata MediaMetadata;
+
+ // Callback function should take ownership of |metadata|.
+ typedef base::Callback<
+ void(bool parse_success, scoped_ptr<MediaMetadata> metadata)>
+ DoneCallback;
+
+ SafeMediaMetadataParser(Profile* profile, const std::string& blob_uuid,
+ int64 blob_size, const std::string& mime_type);
+
+ // 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,
+ };
+
+ // Private because content::UtilityProcessHostClient is ref-counted.
+ virtual ~SafeMediaMetadataParser();
+
+ // Launches the utility process. Must run on the IO thread.
+ void StartWorkOnIOThread();
+
+ // Notification from the utility process when it finishes parsing metadata.
+ // Runs on the IO thread.
+ void OnParseMediaMetadataFinished(
+ bool parse_success,
+ const base::DictionaryValue& metadata_dictionary);
+
+ // Notification when the utility process requests a byte range from the blob.
+ // Runs on the IO thread.
+ void OnUtilityProcessRequestBlobBytes(int64 request_id, int64 byte_start,
+ int64 length);
+ // Completes the Blob byte request.
+ void OnBlobReaderDone(int64 request_id, scoped_ptr<std::string> data);
+
+ // UtilityProcessHostClient implementation.
+ // Runs on the IO thread.
+ virtual void OnProcessCrashed(int exit_code) OVERRIDE;
+ virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
+
+ Profile* profile_;
vandebo (ex-Chrome) 2014/01/07 18:34:59 Which thread are these accessed on?
tommycli 2014/01/07 20:23:31 Done.
+ std::string blob_uuid_;
vandebo (ex-Chrome) 2014/01/07 18:34:59 Can these be const ?
tommycli 2014/01/07 20:23:31 Done.
+ int64 blob_size_;
+ std::string mime_type_;
+
+ // Only accessed on the UI thread.
+ DoneCallback callback_;
+
+ // Only accessed on the IO thread.
+ base::WeakPtr<content::UtilityProcessHost> utility_process_host_;
+
+ // 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_;
+
+ DISALLOW_COPY_AND_ASSIGN(SafeMediaMetadataParser);
+};
+
+} // namespace metadata
+
+#endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_MEDIA_METADATA_PARSER_H_

Powered by Google App Engine
This is Rietveld 408576698