Commit 53d04735 authored by mcasas's avatar mcasas Committed by Commit bot

ImageCapture: replace Mojo String/Array with stl/wtf string/vector

This CL nukes the usage of mojo::String and mojo::Array<> after [1],
so where it was mojo::String it now reads std::string or WTF::String
and also mojo::Array<> is replaced with std::vector or WTF::Vector,
as appropriate.

[1] https://groups.google.com/a/chromium.org/forum/?utm_medium=email&utm_source=footer#!msg/chromium-mojo/2SHvKyahLGg/sU61P0IIBgAJ

BUG=624136, 518807

TBR=xhwang@chromium.org
for the trivial change in media/mojo/interfaces/BUILD.gn

Review-Url: https://codereview.chromium.org/2166713002
Cr-Commit-Position: refs/heads/master@{#406776}
parent 1da432b8
...@@ -51,20 +51,23 @@ void RunFailedSetOptionsCallback( ...@@ -51,20 +51,23 @@ void RunFailedSetOptionsCallback(
void RunTakePhotoCallbackOnUIThread( void RunTakePhotoCallbackOnUIThread(
const ImageCaptureImpl::TakePhotoCallback& callback, const ImageCaptureImpl::TakePhotoCallback& callback,
mojo::String mime_type, const std::string& mime_type,
mojo::Array<uint8_t> data) { const std::vector<uint8_t>& data) {
// TODO(mcasas): Use a mojo typemapping instead of const_cast to avoid copying
// |data|, https://crbug.com/630040.
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE, BrowserThread::UI, FROM_HERE,
base::Bind(callback, mime_type, base::Passed(std::move(data)))); base::Bind(callback, mime_type,
base::Passed(const_cast<std::vector<uint8_t>*>(&data))));
} }
void RunFailedTakePhotoCallback(const ImageCaptureImpl::TakePhotoCallback& cb) { void RunFailedTakePhotoCallback(const ImageCaptureImpl::TakePhotoCallback& cb) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
cb.Run("", mojo::Array<uint8_t>()); cb.Run("", std::vector<uint8_t>());
} }
void GetCapabilitiesOnIOThread( void GetCapabilitiesOnIOThread(
const mojo::String& source_id, const std::string& source_id,
MediaStreamManager* media_stream_manager, MediaStreamManager* media_stream_manager,
media::ScopedResultCallback<ImageCaptureImpl::GetCapabilitiesCallback> media::ScopedResultCallback<ImageCaptureImpl::GetCapabilitiesCallback>
callback) { callback) {
...@@ -80,7 +83,7 @@ void GetCapabilitiesOnIOThread( ...@@ -80,7 +83,7 @@ void GetCapabilitiesOnIOThread(
} }
void SetOptionsOnIOThread( void SetOptionsOnIOThread(
const mojo::String& source_id, const std::string& source_id,
MediaStreamManager* media_stream_manager, MediaStreamManager* media_stream_manager,
media::mojom::PhotoSettingsPtr settings, media::mojom::PhotoSettingsPtr settings,
media::ScopedResultCallback<ImageCaptureImpl::SetOptionsCallback> media::ScopedResultCallback<ImageCaptureImpl::SetOptionsCallback>
...@@ -97,7 +100,7 @@ void SetOptionsOnIOThread( ...@@ -97,7 +100,7 @@ void SetOptionsOnIOThread(
} }
void TakePhotoOnIOThread( void TakePhotoOnIOThread(
const mojo::String& source_id, const std::string& source_id,
MediaStreamManager* media_stream_manager, MediaStreamManager* media_stream_manager,
media::ScopedResultCallback<ImageCaptureImpl::TakePhotoCallback> callback) { media::ScopedResultCallback<ImageCaptureImpl::TakePhotoCallback> callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
...@@ -123,7 +126,7 @@ void ImageCaptureImpl::Create( ...@@ -123,7 +126,7 @@ void ImageCaptureImpl::Create(
ImageCaptureImpl::~ImageCaptureImpl() {} ImageCaptureImpl::~ImageCaptureImpl() {}
void ImageCaptureImpl::GetCapabilities( void ImageCaptureImpl::GetCapabilities(
const mojo::String& source_id, const std::string& source_id,
const GetCapabilitiesCallback& callback) { const GetCapabilitiesCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
...@@ -138,7 +141,7 @@ void ImageCaptureImpl::GetCapabilities( ...@@ -138,7 +141,7 @@ void ImageCaptureImpl::GetCapabilities(
base::Passed(&scoped_callback))); base::Passed(&scoped_callback)));
} }
void ImageCaptureImpl::SetOptions(const mojo::String& source_id, void ImageCaptureImpl::SetOptions(const std::string& source_id,
media::mojom::PhotoSettingsPtr settings, media::mojom::PhotoSettingsPtr settings,
const SetOptionsCallback& callback) { const SetOptionsCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
...@@ -154,7 +157,7 @@ void ImageCaptureImpl::SetOptions(const mojo::String& source_id, ...@@ -154,7 +157,7 @@ void ImageCaptureImpl::SetOptions(const mojo::String& source_id,
base::Passed(&settings), base::Passed(&scoped_callback))); base::Passed(&settings), base::Passed(&scoped_callback)));
} }
void ImageCaptureImpl::TakePhoto(const mojo::String& source_id, void ImageCaptureImpl::TakePhoto(const std::string& source_id,
const TakePhotoCallback& callback) { const TakePhotoCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include "media/mojo/interfaces/image_capture.mojom.h" #include "media/mojo/interfaces/image_capture.mojom.h"
#include "mojo/public/cpp/bindings/interface_request.h" #include "mojo/public/cpp/bindings/interface_request.h"
#include "mojo/public/cpp/bindings/string.h"
#include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/cpp/bindings/strong_binding.h"
namespace content { namespace content {
...@@ -18,14 +17,14 @@ class ImageCaptureImpl : public media::mojom::ImageCapture { ...@@ -18,14 +17,14 @@ class ImageCaptureImpl : public media::mojom::ImageCapture {
mojo::InterfaceRequest<media::mojom::ImageCapture> request); mojo::InterfaceRequest<media::mojom::ImageCapture> request);
~ImageCaptureImpl() override; ~ImageCaptureImpl() override;
void GetCapabilities(const mojo::String& source_id, void GetCapabilities(const std::string& source_id,
const GetCapabilitiesCallback& callback) override; const GetCapabilitiesCallback& callback) override;
void SetOptions(const mojo::String& source_id, void SetOptions(const std::string& source_id,
media::mojom::PhotoSettingsPtr settings, media::mojom::PhotoSettingsPtr settings,
const SetOptionsCallback& callback) override; const SetOptionsCallback& callback) override;
void TakePhoto(const mojo::String& source_id, void TakePhoto(const std::string& source_id,
const TakePhotoCallback& callback) override; const TakePhotoCallback& callback) override;
private: private:
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include "jni/VideoCapture_jni.h" #include "jni/VideoCapture_jni.h"
#include "media/capture/video/android/photo_capabilities.h" #include "media/capture/video/android/photo_capabilities.h"
#include "media/capture/video/android/video_capture_device_factory_android.h" #include "media/capture/video/android/video_capture_device_factory_android.h"
#include "mojo/public/cpp/bindings/string.h"
using base::android::AttachCurrentThread; using base::android::AttachCurrentThread;
using base::android::CheckException; using base::android::CheckException;
...@@ -263,8 +262,7 @@ void VideoCaptureDeviceAndroid::OnPhotoTaken( ...@@ -263,8 +262,7 @@ void VideoCaptureDeviceAndroid::OnPhotoTaken(
std::vector<uint8_t> native_data; std::vector<uint8_t> native_data;
base::android::JavaByteArrayToByteVector(env, data.obj(), &native_data); base::android::JavaByteArrayToByteVector(env, data.obj(), &native_data);
cb->Run(mojo::String::From(native_data.empty() ? "" : "image/jpeg"), cb->Run(std::string(native_data.empty() ? "" : "image/jpeg"), native_data);
mojo::Array<uint8_t>::From(native_data));
photo_callbacks_.erase(reference_it); photo_callbacks_.erase(reference_it);
} }
......
...@@ -108,8 +108,7 @@ void DoTakeFakePhoto(VideoCaptureDevice::TakePhotoCallback callback, ...@@ -108,8 +108,7 @@ void DoTakeFakePhoto(VideoCaptureDevice::TakePhotoCallback callback,
std::vector<gfx::PNGCodec::Comment>(), &encoded_data); std::vector<gfx::PNGCodec::Comment>(), &encoded_data);
DCHECK(result); DCHECK(result);
callback.Run(mojo::String::From("image/png"), callback.Run("image/png", encoded_data);
mojo::Array<uint8_t>::From(encoded_data));
} }
FakeVideoCaptureDevice::FakeVideoCaptureDevice(BufferOwnership buffer_ownership, FakeVideoCaptureDevice::FakeVideoCaptureDevice(BufferOwnership buffer_ownership,
......
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
#include "media/base/video_capture_types.h" #include "media/base/video_capture_types.h"
#include "media/capture/video/fake_video_capture_device_factory.h" #include "media/capture/video/fake_video_capture_device_factory.h"
#include "media/capture/video/video_capture_device.h" #include "media/capture/video/video_capture_device.h"
#include "mojo/public/cpp/bindings/string.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -152,9 +151,10 @@ class ImageCaptureClient : public base::RefCounted<ImageCaptureClient> { ...@@ -152,9 +151,10 @@ class ImageCaptureClient : public base::RefCounted<ImageCaptureClient> {
void(const base::Callback<void(bool)>&)); void(const base::Callback<void(bool)>&));
// GMock doesn't support move-only arguments, so we use this forward method. // GMock doesn't support move-only arguments, so we use this forward method.
void DoOnPhotoTaken(mojo::String mime_type, mojo::Array<uint8_t> data) { void DoOnPhotoTaken(const std::string& mime_type,
const std::vector<uint8_t>& data) {
// Only PNG images are supported right now. // Only PNG images are supported right now.
EXPECT_STREQ("image/png", mime_type.storage().c_str()); EXPECT_STREQ("image/png", mime_type.c_str());
// Not worth decoding the incoming data. Just check that the header is PNG. // Not worth decoding the incoming data. Just check that the header is PNG.
// http://www.libpng.org/pub/png/spec/1.2/PNG-Rationale.html#R.PNG-file-signature // http://www.libpng.org/pub/png/spec/1.2/PNG-Rationale.html#R.PNG-file-signature
ASSERT_GT(data.size(), 4u); ASSERT_GT(data.size(), 4u);
...@@ -164,9 +164,9 @@ class ImageCaptureClient : public base::RefCounted<ImageCaptureClient> { ...@@ -164,9 +164,9 @@ class ImageCaptureClient : public base::RefCounted<ImageCaptureClient> {
OnCorrectPhotoTaken(); OnCorrectPhotoTaken();
} }
MOCK_METHOD0(OnCorrectPhotoTaken, void(void)); MOCK_METHOD0(OnCorrectPhotoTaken, void(void));
MOCK_METHOD1( MOCK_METHOD1(OnTakePhotoFailure,
OnTakePhotoFailure, void(const base::Callback<void(const std::string&,
void(const base::Callback<void(mojo::String, mojo::Array<uint8_t>)>&)); const std::vector<uint8_t>&)>&));
private: private:
friend class base::RefCounted<ImageCaptureClient>; friend class base::RefCounted<ImageCaptureClient>;
......
...@@ -444,9 +444,8 @@ void VideoCaptureDeviceMac::OnPhotoTaken(const uint8_t* image_data, ...@@ -444,9 +444,8 @@ void VideoCaptureDeviceMac::OnPhotoTaken(const uint8_t* image_data,
return; return;
} }
photo_callback_->Run(mojo::String::From(mime_type), photo_callback_->Run(
mojo::Array<uint8_t>(std::vector<uint8_t>( mime_type, std::vector<uint8_t>(image_data, image_data + image_length));
image_data, image_data + image_length)));
photo_callback_.reset(); photo_callback_.reset();
} }
......
...@@ -326,7 +326,7 @@ class CAPTURE_EXPORT VideoCaptureDevice { ...@@ -326,7 +326,7 @@ class CAPTURE_EXPORT VideoCaptureDevice {
// and/or interrupting the capture flow. Runs |callback| on the thread // and/or interrupting the capture flow. Runs |callback| on the thread
// where TakePhoto() is called, if the photo was successfully taken. // where TakePhoto() is called, if the photo was successfully taken.
using TakePhotoCallback = ScopedResultCallback< using TakePhotoCallback = ScopedResultCallback<
base::Callback<void(mojo::String, mojo::Array<uint8_t>)>>; base::Callback<void(const std::string&, const std::vector<uint8_t>&)>>;
virtual void TakePhoto(TakePhotoCallback callback); virtual void TakePhoto(TakePhotoCallback callback);
// Gets the power line frequency, either from the params if specified by the // Gets the power line frequency, either from the params if specified by the
......
...@@ -145,8 +145,9 @@ class MockVideoCaptureClient : public VideoCaptureDevice::Client { ...@@ -145,8 +145,9 @@ class MockVideoCaptureClient : public VideoCaptureDevice::Client {
class MockImageCaptureClient : public base::RefCounted<MockImageCaptureClient> { class MockImageCaptureClient : public base::RefCounted<MockImageCaptureClient> {
public: public:
// GMock doesn't support move-only arguments, so we use this forward method. // GMock doesn't support move-only arguments, so we use this forward method.
void DoOnPhotoTaken(mojo::String mime_type, mojo::Array<uint8_t> data) { void DoOnPhotoTaken(const std::string& mime_type,
EXPECT_STREQ("image/jpeg", mime_type.storage().c_str()); const std::vector<uint8_t>& data) {
EXPECT_STREQ("image/jpeg", mime_type.c_str());
ASSERT_GT(data.size(), 4u); ASSERT_GT(data.size(), 4u);
// Check some bytes that univocally identify |data| as a JPEG File. // Check some bytes that univocally identify |data| as a JPEG File.
// https://en.wikipedia.org/wiki/JPEG_File_Interchange_Format#File_format_structure // https://en.wikipedia.org/wiki/JPEG_File_Interchange_Format#File_format_structure
...@@ -157,9 +158,9 @@ class MockImageCaptureClient : public base::RefCounted<MockImageCaptureClient> { ...@@ -157,9 +158,9 @@ class MockImageCaptureClient : public base::RefCounted<MockImageCaptureClient> {
OnCorrectPhotoTaken(); OnCorrectPhotoTaken();
} }
MOCK_METHOD0(OnCorrectPhotoTaken, void(void)); MOCK_METHOD0(OnCorrectPhotoTaken, void(void));
MOCK_METHOD1( MOCK_METHOD1(OnTakePhotoFailure,
OnTakePhotoFailure, void(const base::Callback<void(const std::string&,
void(const base::Callback<void(mojo::String, mojo::Array<uint8_t>)>&)); const std::vector<uint8_t>&)>&));
private: private:
friend class base::RefCounted<MockImageCaptureClient>; friend class base::RefCounted<MockImageCaptureClient>;
......
...@@ -39,6 +39,4 @@ mojom("image_capture") { ...@@ -39,6 +39,4 @@ mojom("image_capture") {
sources = [ sources = [
"image_capture.mojom", "image_capture.mojom",
] ]
use_new_wrapper_types = false
} }
...@@ -85,9 +85,6 @@ ...@@ -85,9 +85,6 @@
'sources': [ 'sources': [
'image_capture.mojom', 'image_capture.mojom',
], ],
'variables': {
'use_new_wrapper_types': 'false',
},
}, },
{ {
# GN version: //media/mojo/interfaces:image_capture # GN version: //media/mojo/interfaces:image_capture
...@@ -95,7 +92,6 @@ ...@@ -95,7 +92,6 @@
'type': 'static_library', 'type': 'static_library',
'variables': { 'variables': {
'for_blink': 'true', 'for_blink': 'true',
'use_new_wrapper_types': 'false',
}, },
'includes': [ 'includes': [
'../../../mojo/mojom_bindings_generator.gypi', '../../../mojo/mojom_bindings_generator.gypi',
......
...@@ -218,17 +218,15 @@ void ImageCapture::onSetOptions(ScriptPromiseResolver* resolver, bool result) ...@@ -218,17 +218,15 @@ void ImageCapture::onSetOptions(ScriptPromiseResolver* resolver, bool result)
m_serviceRequests.remove(resolver); m_serviceRequests.remove(resolver);
} }
void ImageCapture::onTakePhoto(ScriptPromiseResolver* resolver, const String& mimeType, mojo::WTFArray<uint8_t> data) void ImageCapture::onTakePhoto(ScriptPromiseResolver* resolver, const String& mimeType, const Vector<uint8_t>& data)
{ {
if (!m_serviceRequests.contains(resolver)) if (!m_serviceRequests.contains(resolver))
return; return;
if (data.is_null() || data.empty()) { if (data.isEmpty())
resolver->reject(DOMException::create(UnknownError, "platform error")); resolver->reject(DOMException::create(UnknownError, "platform error"));
} else { else
const auto& storage = data.storage(); resolver->resolve(Blob::create(data.data(), data.size(), mimeType));
resolver->resolve(Blob::create(storage.data(), storage.size(), mimeType));
}
m_serviceRequests.remove(resolver); m_serviceRequests.remove(resolver);
} }
......
...@@ -61,7 +61,7 @@ private: ...@@ -61,7 +61,7 @@ private:
void onCapabilities(ScriptPromiseResolver*, media::mojom::blink::PhotoCapabilitiesPtr); void onCapabilities(ScriptPromiseResolver*, media::mojom::blink::PhotoCapabilitiesPtr);
void onSetOptions(ScriptPromiseResolver*, bool); void onSetOptions(ScriptPromiseResolver*, bool);
void onTakePhoto(ScriptPromiseResolver*, const String& mimeType, mojo::WTFArray<uint8_t> data); void onTakePhoto(ScriptPromiseResolver*, const String& mimeType, const Vector<uint8_t>& data);
void onServiceConnectionError(); void onServiceConnectionError();
Member<MediaStreamTrack> m_streamTrack; Member<MediaStreamTrack> m_streamTrack;
......
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