Commit eedcd440 authored by Antonio Gomes's avatar Antonio Gomes Committed by Commit Bot

Switch WebAudioOutputIPCFactory away from base::flat_map

... and use WTF::HashMap instead.

BUG=787252
R=guidou@chromium.org

Change-Id: I4950b6fc9b677cdb0c26814373955f4addc68251
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2364216
Commit-Queue: Antonio Gomes (GMT-4) <tonikitoo@igalia.com>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Cr-Commit-Position: refs/heads/master@{#803854}
parent 64775d21
include_rules = [ include_rules = [
# TODO(https://crbug.com/787252): Remove this include when WTF::HashMap.
# is used instead.
"+base/containers/flat_map.h",
"+media/audio", "+media/audio",
"+media/base/audio_parameters.h", "+media/base/audio_parameters.h",
"+media/mojo", "+media/mojo",
......
...@@ -8,13 +8,13 @@ ...@@ -8,13 +8,13 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/check_op.h" #include "base/check_op.h"
#include "base/containers/flat_map.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/bindings/remote.h"
#include "third_party/blink/public/common/browser_interface_broker_proxy.h" #include "third_party/blink/public/common/browser_interface_broker_proxy.h"
#include "third_party/blink/public/mojom/media/renderer_audio_output_stream_factory.mojom-blink.h" #include "third_party/blink/public/mojom/media/renderer_audio_output_stream_factory.mojom-blink.h"
#include "third_party/blink/renderer/modules/media/audio/mojo_audio_output_ipc.h" #include "third_party/blink/renderer/modules/media/audio/mojo_audio_output_ipc.h"
#include "third_party/blink/renderer/platform/wtf/hash_map.h"
namespace blink { namespace blink {
...@@ -22,13 +22,13 @@ WebAudioOutputIPCFactory* WebAudioOutputIPCFactory::instance_ = nullptr; ...@@ -22,13 +22,13 @@ WebAudioOutputIPCFactory* WebAudioOutputIPCFactory::instance_ = nullptr;
class WebAudioOutputIPCFactory::Impl { class WebAudioOutputIPCFactory::Impl {
public: public:
using StreamFactoryMap = base::flat_map< using StreamFactoryMap = WTF::HashMap<
blink::LocalFrameToken, uint64_t,
mojo::Remote<mojom::blink::RendererAudioOutputStreamFactory>>; mojo::Remote<mojom::blink::RendererAudioOutputStreamFactory>>;
explicit Impl(scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) explicit Impl(scoped_refptr<base::SingleThreadTaskRunner> io_task_runner)
: io_task_runner_(std::move(io_task_runner)) {} : io_task_runner_(std::move(io_task_runner)) {}
~Impl() { DCHECK(factory_remotes_.empty()); } ~Impl() { DCHECK(factory_remotes_.IsEmpty()); }
mojom::blink::RendererAudioOutputStreamFactory* GetRemoteFactory( mojom::blink::RendererAudioOutputStreamFactory* GetRemoteFactory(
const blink::LocalFrameToken& frame_token) const; const blink::LocalFrameToken& frame_token) const;
...@@ -106,8 +106,8 @@ mojom::blink::RendererAudioOutputStreamFactory* ...@@ -106,8 +106,8 @@ mojom::blink::RendererAudioOutputStreamFactory*
WebAudioOutputIPCFactory::Impl::GetRemoteFactory( WebAudioOutputIPCFactory::Impl::GetRemoteFactory(
const blink::LocalFrameToken& frame_token) const { const blink::LocalFrameToken& frame_token) const {
DCHECK(io_task_runner_->BelongsToCurrentThread()); DCHECK(io_task_runner_->BelongsToCurrentThread());
auto it = factory_remotes_.find(frame_token); auto it = factory_remotes_.find(LocalFrameToken::Hasher()(frame_token));
return it == factory_remotes_.end() ? nullptr : it->second.get(); return it == factory_remotes_.end() ? nullptr : it->value.get();
} }
void WebAudioOutputIPCFactory::Impl::RegisterRemoteFactoryOnIOThread( void WebAudioOutputIPCFactory::Impl::RegisterRemoteFactoryOnIOThread(
...@@ -115,14 +115,17 @@ void WebAudioOutputIPCFactory::Impl::RegisterRemoteFactoryOnIOThread( ...@@ -115,14 +115,17 @@ void WebAudioOutputIPCFactory::Impl::RegisterRemoteFactoryOnIOThread(
mojo::PendingRemote<mojom::blink::RendererAudioOutputStreamFactory> mojo::PendingRemote<mojom::blink::RendererAudioOutputStreamFactory>
factory_pending_remote) { factory_pending_remote) {
DCHECK(io_task_runner_->BelongsToCurrentThread()); DCHECK(io_task_runner_->BelongsToCurrentThread());
std::pair<StreamFactoryMap::iterator, bool> emplace_result = mojo::Remote<mojom::blink::RendererAudioOutputStreamFactory> factory_remote(
factory_remotes_.emplace(frame_token, std::move(factory_pending_remote)); std::move(factory_pending_remote));
DCHECK(emplace_result.second) << "Attempt to register a factory for a " auto emplace_result = factory_remotes_.insert(
"frame which already has a factory " LocalFrameToken::Hasher()(frame_token), std::move(factory_remote));
"registered.";
auto& emplaced_factory = emplace_result.first->second; DCHECK(emplace_result.is_new_entry) << "Attempt to register a factory for a "
"frame which already has a factory "
"registered.";
auto& emplaced_factory = emplace_result.stored_value->value;
DCHECK(emplaced_factory.is_bound()) DCHECK(emplaced_factory.is_bound())
<< "Factory is not bound to a remote implementation."; << "Factory is not bound to a remote implementation.";
...@@ -140,7 +143,7 @@ void WebAudioOutputIPCFactory::Impl::MaybeDeregisterRemoteFactoryOnIOThread( ...@@ -140,7 +143,7 @@ void WebAudioOutputIPCFactory::Impl::MaybeDeregisterRemoteFactoryOnIOThread(
// handler of the factory remote. Calling erase multiple times even though // handler of the factory remote. Calling erase multiple times even though
// there is nothing to erase is safe, so we don't have to handle this in any // there is nothing to erase is safe, so we don't have to handle this in any
// particular way. // particular way.
factory_remotes_.erase(frame_token); factory_remotes_.erase(LocalFrameToken::Hasher()(frame_token));
} }
} // namespace blink } // namespace blink
...@@ -838,7 +838,6 @@ _CONFIG = [ ...@@ -838,7 +838,6 @@ _CONFIG = [
'allowed': [ 'allowed': [
# TODO(https://crbug.com/787252): Remove most of the entries below, # TODO(https://crbug.com/787252): Remove most of the entries below,
# once the directory is fully Onion soup'ed. # once the directory is fully Onion soup'ed.
'base::flat_map',
'base::Bind.*', 'base::Bind.*',
'base::Unretained', 'base::Unretained',
'mojo::WrapCallbackWithDefaultInvokeIfNotRun', 'mojo::WrapCallbackWithDefaultInvokeIfNotRun',
......
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