Commit fbc2f693 authored by Jay Civelli's avatar Jay Civelli Committed by Commit Bot

Make media::InitMediaLibrary work with the sandbox

Initializing the media library entails getting information about the CPU
for the libyuv and ffmep libraries. Retrieving that information might
access the file system (/cpu/procinfo). The extension handler code would
initialize the media library before the sandbox is turned on.
As part of the effort to move process launching to the service manager
where the service process is always sandboxed, this CL  adds a new
InitializeMediaLibraryInSandbox method that lets callers specify the CPU
info so the initialization can be done inside the sandbox.

The client library of the media gallery util service which was the
reason why extension handlers would need to initialize the media
library, now do it explicitly and provide the CPU info. As a result,
extension handlers related files can be removed.

Bug: 823931

Change-Id: Ie1630f3ff04c94901224750ffdea4423bd1b3186
Reviewed-on: https://chromium-review.googlesource.com/966925Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@chromium.org>
Commit-Queue: Jay Civelli <jcivelli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#549813}
parent 9d38f842
...@@ -890,11 +890,6 @@ void ChromeMainDelegate::PreSandboxStartup() { ...@@ -890,11 +890,6 @@ void ChromeMainDelegate::PreSandboxStartup() {
} }
#if !defined(CHROME_MULTIPLE_DLL_BROWSER) #if !defined(CHROME_MULTIPLE_DLL_BROWSER)
if (process_type == switches::kUtilityProcess ||
process_type == switches::kZygoteProcess) {
ChromeContentUtilityClient::PreSandboxStartup();
}
InitializePDF(); InitializePDF();
#endif #endif
......
...@@ -130,7 +130,7 @@ void SupportedAudioVideoChecker::OnFileOpen( ...@@ -130,7 +130,7 @@ void SupportedAudioVideoChecker::OnFileOpen(
return; return;
} }
safe_checker_ = new SafeAudioVideoChecker(std::move(file), callback_, safe_checker_ = std::make_unique<SafeAudioVideoChecker>(
std::move(connector)); std::move(file), callback_, std::move(connector));
safe_checker_->Start(); safe_checker_->Start();
} }
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "base/files/file.h" #include "base/files/file.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "chrome/browser/media_galleries/fileapi/av_scanning_file_validator.h" #include "chrome/browser/media_galleries/fileapi/av_scanning_file_validator.h"
...@@ -50,7 +49,7 @@ class SupportedAudioVideoChecker : public AVScanningFileValidator { ...@@ -50,7 +49,7 @@ class SupportedAudioVideoChecker : public AVScanningFileValidator {
base::FilePath path_; base::FilePath path_;
storage::CopyOrMoveFileValidator::ResultCallback callback_; storage::CopyOrMoveFileValidator::ResultCallback callback_;
scoped_refptr<SafeAudioVideoChecker> safe_checker_; std::unique_ptr<SafeAudioVideoChecker> safe_checker_;
base::WeakPtrFactory<SupportedAudioVideoChecker> weak_factory_; base::WeakPtrFactory<SupportedAudioVideoChecker> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(SupportedAudioVideoChecker); DISALLOW_COPY_AND_ASSIGN(SupportedAudioVideoChecker);
......
...@@ -16,6 +16,8 @@ source_set("lib") { ...@@ -16,6 +16,8 @@ source_set("lib") {
"media_metadata_parser.h", "media_metadata_parser.h",
"media_parser.cc", "media_parser.cc",
"media_parser.h", "media_parser.h",
"media_parser_factory.cc",
"media_parser_factory.h",
] ]
deps = [ deps = [
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
"interface_provider_specs": { "interface_provider_specs": {
"service_manager:connector": { "service_manager:connector": {
"provides": { "provides": {
"parse_media": [ "chrome::mojom::MediaParser" ] "parse_media": [ "chrome::mojom::MediaParserFactory" ]
}, },
"requires": { "requires": {
"service_manager": [ "service_manager:all_users" ] "service_manager": [ "service_manager:all_users" ]
......
...@@ -5,16 +5,16 @@ ...@@ -5,16 +5,16 @@
#include "chrome/services/media_gallery_util/media_gallery_util_service.h" #include "chrome/services/media_gallery_util/media_gallery_util_service.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/services/media_gallery_util/media_parser.h" #include "chrome/services/media_gallery_util/media_parser_factory.h"
#include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/cpp/bindings/strong_binding.h"
namespace { namespace {
void OnMediaParserRequest( void OnMediaParserFactoryRequest(
service_manager::ServiceContextRefFactory* ref_factory, service_manager::ServiceContextRefFactory* ref_factory,
chrome::mojom::MediaParserRequest request) { chrome::mojom::MediaParserFactoryRequest request) {
mojo::MakeStrongBinding( mojo::MakeStrongBinding(
std::make_unique<MediaParser>(ref_factory->CreateRef()), std::make_unique<MediaParserFactory>(ref_factory->CreateRef()),
std::move(request)); std::move(request));
} }
...@@ -32,7 +32,8 @@ MediaGalleryUtilService::CreateService() { ...@@ -32,7 +32,8 @@ MediaGalleryUtilService::CreateService() {
void MediaGalleryUtilService::OnStart() { void MediaGalleryUtilService::OnStart() {
ref_factory_ = std::make_unique<service_manager::ServiceContextRefFactory>( ref_factory_ = std::make_unique<service_manager::ServiceContextRefFactory>(
context()->CreateQuitClosure()); context()->CreateQuitClosure());
registry_.AddInterface(base::Bind(&OnMediaParserRequest, ref_factory_.get())); registry_.AddInterface(
base::Bind(&OnMediaParserFactoryRequest, ref_factory_.get()));
} }
void MediaGalleryUtilService::OnBindInterface( void MediaGalleryUtilService::OnBindInterface(
......
// Copyright 2018 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.
#include "chrome/services/media_gallery_util/media_parser_factory.h"
#include "base/allocator/buildflags.h"
#include "chrome/services/media_gallery_util/media_parser.h"
#include "media/base/media.h"
#include "media/media_buildflags.h"
#include "mojo/public/cpp/bindings/interface_request.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
MediaParserFactory::MediaParserFactory(
std::unique_ptr<service_manager::ServiceContextRef> service_ref)
: service_ref_(std::move(service_ref)) {}
MediaParserFactory::~MediaParserFactory() = default;
void MediaParserFactory::CreateMediaParser(int64_t libyuv_cpu_flags,
int64_t libavutil_cpu_flags,
CreateMediaParserCallback callback) {
media::InitializeMediaLibraryInSandbox(libyuv_cpu_flags, libavutil_cpu_flags);
chrome::mojom::MediaParserPtr media_parser_ptr;
mojo::MakeStrongBinding(std::make_unique<MediaParser>(service_ref_->Clone()),
mojo::MakeRequest(&media_parser_ptr));
std::move(callback).Run(std::move(media_parser_ptr));
}
// Copyright 2018 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_SERVICES_MEDIA_GALLERY_UTIL_MEDIA_PARSER_FACTORY_H_
#define CHROME_SERVICES_MEDIA_GALLERY_UTIL_MEDIA_PARSER_FACTORY_H_
#include <stdint.h>
#include <memory>
#include "chrome/services/media_gallery_util/public/mojom/media_parser.mojom.h"
#include "services/service_manager/public/cpp/service_context_ref.h"
class MediaParserFactory : public chrome::mojom::MediaParserFactory {
public:
explicit MediaParserFactory(
std::unique_ptr<service_manager::ServiceContextRef> service_ref);
~MediaParserFactory() override;
private:
// chrome::mojom::MediaParserFactory:
void CreateMediaParser(int64_t libyuv_cpu_flags,
int64_t ffmpeg_cpu_flags,
CreateMediaParserCallback callback) override;
const std::unique_ptr<service_manager::ServiceContextRef> service_ref_;
DISALLOW_COPY_AND_ASSIGN(MediaParserFactory);
};
#endif // CHROME_SERVICES_MEDIA_GALLERY_UTIL_MEDIA_PARSER_FACTORY_H_
...@@ -6,6 +6,8 @@ import("//media/media_options.gni") ...@@ -6,6 +6,8 @@ import("//media/media_options.gni")
source_set("cpp") { source_set("cpp") {
sources = [ sources = [
"media_parser_provider.cc",
"media_parser_provider.h",
"safe_audio_video_checker.cc", "safe_audio_video_checker.cc",
"safe_audio_video_checker.h", "safe_audio_video_checker.h",
"safe_media_metadata_parser.cc", "safe_media_metadata_parser.cc",
...@@ -15,11 +17,19 @@ source_set("cpp") { ...@@ -15,11 +17,19 @@ source_set("cpp") {
deps = [ deps = [
"//services/service_manager/public/cpp", "//services/service_manager/public/cpp",
"//third_party/boringssl", "//third_party/boringssl",
"//third_party/libyuv",
] ]
public_deps = [ public_deps = [
"//chrome/services/media_gallery_util/public/mojom", "//chrome/services/media_gallery_util/public/mojom",
] ]
if (media_use_ffmpeg) {
deps += [
"//third_party/ffmpeg",
"//third_party/ffmpeg:ffmpeg_features",
]
}
} }
source_set("browser_tests") { source_set("browser_tests") {
......
include_rules = [ include_rules = [
"+extensions/browser", "+extensions/browser",
"+third_party/libyuv",
"+third_party/ffmpeg",
] ]
\ No newline at end of file
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "chrome/services/media_gallery_util/public/cpp/media_parser_provider.h"
#include "chrome/services/media_gallery_util/public/mojom/constants.mojom.h" #include "chrome/services/media_gallery_util/public/mojom/constants.mojom.h"
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
#include "content/public/common/service_manager_connection.h" #include "content/public/common/service_manager_connection.h"
...@@ -24,17 +25,41 @@ namespace { ...@@ -24,17 +25,41 @@ namespace {
using MediaGalleryUtilBrowserTest = InProcessBrowserTest; using MediaGalleryUtilBrowserTest = InProcessBrowserTest;
class TestMediaParserProvider : public MediaParserProvider {
public:
TestMediaParserProvider() = default;
chrome::mojom::MediaParser* GetMediaParser(
service_manager::Connector* connector) {
DCHECK(!quit_loop_);
base::RunLoop run_loop;
quit_loop_ = run_loop.QuitClosure();
RetrieveMediaParser(connector);
run_loop.Run();
return media_parser();
}
private:
void OnMediaParserCreated() override { std::move(quit_loop_).Run(); }
void OnConnectionError() override { std::move(quit_loop_).Run(); }
base::Closure quit_loop_;
};
} // namespace } // namespace
// Tests that the MediaParserProvider class used by the client library classes
// does initialize the CPU info correctly.
IN_PROC_BROWSER_TEST_F(MediaGalleryUtilBrowserTest, TestThirdPartyCpuInfo) { IN_PROC_BROWSER_TEST_F(MediaGalleryUtilBrowserTest, TestThirdPartyCpuInfo) {
service_manager::Connector* connector = service_manager::Connector* connector =
content::ServiceManagerConnection::GetForProcess()->GetConnector(); content::ServiceManagerConnection::GetForProcess()->GetConnector();
chrome::mojom::MediaParserPtr media_parser_ptr; TestMediaParserProvider media_parser_provider;
connector->BindInterface(chrome::mojom::kMediaGalleryUtilServiceName, chrome::mojom::MediaParser* media_parser =
mojo::MakeRequest(&media_parser_ptr)); media_parser_provider.GetMediaParser(connector);
base::RunLoop run_loop; base::RunLoop run_loop;
media_parser_ptr->GetCpuInfo(base::BindOnce( media_parser->GetCpuInfo(base::BindOnce(
[](base::Closure quit_closure, int64_t libyuv_cpu_flags, [](base::Closure quit_closure, int64_t libyuv_cpu_flags,
int64_t ffmpeg_cpu_flags) { int64_t ffmpeg_cpu_flags) {
int64_t expected_ffmpeg_cpu_flags = 0; int64_t expected_ffmpeg_cpu_flags = 0;
......
// Copyright 2018 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.
#include "chrome/services/media_gallery_util/public/cpp/media_parser_provider.h"
#include "base/allocator/buildflags.h"
#include "base/bind.h"
#include "chrome/services/media_gallery_util/public/mojom/constants.mojom.h"
#include "media/media_buildflags.h"
#include "services/service_manager/public/cpp/connector.h"
#include "third_party/libyuv/include/libyuv.h"
#if BUILDFLAG(ENABLE_FFMPEG)
#include "third_party/ffmpeg/ffmpeg_features.h" // nogncheck
extern "C" {
#include <libavutil/cpu.h>
}
#endif
MediaParserProvider::MediaParserProvider() = default;
MediaParserProvider::~MediaParserProvider() = default;
void MediaParserProvider::RetrieveMediaParser(
service_manager::Connector* connector) {
DCHECK(!media_parser_factory_ptr_);
DCHECK(!media_parser_ptr_);
connector->BindInterface(chrome::mojom::kMediaGalleryUtilServiceName,
mojo::MakeRequest(&media_parser_factory_ptr_));
media_parser_factory_ptr_.set_connection_error_handler(base::BindOnce(
&MediaParserProvider::OnConnectionError, base::Unretained(this)));
int libyuv_cpu_flags = libyuv::InitCpuFlags();
#if BUILDFLAG(ENABLE_FFMPEG)
int avutil_cpu_flags = av_get_cpu_flags();
#else
int avutil_cpu_flags = -1;
#endif
media_parser_factory_ptr_->CreateMediaParser(
libyuv_cpu_flags, avutil_cpu_flags,
base::BindOnce(&MediaParserProvider::OnMediaParserCreatedImpl,
base::Unretained(this)));
}
void MediaParserProvider::OnMediaParserCreatedImpl(
chrome::mojom::MediaParserPtr media_parser_ptr) {
media_parser_ptr_ = std::move(media_parser_ptr);
media_parser_ptr_.set_connection_error_handler(base::BindOnce(
&MediaParserProvider::OnConnectionError, base::Unretained(this)));
media_parser_factory_ptr_.reset();
OnMediaParserCreated();
}
void MediaParserProvider::ResetMediaParser() {
media_parser_ptr_.reset();
media_parser_factory_ptr_.reset();
}
// Copyright 2018 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_SERVICES_MEDIA_GALLERY_UTIL_PUBLIC_CPP_MEDIA_PARSER_PROVIDER_H_
#define CHROME_SERVICES_MEDIA_GALLERY_UTIL_PUBLIC_CPP_MEDIA_PARSER_PROVIDER_H_
#include "base/macros.h"
#include "chrome/services/media_gallery_util/public/mojom/media_parser.mojom.h"
namespace service_manager {
class Connector;
}
// Base class used by SafeMediaMetadataParser and SafeAudioVideoChecker to
// retrieve a MediaParserPtr.
class MediaParserProvider {
public:
MediaParserProvider();
virtual ~MediaParserProvider();
protected:
// Retrieves the MediaParserPtr. OnMediaParserCreated() is called when the
// media parser is available.
void RetrieveMediaParser(service_manager::Connector* connector);
// Invoked when the media parser was successfully created. It can then be
// obtained by calling media_parser() and is guaranteed to be non null.
virtual void OnMediaParserCreated() = 0;
// Invoked when there was an error with the connection to the media gallerie
// util service. When this call happens, it means any pending callback
// expected from media_parser() will not happen.
virtual void OnConnectionError() = 0;
chrome::mojom::MediaParser* media_parser() const {
return media_parser_ptr_.get();
}
// Clears all interface ptr to the media gallery service.
void ResetMediaParser();
private:
void OnMediaParserCreatedImpl(chrome::mojom::MediaParserPtr media_parser_ptr);
chrome::mojom::MediaParserFactoryPtr media_parser_factory_ptr_;
chrome::mojom::MediaParserPtr media_parser_ptr_;
DISALLOW_COPY_AND_ASSIGN(MediaParserProvider);
};
#endif // CHROME_SERVICES_MEDIA_GALLERY_UTIL_PUBLIC_CPP_MEDIA_PARSER_PROVIDER_H_
...@@ -28,23 +28,24 @@ void SafeAudioVideoChecker::Start() { ...@@ -28,23 +28,24 @@ void SafeAudioVideoChecker::Start() {
return; return;
} }
DCHECK(!media_parser_ptr_); RetrieveMediaParser(connector_.get());
}
connector_->BindInterface(chrome::mojom::kMediaGalleryUtilServiceName,
mojo::MakeRequest(&media_parser_ptr_));
media_parser_ptr_.set_connection_error_handler(base::Bind(
&SafeAudioVideoChecker::CheckMediaFileDone, this, /*valid=*/false));
void SafeAudioVideoChecker::OnMediaParserCreated() {
static constexpr auto kFileDecodeTime = static constexpr auto kFileDecodeTime =
base::TimeDelta::FromMilliseconds(250); base::TimeDelta::FromMilliseconds(250);
media_parser_ptr_->CheckMediaFile( media_parser()->CheckMediaFile(
kFileDecodeTime, std::move(file_), kFileDecodeTime, std::move(file_),
base::Bind(&SafeAudioVideoChecker::CheckMediaFileDone, this)); base::BindOnce(&SafeAudioVideoChecker::CheckMediaFileDone,
base::Unretained(this)));
}
void SafeAudioVideoChecker::OnConnectionError() {
CheckMediaFileDone(/*valid=*/false);
} }
void SafeAudioVideoChecker::CheckMediaFileDone(bool valid) { void SafeAudioVideoChecker::CheckMediaFileDone(bool valid) {
media_parser_ptr_.reset(); // Terminate the utility process.
std::move(callback_).Run(valid ? base::File::FILE_OK std::move(callback_).Run(valid ? base::File::FILE_OK
: base::File::FILE_ERROR_SECURITY); : base::File::FILE_ERROR_SECURITY);
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "base/files/file.h" #include "base/files/file.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ref_counted.h" #include "chrome/services/media_gallery_util/public/cpp/media_parser_provider.h"
#include "chrome/services/media_gallery_util/public/mojom/media_parser.mojom.h" #include "chrome/services/media_gallery_util/public/mojom/media_parser.mojom.h"
namespace service_manager { namespace service_manager {
...@@ -18,9 +18,7 @@ class Connector; ...@@ -18,9 +18,7 @@ class Connector;
// File::FILE_OK, then file appears to be valid. File validation does not // File::FILE_OK, then file appears to be valid. File validation does not
// attempt to decode the entire file since that could take a considerable // attempt to decode the entire file since that could take a considerable
// amount of time. // amount of time.
class SafeAudioVideoChecker : public MediaParserProvider {
class SafeAudioVideoChecker
: public base::RefCountedThreadSafe<SafeAudioVideoChecker> {
public: public:
using ResultCallback = base::OnceCallback<void(base::File::Error result)>; using ResultCallback = base::OnceCallback<void(base::File::Error result)>;
...@@ -28,6 +26,7 @@ class SafeAudioVideoChecker ...@@ -28,6 +26,7 @@ class SafeAudioVideoChecker
SafeAudioVideoChecker(base::File file, SafeAudioVideoChecker(base::File file,
ResultCallback callback, ResultCallback callback,
std::unique_ptr<service_manager::Connector> connector); std::unique_ptr<service_manager::Connector> connector);
~SafeAudioVideoChecker() override;
// Checks the file. Can be called on a different thread than the UI thread. // Checks the file. Can be called on a different thread than the UI thread.
// Note that the callback specified in the construtor will be called on the // Note that the callback specified in the construtor will be called on the
...@@ -35,9 +34,9 @@ class SafeAudioVideoChecker ...@@ -35,9 +34,9 @@ class SafeAudioVideoChecker
void Start(); void Start();
private: private:
friend class base::RefCountedThreadSafe<SafeAudioVideoChecker>; // MediaParserProvider implementation:
void OnMediaParserCreated() override;
~SafeAudioVideoChecker(); void OnConnectionError() override;
// Media file check result. // Media file check result.
void CheckMediaFileDone(bool valid); void CheckMediaFileDone(bool valid);
...@@ -45,9 +44,6 @@ class SafeAudioVideoChecker ...@@ -45,9 +44,6 @@ class SafeAudioVideoChecker
// Media file to check. // Media file to check.
base::File file_; base::File file_;
// Pointer to the Mojo interface doing the actual parsing.
chrome::mojom::MediaParserPtr media_parser_ptr_;
// Connector to the ServiceManager used to ind the MediaParser interface. // Connector to the ServiceManager used to ind the MediaParser interface.
std::unique_ptr<service_manager::Connector> connector_; std::unique_ptr<service_manager::Connector> connector_;
......
...@@ -55,30 +55,24 @@ SafeMediaMetadataParser::~SafeMediaMetadataParser() = default; ...@@ -55,30 +55,24 @@ SafeMediaMetadataParser::~SafeMediaMetadataParser() = default;
void SafeMediaMetadataParser::Start(service_manager::Connector* connector, void SafeMediaMetadataParser::Start(service_manager::Connector* connector,
DoneCallback callback) { DoneCallback callback) {
DCHECK(!media_parser_ptr_); DCHECK(!media_parser());
DCHECK(callback); DCHECK(callback);
callback_ = std::move(callback); callback_ = std::move(callback);
connector->BindInterface(chrome::mojom::kMediaGalleryUtilServiceName, RetrieveMediaParser(connector);
mojo::MakeRequest(&media_parser_ptr_)); }
// It's safe to use Unretained below as |this| owns |media_parser_ptr_|.
media_parser_ptr_.set_connection_error_handler(
base::BindOnce(&SafeMediaMetadataParser::ParseMediaMetadataFailed,
base::Unretained(this)));
void SafeMediaMetadataParser::OnMediaParserCreated() {
chrome::mojom::MediaDataSourcePtr source; chrome::mojom::MediaDataSourcePtr source;
media_data_source_ = std::make_unique<MediaDataSourceImpl>(this, &source); media_data_source_ = std::make_unique<MediaDataSourceImpl>(this, &source);
media_parser_ptr_->ParseMediaMetadata( media_parser()->ParseMediaMetadata(
mime_type_, blob_size_, get_attached_images_, std::move(source), mime_type_, blob_size_, get_attached_images_, std::move(source),
base::BindOnce(&SafeMediaMetadataParser::ParseMediaMetadataDone, base::BindOnce(&SafeMediaMetadataParser::ParseMediaMetadataDone,
base::Unretained(this))); base::Unretained(this)));
} }
void SafeMediaMetadataParser::ParseMediaMetadataFailed() { void SafeMediaMetadataParser::OnConnectionError() {
media_parser_ptr_.reset(); // Terminate the utility process.
media_data_source_.reset();
auto metadata_dictionary = std::make_unique<base::DictionaryValue>(); auto metadata_dictionary = std::make_unique<base::DictionaryValue>();
auto attached_images = auto attached_images =
std::make_unique<std::vector<metadata::AttachedImage>>(); std::make_unique<std::vector<metadata::AttachedImage>>();
...@@ -92,7 +86,7 @@ void SafeMediaMetadataParser::ParseMediaMetadataDone( ...@@ -92,7 +86,7 @@ void SafeMediaMetadataParser::ParseMediaMetadataDone(
bool parse_success, bool parse_success,
std::unique_ptr<base::DictionaryValue> metadata_dictionary, std::unique_ptr<base::DictionaryValue> metadata_dictionary,
const std::vector<metadata::AttachedImage>& attached_images) { const std::vector<metadata::AttachedImage>& attached_images) {
media_parser_ptr_.reset(); // Terminate the utility process. ResetMediaParser();
media_data_source_.reset(); media_data_source_.reset();
auto attached_images_copy = auto attached_images_copy =
...@@ -118,6 +112,6 @@ void SafeMediaMetadataParser::BlobReaderDone( ...@@ -118,6 +112,6 @@ void SafeMediaMetadataParser::BlobReaderDone(
chrome::mojom::MediaDataSource::ReadBlobCallback callback, chrome::mojom::MediaDataSource::ReadBlobCallback callback,
std::unique_ptr<std::string> data, std::unique_ptr<std::string> data,
int64_t /* blob_total_size */) { int64_t /* blob_total_size */) {
if (media_parser_ptr_) if (media_parser())
std::move(callback).Run(std::vector<uint8_t>(data->begin(), data->end())); std::move(callback).Run(std::vector<uint8_t>(data->begin(), data->end()));
} }
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "chrome/common/media_galleries/metadata_types.h" #include "chrome/common/media_galleries/metadata_types.h"
#include "chrome/services/media_gallery_util/public/cpp/media_parser_provider.h"
#include "chrome/services/media_gallery_util/public/mojom/media_parser.mojom.h" #include "chrome/services/media_gallery_util/public/mojom/media_parser.mojom.h"
namespace content { namespace content {
...@@ -29,7 +30,7 @@ class Connector; ...@@ -29,7 +30,7 @@ class Connector;
// expects the MIME type of the Blob to be already known. It creates a utility // expects the MIME type of the Blob to be already known. It creates a utility
// process to do further MIME-type-specific metadata extraction from the Blob // process to do further MIME-type-specific metadata extraction from the Blob
// data. // data.
class SafeMediaMetadataParser { class SafeMediaMetadataParser : public MediaParserProvider {
public: public:
typedef base::OnceCallback<void( typedef base::OnceCallback<void(
bool parse_success, bool parse_success,
...@@ -42,7 +43,7 @@ class SafeMediaMetadataParser { ...@@ -42,7 +43,7 @@ class SafeMediaMetadataParser {
int64_t blob_size, int64_t blob_size,
const std::string& mime_type, const std::string& mime_type,
bool get_attached_images); bool get_attached_images);
~SafeMediaMetadataParser(); ~SafeMediaMetadataParser() override;
// Should be called on the thread |connector| is associated with. |callback| // Should be called on the thread |connector| is associated with. |callback|
// is invoked on that same thread. // is invoked on that same thread.
...@@ -51,8 +52,9 @@ class SafeMediaMetadataParser { ...@@ -51,8 +52,9 @@ class SafeMediaMetadataParser {
private: private:
class MediaDataSourceImpl; class MediaDataSourceImpl;
// Callback if the utility process or metadata parse request fails. // MediaParserProvider implementation:
void ParseMediaMetadataFailed(); void OnMediaParserCreated() override;
void OnConnectionError() override;
// Callback from utility process when it finishes parsing metadata. // Callback from utility process when it finishes parsing metadata.
void ParseMediaMetadataDone( void ParseMediaMetadataDone(
...@@ -78,7 +80,6 @@ class SafeMediaMetadataParser { ...@@ -78,7 +80,6 @@ class SafeMediaMetadataParser {
const std::string mime_type_; const std::string mime_type_;
bool get_attached_images_; bool get_attached_images_;
chrome::mojom::MediaParserPtr media_parser_ptr_;
DoneCallback callback_; DoneCallback callback_;
std::unique_ptr<MediaDataSourceImpl> media_data_source_; std::unique_ptr<MediaDataSourceImpl> media_data_source_;
......
...@@ -35,6 +35,17 @@ interface MediaParser { ...@@ -35,6 +35,17 @@ interface MediaParser {
GetCpuInfo() => (int64 libyuv_cpu_flags, int64 ffmpeg_cpu_flags); GetCpuInfo() => (int64 libyuv_cpu_flags, int64 ffmpeg_cpu_flags);
}; };
interface MediaParserFactory {
// Creates a MediaParser. |libyuv_cpuf_lags| are the flags returned by
// libyuv::InitCpuFlags() from third-party/libyuv and |libavutil_cpu_flags|
// the flags returned by av_get_cpu_flags() from FFmpeg. These flags have to
// be passed in as retrieving them may require file access (to /proc/cpuinfo
// for instance) and the media parser may be run in a sandboxed process with
// no such access.
CreateMediaParser(int64 libyuv_cpu_flags, int64 libavutil_cpu_flags)
=> (MediaParser media_parser);
};
interface MediaDataSource { interface MediaDataSource {
// ParseMediaMetadata interface used to read blob data for parsing from the // ParseMediaMetadata interface used to read blob data for parsing from the
// calling process. // calling process.
......
...@@ -99,8 +99,6 @@ static_library("utility") { ...@@ -99,8 +99,6 @@ static_library("utility") {
if (enable_extensions) { if (enable_extensions) {
sources += [ sources += [
"extensions/extensions_handler.cc",
"extensions/extensions_handler.h",
"image_writer/disk_unmounter_mac.cc", "image_writer/disk_unmounter_mac.cc",
"image_writer/disk_unmounter_mac.h", "image_writer/disk_unmounter_mac.h",
"image_writer/error_messages.cc", "image_writer/error_messages.cc",
......
...@@ -49,7 +49,6 @@ ...@@ -49,7 +49,6 @@
#include "chrome/services/media_gallery_util/public/mojom/constants.mojom.h" #include "chrome/services/media_gallery_util/public/mojom/constants.mojom.h"
#include "chrome/services/removable_storage_writer/public/mojom/constants.mojom.h" #include "chrome/services/removable_storage_writer/public/mojom/constants.mojom.h"
#include "chrome/services/removable_storage_writer/removable_storage_writer_service.h" #include "chrome/services/removable_storage_writer/removable_storage_writer_service.h"
#include "chrome/utility/extensions/extensions_handler.h"
#if defined(OS_WIN) #if defined(OS_WIN)
#include "chrome/services/wifi_util_win/public/mojom/constants.mojom.h" #include "chrome/services/wifi_util_win/public/mojom/constants.mojom.h"
#include "chrome/services/wifi_util_win/wifi_util_win_service.h" #include "chrome/services/wifi_util_win/wifi_util_win_service.h"
...@@ -100,10 +99,6 @@ void RegisterRemovableStorageWriterService( ...@@ -100,10 +99,6 @@ void RegisterRemovableStorageWriterService(
ChromeContentUtilityClient::ChromeContentUtilityClient() ChromeContentUtilityClient::ChromeContentUtilityClient()
: utility_process_running_elevated_(false) { : utility_process_running_elevated_(false) {
#if BUILDFLAG(ENABLE_EXTENSIONS)
extensions::InitExtensionsClient();
#endif
#if defined(OS_WIN) && BUILDFLAG(ENABLE_PRINT_PREVIEW) #if defined(OS_WIN) && BUILDFLAG(ENABLE_PRINT_PREVIEW)
printing_handler_ = std::make_unique<printing::PrintingHandler>(); printing_handler_ = std::make_unique<printing::PrintingHandler>();
#endif #endif
...@@ -265,13 +260,6 @@ void ChromeContentUtilityClient::RegisterNetworkBinders( ...@@ -265,13 +260,6 @@ void ChromeContentUtilityClient::RegisterNetworkBinders(
g_network_binder_creation_callback.Get().Run(registry); g_network_binder_creation_callback.Get().Run(registry);
} }
// static
void ChromeContentUtilityClient::PreSandboxStartup() {
#if BUILDFLAG(ENABLE_EXTENSIONS)
extensions::PreSandboxStartup();
#endif
}
// static // static
void ChromeContentUtilityClient::SetNetworkBinderCreationCallback( void ChromeContentUtilityClient::SetNetworkBinderCreationCallback(
const NetworkBinderCreationCallback& callback) { const NetworkBinderCreationCallback& callback) {
......
...@@ -34,8 +34,6 @@ class ChromeContentUtilityClient : public content::ContentUtilityClient { ...@@ -34,8 +34,6 @@ class ChromeContentUtilityClient : public content::ContentUtilityClient {
void RegisterNetworkBinders( void RegisterNetworkBinders(
service_manager::BinderRegistry* registry) override; service_manager::BinderRegistry* registry) override;
static void PreSandboxStartup();
// See NetworkBinderProvider above. // See NetworkBinderProvider above.
static void SetNetworkBinderCreationCallback( static void SetNetworkBinderCreationCallback(
const NetworkBinderCreationCallback& callback); const NetworkBinderCreationCallback& callback);
......
include_rules = [
"+extensions/buildflags",
"+extensions/common",
"+extensions/features",
]
file://extensions/OWNERS
# COMPONENT: Platform>Extensions
// Copyright 2014 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.
#include "chrome/utility/extensions/extensions_handler.h"
#include "chrome/common/extensions/chrome_extensions_client.h"
#include "media/base/media.h"
namespace extensions {
// static
void InitExtensionsClient() {
ExtensionsClient::Set(ChromeExtensionsClient::GetInstance());
}
// static
void PreSandboxStartup() {
media::InitializeMediaLibrary(); // Used for media file validation.
}
} // namespace extensions
// Copyright 2014 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_UTILITY_EXTENSIONS_EXTENSIONS_HANDLER_H_
#define CHROME_UTILITY_EXTENSIONS_EXTENSIONS_HANDLER_H_
#include "build/build_config.h"
#include "extensions/buildflags/buildflags.h"
#if !BUILDFLAG(ENABLE_EXTENSIONS)
#error "Extensions must be enabled"
#endif
namespace extensions {
void InitExtensionsClient();
void PreSandboxStartup();
} // namespace extensions
#endif // CHROME_UTILITY_EXTENSIONS_EXTENSIONS_HANDLER_H_
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
# chrome/common/extensions/OWNERS # chrome/common/extensions/OWNERS
# chrome/renderer/extensions/OWNERS # chrome/renderer/extensions/OWNERS
# chrome/renderer/resources/extensions/OWNERS # chrome/renderer/resources/extensions/OWNERS
# chrome/utility/extensions/OWNERS
rdevlin.cronin@chromium.org rdevlin.cronin@chromium.org
lazyboy@chromium.org lazyboy@chromium.org
......
...@@ -35,11 +35,12 @@ class MediaInitializer { ...@@ -35,11 +35,12 @@ class MediaInitializer {
TRACE_EVENT_WARMUP_CATEGORY("audio"); TRACE_EVENT_WARMUP_CATEGORY("audio");
TRACE_EVENT_WARMUP_CATEGORY("media"); TRACE_EVENT_WARMUP_CATEGORY("media");
// Initializing the CPU flags may query /proc for details on the current CPU
// for NEON, VFP, etc optimizations. If in a sandboxed process, they should
// have been forced (see InitializeMediaLibraryInSandbox).
libyuv::InitCpuFlags(); libyuv::InitCpuFlags();
#if BUILDFLAG(ENABLE_FFMPEG) #if BUILDFLAG(ENABLE_FFMPEG)
// Initialize CPU flags outside of the sandbox as this may query /proc for
// details on the current CPU for NEON, VFP, etc optimizations.
av_get_cpu_flags(); av_get_cpu_flags();
// Disable logging as it interferes with layout tests. // Disable logging as it interferes with layout tests.
...@@ -82,6 +83,17 @@ void InitializeMediaLibrary() { ...@@ -82,6 +83,17 @@ void InitializeMediaLibrary() {
GetMediaInstance(); GetMediaInstance();
} }
void InitializeMediaLibraryInSandbox(int64_t libyuv_cpu_flags,
int64_t libavutil_cpu_flags) {
// Force the CPU flags so when they don't require disk access when queried
// from MediaInitializer().
libyuv::SetCpuFlags(libyuv_cpu_flags);
#if BUILDFLAG(ENABLE_FFMPEG)
av_force_cpu_flags(libavutil_cpu_flags);
#endif
GetMediaInstance();
}
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
void EnablePlatformDecoderSupport() { void EnablePlatformDecoderSupport() {
GetMediaInstance()->enable_platform_decoder_support(); GetMediaInstance()->enable_platform_decoder_support();
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#ifndef MEDIA_BASE_MEDIA_H_ #ifndef MEDIA_BASE_MEDIA_H_
#define MEDIA_BASE_MEDIA_H_ #define MEDIA_BASE_MEDIA_H_
#include <stdint.h>
#include "build/build_config.h" #include "build/build_config.h"
#include "media/base/media_export.h" #include "media/base/media_export.h"
...@@ -17,6 +19,15 @@ namespace media { ...@@ -17,6 +19,15 @@ namespace media {
// features. // features.
MEDIA_EXPORT void InitializeMediaLibrary(); MEDIA_EXPORT void InitializeMediaLibrary();
// Same as InitializeMediaLibrary() but specifies the CPU flags used by libyuv
// and ffmpeg (libavutil). Retrieving these flags may access the file system
// (/proc/cpuinfo) which won't work in sandboxed processes. For such processes,
// a non sandboxed process should retrieve these flags in advance (via
// libyuv::InitCpuFlags() and av_get_cpu_flags()) and pass them to the sandboxed
// process that should then call this method.
MEDIA_EXPORT void InitializeMediaLibraryInSandbox(int64_t libyuv_cpu_flags,
int64_t libavutil_cpu_flags);
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
// Tells the media library it has support for OS level decoders. Should only be // Tells the media library it has support for OS level decoders. Should only be
// used for actual decoders (e.g. MediaCodec) and not full-featured players // used for actual decoders (e.g. MediaCodec) and not full-featured players
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment