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

Unified Diff: chrome/utility/extensions/extensions_handler.cc

Issue 2611283002: [mojo talk demo] Convert utility process CheckMediaFile IPC to mojo (Closed)
Patch Set: Created 3 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
« no previous file with comments | « chrome/utility/extensions/extensions_handler.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/utility/extensions/extensions_handler.cc
diff --git a/chrome/utility/extensions/extensions_handler.cc b/chrome/utility/extensions/extensions_handler.cc
index 787a8b9ef20161ec71ea57e28608859ad392c90b..7b4afeff68c31ef277744e40ac2ca52acfc14865 100644
--- a/chrome/utility/extensions/extensions_handler.cc
+++ b/chrome/utility/extensions/extensions_handler.cc
@@ -12,6 +12,7 @@
#include "chrome/common/chrome_utility_messages.h"
#include "chrome/common/extensions/chrome_extensions_client.h"
#include "chrome/common/extensions/chrome_utility_extensions_messages.h"
+#include "chrome/common/extensions/media_parser.mojom.h"
#include "chrome/common/media_galleries/metadata_types.h"
#include "chrome/utility/chrome_content_utility_client.h"
#include "chrome/utility/media_galleries/ipc_data_source.h"
@@ -22,6 +23,8 @@
#include "extensions/common/extension_utility_messages.h"
#include "extensions/utility/unpacker.h"
#include "media/base/media.h"
+#include "mojo/public/cpp/bindings/strong_binding.h"
+#include "services/service_manager/public/cpp/interface_registry.h"
#include "ui/base/ui_base_switches.h"
#if !defined(MEDIA_DISABLE_FFMPEG)
@@ -61,6 +64,39 @@ void FinishParseMediaMetadata(
ReleaseProcessIfNeeded();
}
+class MediaParserImpl : public extensions::mojom::MediaParser {
+ public:
+ MediaParserImpl() = default;
+ ~MediaParserImpl() override = default;
+
+ static void Create(extensions::mojom::MediaParserRequest request) {
+ mojo::MakeStrongBinding(base::MakeUnique<MediaParserImpl>(),
+ std::move(request));
+ }
+
+ private:
+ // extensions::mojom::MediaParser:
+ void CheckMediaFile(int64_t decode_time_ms,
+ base::File file,
+ const CheckMediaFileCallback& callback) override {
+#if !defined(MEDIA_DISABLE_FFMPEG)
+ media::MediaFileChecker checker(std::move(file));
+ const bool check_success =
+ checker.Start(base::TimeDelta::FromMilliseconds(decode_time_ms));
+ callback.Run(check_success);
+#else
+ callback.Run(false);
+#endif
+ // Caller is based on UtilityProcessHostClient and expects the
+ // utility process to manage its own lifetime. TODO(noel): use
+ // utility_process_mojo_client at the call-site to avoid the
+ // need for this release call.
+ ReleaseProcessIfNeeded();
+ }
+
+ DISALLOW_COPY_AND_ASSIGN(MediaParserImpl);
+};
+
} // namespace
ExtensionsHandler::ExtensionsHandler(ChromeContentUtilityClient* utility_client)
@@ -77,10 +113,21 @@ void ExtensionsHandler::PreSandboxStartup() {
media::InitializeMediaLibrary();
}
+// static
+void ExtensionsHandler::ExposeInterfacesToBrowser(
+ service_manager::InterfaceRegistry* registry,
+ bool running_elevated) {
+ // If our process runs with elevated privileges, only add elevated
+ // Mojo services to the service_manager::InterfaceRegistry.
+ if (running_elevated)
+ return;
+
+ registry->AddInterface(base::Bind(&MediaParserImpl::Create));
+}
+
bool ExtensionsHandler::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(ExtensionsHandler, message)
- IPC_MESSAGE_HANDLER(ChromeUtilityMsg_CheckMediaFile, OnCheckMediaFile)
IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseMediaMetadata,
OnParseMediaMetadata)
@@ -108,21 +155,6 @@ bool ExtensionsHandler::OnMessageReceived(const IPC::Message& message) {
return handled || utility_handler_.OnMessageReceived(message);
}
-void ExtensionsHandler::OnCheckMediaFile(
- int64_t milliseconds_of_decoding,
- const IPC::PlatformFileForTransit& media_file) {
-#if !defined(MEDIA_DISABLE_FFMPEG)
- media::MediaFileChecker checker(
- IPC::PlatformFileForTransitToFile(media_file));
- const bool check_success = checker.Start(
- base::TimeDelta::FromMilliseconds(milliseconds_of_decoding));
- Send(new ChromeUtilityHostMsg_CheckMediaFile_Finished(check_success));
-#else
- Send(new ChromeUtilityHostMsg_CheckMediaFile_Finished(false));
-#endif
- ReleaseProcessIfNeeded();
-}
-
void ExtensionsHandler::OnParseMediaMetadata(const std::string& mime_type,
int64_t total_size,
bool get_attached_images) {
« no previous file with comments | « chrome/utility/extensions/extensions_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698