diff options
author | toyoshim <toyoshim@chromium.org> | 2015-07-09 14:14:51 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-07-09 21:15:39 +0000 |
commit | eb09fc13169f631cfd610af9fabc3a9e3311ec1a (patch) | |
tree | c83d489fe0f67f73fca4243b045f5ad976927481 | |
parent | 0e9e860d8eb0fa12450f4d6c9ed7efd29e0c15c2 (diff) | |
download | chromium_src-eb09fc13169f631cfd610af9fabc3a9e3311ec1a.zip chromium_src-eb09fc13169f631cfd610af9fabc3a9e3311ec1a.tar.gz chromium_src-eb09fc13169f631cfd610af9fabc3a9e3311ec1a.tar.bz2 |
Web MIDI: add a new UMA entry for the final result code
This change adds a new UMA entry for the final MidiManager
result code on browser shutdown.
To report the result correctly, I assigned new numbers for
the result code. As a side effect, this patch can fix an
existing problem that the result code for NOT_INITIALIZED
was not propagated to renderer side correctly.
BUG=465661
Review URL: https://codereview.chromium.org/1217853007
Cr-Commit-Position: refs/heads/master@{#338148}
-rw-r--r-- | content/browser/media/midi_host.cc | 4 | ||||
-rw-r--r-- | content/browser/media/midi_host.h | 2 | ||||
-rw-r--r-- | content/common/media/midi_messages.h | 8 | ||||
-rw-r--r-- | content/renderer/media/midi_message_filter.cc | 21 | ||||
-rw-r--r-- | content/renderer/media/midi_message_filter.h | 8 | ||||
-rw-r--r-- | media/midi/midi_manager.cc | 21 | ||||
-rw-r--r-- | media/midi/midi_manager.h | 20 | ||||
-rw-r--r-- | media/midi/midi_manager_alsa.cc | 20 | ||||
-rw-r--r-- | media/midi/midi_manager_mac.cc | 8 | ||||
-rw-r--r-- | media/midi/midi_manager_mac_unittest.cc | 12 | ||||
-rw-r--r-- | media/midi/midi_manager_unittest.cc | 51 | ||||
-rw-r--r-- | media/midi/midi_manager_usb.cc | 9 | ||||
-rw-r--r-- | media/midi/midi_manager_usb.h | 4 | ||||
-rw-r--r-- | media/midi/midi_manager_usb_unittest.cc | 28 | ||||
-rw-r--r-- | media/midi/midi_manager_win.cc | 6 | ||||
-rw-r--r-- | media/midi/midi_manager_win.h | 4 | ||||
-rw-r--r-- | media/midi/midi_result.h | 27 | ||||
-rw-r--r-- | media/midi/result.h | 30 | ||||
-rw-r--r-- | tools/metrics/histograms/histograms.xml | 12 |
19 files changed, 154 insertions, 141 deletions
diff --git a/content/browser/media/midi_host.cc b/content/browser/media/midi_host.cc index d610025..c26a719 100644 --- a/content/browser/media/midi_host.cc +++ b/content/browser/media/midi_host.cc @@ -130,9 +130,9 @@ void MidiHost::OnEndSession() { midi_manager_->EndSession(this); } -void MidiHost::CompleteStartSession(media::midi::MidiResult result) { +void MidiHost::CompleteStartSession(media::midi::Result result) { DCHECK(is_session_requested_); - if (result == media::midi::MIDI_OK) { + if (result == media::midi::Result::OK) { // ChildSecurityPolicy is set just before OnStartSession by // MidiDispatcherHost. So we can safely cache the policy. has_sys_ex_permission_ = ChildProcessSecurityPolicyImpl::GetInstance()-> diff --git a/content/browser/media/midi_host.h b/content/browser/media/midi_host.h index 7a47775e..c6ff3ea 100644 --- a/content/browser/media/midi_host.h +++ b/content/browser/media/midi_host.h @@ -38,7 +38,7 @@ class CONTENT_EXPORT MidiHost : public BrowserMessageFilter, bool OnMessageReceived(const IPC::Message& message) override; // MidiManagerClient implementation. - void CompleteStartSession(media::midi::MidiResult result) override; + void CompleteStartSession(media::midi::Result result) override; void AddInputPort(const media::midi::MidiPortInfo& info) override; void AddOutputPort(const media::midi::MidiPortInfo& info) override; void SetInputPortState(uint32 port, diff --git a/content/common/media/midi_messages.h b/content/common/media/midi_messages.h index 67500f6..14ac45d 100644 --- a/content/common/media/midi_messages.h +++ b/content/common/media/midi_messages.h @@ -10,7 +10,7 @@ #include "ipc/ipc_message_macros.h" #include "ipc/param_traits_macros.h" #include "media/midi/midi_port_info.h" -#include "media/midi/midi_result.h" +#include "media/midi/result.h" #include "url/gurl.h" #undef IPC_MESSAGE_EXPORT @@ -28,8 +28,7 @@ IPC_STRUCT_TRAITS_BEGIN(media::midi::MidiPortInfo) IPC_STRUCT_TRAITS_MEMBER(state) IPC_STRUCT_TRAITS_END() -IPC_ENUM_TRAITS_MAX_VALUE(media::midi::MidiResult, - media::midi::MIDI_RESULT_LAST) +IPC_ENUM_TRAITS_MAX_VALUE(media::midi::Result, media::midi::Result::MAX) // Messages for IPC between MidiMessageFilter and MidiHost. @@ -59,8 +58,7 @@ IPC_MESSAGE_CONTROL2(MidiMsg_SetOutputPortState, uint32 /* port */, media::midi::MidiPortState /* state */) -IPC_MESSAGE_CONTROL1(MidiMsg_SessionStarted, - media::midi::MidiResult /* result */) +IPC_MESSAGE_CONTROL1(MidiMsg_SessionStarted, media::midi::Result /* result */) IPC_MESSAGE_CONTROL3(MidiMsg_DataReceived, uint32 /* port */, diff --git a/content/renderer/media/midi_message_filter.cc b/content/renderer/media/midi_message_filter.cc index ceb4f08..82bdc70 100644 --- a/content/renderer/media/midi_message_filter.cc +++ b/content/renderer/media/midi_message_filter.cc @@ -29,7 +29,7 @@ MidiMessageFilter::MidiMessageFilter( : sender_(nullptr), io_task_runner_(io_task_runner), main_task_runner_(base::ThreadTaskRunnerHandle::Get()), - session_result_(media::midi::MIDI_NOT_INITIALIZED), + session_result_(media::midi::Result::NOT_INITIALIZED), unacknowledged_bytes_sent_(0u) { } @@ -39,7 +39,7 @@ void MidiMessageFilter::AddClient(blink::WebMIDIAccessorClient* client) { DCHECK(main_task_runner_->BelongsToCurrentThread()); TRACE_EVENT0("midi", "MidiMessageFilter::AddClient"); clients_waiting_session_queue_.push_back(client); - if (session_result_ != media::midi::MIDI_NOT_INITIALIZED) { + if (session_result_ != media::midi::Result::NOT_INITIALIZED) { HandleClientAdded(session_result_); } else if (clients_waiting_session_queue_.size() == 1u) { io_task_runner_->PostTask( @@ -57,7 +57,7 @@ void MidiMessageFilter::RemoveClient(blink::WebMIDIAccessorClient* client) { if (it != clients_waiting_session_queue_.end()) clients_waiting_session_queue_.erase(it); if (clients_.empty() && clients_waiting_session_queue_.empty()) { - session_result_ = media::midi::MIDI_NOT_INITIALIZED; + session_result_ = media::midi::Result::NOT_INITIALIZED; inputs_.clear(); outputs_.clear(); io_task_runner_->PostTask( @@ -143,7 +143,7 @@ void MidiMessageFilter::OnChannelClosing() { sender_ = nullptr; } -void MidiMessageFilter::OnSessionStarted(media::midi::MidiResult result) { +void MidiMessageFilter::OnSessionStarted(media::midi::Result result) { TRACE_EVENT0("midi", "MidiMessageFilter::OnSessionStarted"); DCHECK(io_task_runner_->BelongsToCurrentThread()); // Handle on the main JS thread. @@ -200,19 +200,19 @@ void MidiMessageFilter::OnAcknowledgeSentData(size_t bytes_sent) { this, bytes_sent)); } -void MidiMessageFilter::HandleClientAdded(media::midi::MidiResult result) { +void MidiMessageFilter::HandleClientAdded(media::midi::Result result) { TRACE_EVENT0("midi", "MidiMessageFilter::HandleClientAdded"); DCHECK(main_task_runner_->BelongsToCurrentThread()); session_result_ = result; std::string error; std::string message; switch (result) { - case media::midi::MIDI_OK: + case media::midi::Result::OK: break; - case media::midi::MIDI_NOT_SUPPORTED: + case media::midi::Result::NOT_SUPPORTED: error = "NotSupportedError"; break; - case media::midi::MIDI_INITIALIZATION_ERROR: + case media::midi::Result::INITIALIZATION_ERROR: error = "InvalidStateError"; message = "Platform dependent initialization failed."; break; @@ -230,7 +230,7 @@ void MidiMessageFilter::HandleClientAdded(media::midi::MidiResult result) { while (!clients_waiting_session_queue_.empty()) { auto client = clients_waiting_session_queue_.back(); clients_waiting_session_queue_.pop_back(); - if (result == media::midi::MIDI_OK) { + if (result == media::midi::Result::OK) { // Add the client's input and output ports. for (const auto& info : inputs_) { client->didAddInputPort( @@ -250,7 +250,8 @@ void MidiMessageFilter::HandleClientAdded(media::midi::MidiResult result) { ToBlinkState(info.state)); } } - client->didStartSession(result == media::midi::MIDI_OK, error16, message16); + client->didStartSession(result == media::midi::Result::OK, error16, + message16); clients_.insert(client); } } diff --git a/content/renderer/media/midi_message_filter.h b/content/renderer/media/midi_message_filter.h index 26f12b9..77cbb73 100644 --- a/content/renderer/media/midi_message_filter.h +++ b/content/renderer/media/midi_message_filter.h @@ -12,7 +12,7 @@ #include "content/common/content_export.h" #include "ipc/message_filter.h" #include "media/midi/midi_port_info.h" -#include "media/midi/midi_result.h" +#include "media/midi/result.h" #include "third_party/WebKit/public/platform/WebMIDIAccessorClient.h" namespace base { @@ -75,7 +75,7 @@ class CONTENT_EXPORT MidiMessageFilter : public IPC::MessageFilter { // Called when the browser process has approved (or denied) access to // MIDI hardware. - void OnSessionStarted(media::midi::MidiResult result); + void OnSessionStarted(media::midi::Result result); // These functions are called in 2 cases: // (1) Just before calling |OnSessionStarted|, to notify the recipient about @@ -103,7 +103,7 @@ class CONTENT_EXPORT MidiMessageFilter : public IPC::MessageFilter { void OnAcknowledgeSentData(size_t bytes_sent); // Following methods, Handle*, run on |main_task_runner_|. - void HandleClientAdded(media::midi::MidiResult result); + void HandleClientAdded(media::midi::Result result); void HandleAddInputPort(media::midi::MidiPortInfo info); void HandleAddOutputPort(media::midi::MidiPortInfo info); @@ -142,7 +142,7 @@ class CONTENT_EXPORT MidiMessageFilter : public IPC::MessageFilter { ClientsQueue clients_waiting_session_queue_; // Represents a result on starting a session. Can be accessed only on - media::midi::MidiResult session_result_; + media::midi::Result session_result_; // Holds MidiPortInfoList for input ports and output ports. media::midi::MidiPortInfoList inputs_; diff --git a/media/midi/midi_manager.cc b/media/midi/midi_manager.cc index 4fc5b23..d61bd7a 100644 --- a/media/midi/midi_manager.cc +++ b/media/midi/midi_manager.cc @@ -6,17 +6,20 @@ #include "base/bind.h" #include "base/message_loop/message_loop.h" +#include "base/metrics/histogram_macros.h" #include "base/trace_event/trace_event.h" namespace media { namespace midi { MidiManager::MidiManager() - : initialized_(false), - result_(MIDI_NOT_SUPPORTED) { + : initialized_(false), result_(Result::NOT_INITIALIZED) { } MidiManager::~MidiManager() { + UMA_HISTOGRAM_ENUMERATION("Media.Midi.ResultOnShutdown", + static_cast<int>(result_), + static_cast<int>(Result::MAX) + 1); } #if !defined(OS_MACOSX) && !defined(OS_WIN) && \ @@ -64,7 +67,7 @@ void MidiManager::StartSession(MidiManagerClient* client) { } if (too_many_pending_clients_exist) { // Return an error immediately if there are too many requests. - client->CompleteStartSession(MIDI_INITIALIZATION_ERROR); + client->CompleteStartSession(Result::INITIALIZATION_ERROR); return; } // CompleteInitialization() will be called asynchronously when platform @@ -74,10 +77,10 @@ void MidiManager::StartSession(MidiManagerClient* client) { // Platform dependent initialization was already finished for previously // initialized clients. - MidiResult result; + Result result; { base::AutoLock auto_lock(lock_); - if (result_ == MIDI_OK) { + if (result_ == Result::OK) { AddInitialPorts(client); clients_.insert(client); } @@ -111,10 +114,10 @@ void MidiManager::DispatchSendMidiData(MidiManagerClient* client, } void MidiManager::StartInitialization() { - CompleteInitialization(MIDI_NOT_SUPPORTED); + CompleteInitialization(Result::NOT_SUPPORTED); } -void MidiManager::CompleteInitialization(MidiResult result) { +void MidiManager::CompleteInitialization(Result result) { DCHECK(session_thread_runner_.get()); // It is safe to post a task to the IO thread from here because the IO thread // should have stopped if the MidiManager is going to be destructed. @@ -166,7 +169,7 @@ void MidiManager::ReceiveMidiData( client->ReceiveMidiData(port_index, data, length, timestamp); } -void MidiManager::CompleteInitializationInternal(MidiResult result) { +void MidiManager::CompleteInitializationInternal(Result result) { TRACE_EVENT0("midi", "MidiManager::CompleteInitialization"); base::AutoLock auto_lock(lock_); @@ -176,7 +179,7 @@ void MidiManager::CompleteInitializationInternal(MidiResult result) { result_ = result; for (auto client : pending_clients_) { - if (result_ == MIDI_OK) { + if (result_ == Result::OK) { AddInitialPorts(client); clients_.insert(client); } diff --git a/media/midi/midi_manager.h b/media/midi/midi_manager.h index ab874b4..957c84d 100644 --- a/media/midi/midi_manager.h +++ b/media/midi/midi_manager.h @@ -14,7 +14,7 @@ #include "base/time/time.h" #include "media/midi/midi_export.h" #include "media/midi/midi_port_info.h" -#include "media/midi/midi_result.h" +#include "media/midi/result.h" namespace base { class SingleThreadTaskRunner; @@ -43,7 +43,7 @@ class MIDI_EXPORT MidiManagerClient { // CompleteStartSession() is called when platform dependent preparation is // finished. - virtual void CompleteStartSession(MidiResult result) = 0; + virtual void CompleteStartSession(Result result) = 0; // ReceiveMidiData() is called when MIDI data has been received from the // MIDI system. @@ -78,8 +78,8 @@ class MIDI_EXPORT MidiManager { // A client calls StartSession() to receive and send MIDI data. // If the session is ready to start, the MIDI system is lazily initialized // and the client is registered to receive MIDI data. - // CompleteStartSession() is called with MIDI_OK if the session is started. - // Otherwise CompleteStartSession() is called with proper MidiResult code. + // CompleteStartSession() is called with Result::OK if the session is started. + // Otherwise CompleteStartSession() is called with proper Result code. // StartSession() and EndSession() can be called on the Chrome_IOThread. // CompleteStartSession() will be invoked on the same Chrome_IOThread. void StartSession(MidiManagerClient* client); @@ -110,20 +110,20 @@ class MIDI_EXPORT MidiManager { // Initializes the platform dependent MIDI system. MidiManager class has a // default implementation that synchronously calls CompleteInitialization() - // with MIDI_NOT_SUPPORTED on the caller thread. A derived class for a + // with Result::NOT_SUPPORTED on the caller thread. A derived class for a // specific platform should override this method correctly. // This method is called on Chrome_IOThread thread inside StartSession(). // Platform dependent initialization can be processed synchronously or // asynchronously. When the initialization is completed, // CompleteInitialization() should be called with |result|. - // |result| should be MIDI_OK on success, otherwise a proper MidiResult. + // |result| should be Result::OK on success, otherwise a proper Result. virtual void StartInitialization(); // Called from a platform dependent implementation of StartInitialization(). // It invokes CompleteInitializationInternal() on the thread that calls // StartSession() and distributes |result| to MIDIManagerClient objects in // |pending_clients_|. - void CompleteInitialization(MidiResult result); + void CompleteInitialization(Result result); void AddInputPort(const MidiPortInfo& info); void AddOutputPort(const MidiPortInfo& info); @@ -152,7 +152,7 @@ class MIDI_EXPORT MidiManager { } private: - void CompleteInitializationInternal(MidiResult result); + void CompleteInitializationInternal(Result result); void AddInitialPorts(MidiManagerClient* client); // Keeps track of all clients who wish to receive MIDI data. @@ -170,8 +170,8 @@ class MIDI_EXPORT MidiManager { bool initialized_; // Keeps the platform dependent initialization result if initialization is - // completed. Otherwise keeps MIDI_NOT_SUPPORTED. - MidiResult result_; + // completed. Otherwise keeps Result::NOT_INITIALIZED. + Result result_; // Keeps all MidiPortInfo. MidiPortInfoList input_ports_; diff --git a/media/midi/midi_manager_alsa.cc b/media/midi/midi_manager_alsa.cc index 25e7d31..af618ef 100644 --- a/media/midi/midi_manager_alsa.cc +++ b/media/midi/midi_manager_alsa.cc @@ -185,7 +185,7 @@ void MidiManagerAlsa::StartInitialization() { snd_seq_open(&in_client, kAlsaHw, SND_SEQ_OPEN_INPUT, SND_SEQ_NONBLOCK); if (err != 0) { VLOG(1) << "snd_seq_open fails: " << snd_strerror(err); - return CompleteInitialization(MIDI_INITIALIZATION_ERROR); + return CompleteInitialization(Result::INITIALIZATION_ERROR); } in_client_.reset(in_client); in_client_id_ = snd_seq_client_id(in_client_.get()); @@ -194,7 +194,7 @@ void MidiManagerAlsa::StartInitialization() { err = snd_seq_open(&out_client, kAlsaHw, SND_SEQ_OPEN_OUTPUT, 0); if (err != 0) { VLOG(1) << "snd_seq_open fails: " << snd_strerror(err); - return CompleteInitialization(MIDI_INITIALIZATION_ERROR); + return CompleteInitialization(Result::INITIALIZATION_ERROR); } out_client_.reset(out_client); out_client_id_ = snd_seq_client_id(out_client_.get()); @@ -203,12 +203,12 @@ void MidiManagerAlsa::StartInitialization() { err = snd_seq_set_client_name(in_client_.get(), "Chrome (input)"); if (err != 0) { VLOG(1) << "snd_seq_set_client_name fails: " << snd_strerror(err); - return CompleteInitialization(MIDI_INITIALIZATION_ERROR); + return CompleteInitialization(Result::INITIALIZATION_ERROR); } err = snd_seq_set_client_name(out_client_.get(), "Chrome (output)"); if (err != 0) { VLOG(1) << "snd_seq_set_client_name fails: " << snd_strerror(err); - return CompleteInitialization(MIDI_INITIALIZATION_ERROR); + return CompleteInitialization(Result::INITIALIZATION_ERROR); } // Create input port. @@ -217,7 +217,7 @@ void MidiManagerAlsa::StartInitialization() { if (in_port_id_ < 0) { VLOG(1) << "snd_seq_create_simple_port fails: " << snd_strerror(in_port_id_); - return CompleteInitialization(MIDI_INITIALIZATION_ERROR); + return CompleteInitialization(Result::INITIALIZATION_ERROR); } // Subscribe to the announce port. @@ -235,7 +235,7 @@ void MidiManagerAlsa::StartInitialization() { if (err != 0) { VLOG(1) << "snd_seq_subscribe_port on the announce port fails: " << snd_strerror(err); - return CompleteInitialization(MIDI_INITIALIZATION_ERROR); + return CompleteInitialization(Result::INITIALIZATION_ERROR); } // Generate hotplug events for existing ports. @@ -247,20 +247,20 @@ void MidiManagerAlsa::StartInitialization() { device::udev_monitor_new_from_netlink(udev_.get(), kUdev)); if (!udev_monitor_.get()) { VLOG(1) << "udev_monitor_new_from_netlink fails"; - return CompleteInitialization(MIDI_INITIALIZATION_ERROR); + return CompleteInitialization(Result::INITIALIZATION_ERROR); } err = device::udev_monitor_filter_add_match_subsystem_devtype( udev_monitor_.get(), kUdevSubsystemSound, nullptr); if (err != 0) { VLOG(1) << "udev_monitor_add_match_subsystem fails: " << base::safe_strerror(-err); - return CompleteInitialization(MIDI_INITIALIZATION_ERROR); + return CompleteInitialization(Result::INITIALIZATION_ERROR); } err = device::udev_monitor_enable_receiving(udev_monitor_.get()); if (err != 0) { VLOG(1) << "udev_monitor_enable_receiving fails: " << base::safe_strerror(-err); - return CompleteInitialization(MIDI_INITIALIZATION_ERROR); + return CompleteInitialization(Result::INITIALIZATION_ERROR); } // Generate hotplug events for existing udev devices. @@ -272,7 +272,7 @@ void MidiManagerAlsa::StartInitialization() { FROM_HERE, base::Bind(&MidiManagerAlsa::ScheduleEventLoop, base::Unretained(this))); - CompleteInitialization(MIDI_OK); + CompleteInitialization(Result::OK); } void MidiManagerAlsa::DispatchSendMidiData(MidiManagerClient* client, diff --git a/media/midi/midi_manager_mac.cc b/media/midi/midi_manager_mac.cc index b13b5aa..ade118d 100644 --- a/media/midi/midi_manager_mac.cc +++ b/media/midi/midi_manager_mac.cc @@ -161,7 +161,7 @@ void MidiManagerMac::InitializeCoreMIDI() { MIDIClientCreate(CFSTR("Chrome"), ReceiveMidiNotifyDispatch, this, &midi_client_); if (result != noErr || midi_client_ == 0) - return CompleteInitialization(MIDI_INITIALIZATION_ERROR); + return CompleteInitialization(Result::INITIALIZATION_ERROR); // Create input and output port. DCHECK_EQ(0u, coremidi_input_); @@ -172,7 +172,7 @@ void MidiManagerMac::InitializeCoreMIDI() { this, &coremidi_input_); if (result != noErr || coremidi_input_ == 0) - return CompleteInitialization(MIDI_INITIALIZATION_ERROR); + return CompleteInitialization(Result::INITIALIZATION_ERROR); DCHECK_EQ(0u, coremidi_output_); result = MIDIOutputPortCreate( @@ -180,7 +180,7 @@ void MidiManagerMac::InitializeCoreMIDI() { CFSTR("MIDI Output"), &coremidi_output_); if (result != noErr || coremidi_output_ == 0) - return CompleteInitialization(MIDI_INITIALIZATION_ERROR); + return CompleteInitialization(Result::INITIALIZATION_ERROR); // Following loop may miss some newly attached devices, but such device will // be captured by ReceiveMidiNotifyDispatch callback. @@ -224,7 +224,7 @@ void MidiManagerMac::InitializeCoreMIDI() { // Allocate maximum size of buffer that CoreMIDI can handle. midi_buffer_.resize(kCoreMIDIMaxPacketListSize); - CompleteInitialization(MIDI_OK); + CompleteInitialization(Result::OK); } // static diff --git a/media/midi/midi_manager_mac_unittest.cc b/media/midi/midi_manager_mac_unittest.cc index 8bd75f2..83a24c0 100644 --- a/media/midi/midi_manager_mac_unittest.cc +++ b/media/midi/midi_manager_mac_unittest.cc @@ -23,7 +23,7 @@ void Noop(const MIDIPacketList*, void*, void*) {} class FakeMidiManagerClient : public MidiManagerClient { public: FakeMidiManagerClient() - : result_(MIDI_NOT_SUPPORTED), + : result_(Result::NOT_SUPPORTED), wait_for_result_(true), wait_for_port_(true), unexpected_callback_(false) {} @@ -49,7 +49,7 @@ class FakeMidiManagerClient : public MidiManagerClient { void SetInputPortState(uint32 port_index, MidiPortState state) override {} void SetOutputPortState(uint32 port_index, MidiPortState state) override {} - void CompleteStartSession(MidiResult result) override { + void CompleteStartSession(Result result) override { base::AutoLock lock(lock_); if (!wait_for_result_) unexpected_callback_ = true; @@ -72,7 +72,7 @@ class FakeMidiManagerClient : public MidiManagerClient { return wait_for_port_; } - MidiResult WaitForResult() { + Result WaitForResult() { while (GetWaitForResult()) { base::RunLoop run_loop; run_loop.RunUntilIdle(); @@ -91,7 +91,7 @@ class FakeMidiManagerClient : public MidiManagerClient { private: base::Lock lock_; - MidiResult result_; + Result result_; bool wait_for_result_; MidiPortInfo info_; bool wait_for_port_; @@ -126,8 +126,8 @@ TEST_F(MidiManagerMacTest, MidiNotification) { scoped_ptr<FakeMidiManagerClient> client(new FakeMidiManagerClient); StartSession(client.get()); - MidiResult result = client->WaitForResult(); - EXPECT_EQ(MIDI_OK, result); + Result result = client->WaitForResult(); + EXPECT_EQ(Result::OK, result); // Create MIDIClient, and MIDIEndpoint as a MIDIDestination. This should // notify MIDIManagerMac as a MIDIObjectAddRemoveNotification. diff --git a/media/midi/midi_manager_unittest.cc b/media/midi/midi_manager_unittest.cc index 1b6f638..2b56780 100644 --- a/media/midi/midi_manager_unittest.cc +++ b/media/midi/midi_manager_unittest.cc @@ -36,7 +36,7 @@ class FakeMidiManager : public MidiManager { double timestamp) override {} // Utility functions for testing. - void CallCompleteInitialization(MidiResult result) { + void CallCompleteInitialization(Result result) { CompleteInitialization(result); } @@ -57,8 +57,7 @@ class FakeMidiManager : public MidiManager { class FakeMidiManagerClient : public MidiManagerClient { public: FakeMidiManagerClient() - : result_(MIDI_NOT_SUPPORTED), - wait_for_result_(true) {} + : result_(Result::NOT_SUPPORTED), wait_for_result_(true) {} ~FakeMidiManagerClient() override {} // MidiManagerClient implementation. @@ -67,7 +66,7 @@ class FakeMidiManagerClient : public MidiManagerClient { void SetInputPortState(uint32 port_index, MidiPortState state) override {} void SetOutputPortState(uint32 port_index, MidiPortState state) override {} - void CompleteStartSession(MidiResult result) override { + void CompleteStartSession(Result result) override { EXPECT_TRUE(wait_for_result_); result_ = result; wait_for_result_ = false; @@ -79,9 +78,9 @@ class FakeMidiManagerClient : public MidiManagerClient { double timestamp) override {} void AccumulateMidiBytesSent(size_t size) override {} - MidiResult result() const { return result_; } + Result result() const { return result_; } - MidiResult WaitForResult() { + Result WaitForResult() { while (wait_for_result_) { base::RunLoop run_loop; run_loop.RunUntilIdle(); @@ -90,7 +89,7 @@ class FakeMidiManagerClient : public MidiManagerClient { } private: - MidiResult result_; + Result result_; bool wait_for_result_; DISALLOW_COPY_AND_ASSIGN(FakeMidiManagerClient); @@ -136,7 +135,7 @@ class MidiManagerTest : public ::testing::Test { EXPECT_EQ(after, manager_->GetClientCount()); } - void CompleteInitialization(MidiResult result) { + void CompleteInitialization(Result result) { manager_->CallCompleteInitialization(result); } @@ -159,8 +158,8 @@ TEST_F(MidiManagerTest, StartAndEndSession) { client.reset(new FakeMidiManagerClient); StartTheFirstSession(client.get()); - CompleteInitialization(MIDI_OK); - EXPECT_EQ(MIDI_OK, client->WaitForResult()); + CompleteInitialization(Result::OK); + EXPECT_EQ(Result::OK, client->WaitForResult()); EndSession(client.get(), 1U, 0U); } @@ -169,8 +168,8 @@ TEST_F(MidiManagerTest, StartAndEndSessionWithError) { client.reset(new FakeMidiManagerClient); StartTheFirstSession(client.get()); - CompleteInitialization(MIDI_INITIALIZATION_ERROR); - EXPECT_EQ(MIDI_INITIALIZATION_ERROR, client->WaitForResult()); + CompleteInitialization(Result::INITIALIZATION_ERROR); + EXPECT_EQ(Result::INITIALIZATION_ERROR, client->WaitForResult()); EndSession(client.get(), 0U, 0U); } @@ -185,10 +184,10 @@ TEST_F(MidiManagerTest, StartMultipleSessions) { StartTheFirstSession(client1.get()); StartTheNthSession(client2.get(), 2); StartTheNthSession(client3.get(), 3); - CompleteInitialization(MIDI_OK); - EXPECT_EQ(MIDI_OK, client1->WaitForResult()); - EXPECT_EQ(MIDI_OK, client2->WaitForResult()); - EXPECT_EQ(MIDI_OK, client3->WaitForResult()); + CompleteInitialization(Result::OK); + EXPECT_EQ(Result::OK, client1->WaitForResult()); + EXPECT_EQ(Result::OK, client2->WaitForResult()); + EXPECT_EQ(Result::OK, client3->WaitForResult()); EndSession(client1.get(), 3U, 2U); EndSession(client2.get(), 2U, 1U); EndSession(client3.get(), 1U, 0U); @@ -212,17 +211,17 @@ TEST_F(MidiManagerTest, TooManyPendingSessions) { manager_->start_initialization_is_called_ = false; manager_->StartSession(additional_client.get()); EXPECT_FALSE(manager_->start_initialization_is_called_); - EXPECT_EQ(MIDI_INITIALIZATION_ERROR, additional_client->result()); + EXPECT_EQ(Result::INITIALIZATION_ERROR, additional_client->result()); // Other clients still should not receive a result. RunLoopUntilIdle(); for (size_t i = 0; i < many_existing_clients.size(); ++i) - EXPECT_EQ(MIDI_NOT_SUPPORTED, many_existing_clients[i]->result()); + EXPECT_EQ(Result::NOT_SUPPORTED, many_existing_clients[i]->result()); - // The result MIDI_OK should be distributed to other clients. - CompleteInitialization(MIDI_OK); + // The Result::OK should be distributed to other clients. + CompleteInitialization(Result::OK); for (size_t i = 0; i < many_existing_clients.size(); ++i) - EXPECT_EQ(MIDI_OK, many_existing_clients[i]->WaitForResult()); + EXPECT_EQ(Result::OK, many_existing_clients[i]->WaitForResult()); // Close all successful sessions in FIFO order. size_t sessions = many_existing_clients.size(); @@ -241,7 +240,7 @@ TEST_F(MidiManagerTest, AbortSession) { client.reset(); // Following function should not call the destructed |client| function. - CompleteInitialization(MIDI_OK); + CompleteInitialization(Result::OK); base::RunLoop run_loop; run_loop.RunUntilIdle(); } @@ -256,17 +255,17 @@ TEST_F(MidiManagerTest, CreateMidiManager) { scoped_ptr<MidiManager> manager(MidiManager::Create()); manager->StartSession(client.get()); - MidiResult result = client->WaitForResult(); + Result result = client->WaitForResult(); // This #ifdef needs to be identical to the one in media/midi/midi_manager.cc. // Do not change the condition for disabling this test. #if !defined(OS_MACOSX) && !defined(OS_WIN) && \ !(defined(USE_ALSA) && defined(USE_UDEV)) && !defined(OS_ANDROID) - EXPECT_EQ(MIDI_NOT_SUPPORTED, result); + EXPECT_EQ(Result::NOT_SUPPORTED, result); #elif defined(USE_ALSA) // Temporary until http://crbug.com/371230 is resolved. - EXPECT_TRUE((result == MIDI_OK) || (result == MIDI_INITIALIZATION_ERROR)); + EXPECT_TRUE(result == Result::OK || result == Result::INITIALIZATION_ERROR); #else - EXPECT_EQ(MIDI_OK, result); + EXPECT_EQ(Result::OK, result); #endif } diff --git a/media/midi/midi_manager_usb.cc b/media/midi/midi_manager_usb.cc index 3e096d2..f493b15 100644 --- a/media/midi/midi_manager_usb.cc +++ b/media/midi/midi_manager_usb.cc @@ -25,8 +25,7 @@ void MidiManagerUsb::StartInitialization() { base::Bind(&MidiManager::CompleteInitialization, base::Unretained(this))); } -void MidiManagerUsb::Initialize( - base::Callback<void(MidiResult result)> callback) { +void MidiManagerUsb::Initialize(base::Callback<void(Result result)> callback) { initialize_callback_ = callback; scheduler_.reset(new MidiScheduler(this)); // This is safe because EnumerateDevices cancels the operation on destruction. @@ -103,18 +102,18 @@ void MidiManagerUsb::OnReceivedData(size_t jack_index, void MidiManagerUsb::OnEnumerateDevicesDone(bool result, UsbMidiDevice::Devices* devices) { if (!result) { - initialize_callback_.Run(MIDI_INITIALIZATION_ERROR); + initialize_callback_.Run(Result::INITIALIZATION_ERROR); return; } input_stream_.reset(new UsbMidiInputStream(this)); devices->swap(devices_); for (size_t i = 0; i < devices_.size(); ++i) { if (!AddPorts(devices_[i], static_cast<int>(i))) { - initialize_callback_.Run(MIDI_INITIALIZATION_ERROR); + initialize_callback_.Run(Result::INITIALIZATION_ERROR); return; } } - initialize_callback_.Run(MIDI_OK); + initialize_callback_.Run(Result::OK); } bool MidiManagerUsb::AddPorts(UsbMidiDevice* device, int device_id) { diff --git a/media/midi/midi_manager_usb.h b/media/midi/midi_manager_usb.h index f5316bb..a91e3a3 100644 --- a/media/midi/midi_manager_usb.h +++ b/media/midi/midi_manager_usb.h @@ -70,7 +70,7 @@ class USB_MIDI_EXPORT MidiManagerUsb // will be canceled silently (i.e. |callback| will not be called). // The function is public just for unit tests. Do not call this function // outside code for testing. - void Initialize(base::Callback<void(MidiResult result)> callback); + void Initialize(base::Callback<void(Result result)> callback); private: void OnEnumerateDevicesDone(bool result, UsbMidiDevice::Devices* devices); @@ -81,7 +81,7 @@ class USB_MIDI_EXPORT MidiManagerUsb ScopedVector<UsbMidiOutputStream> output_streams_; scoped_ptr<UsbMidiInputStream> input_stream_; - base::Callback<void(MidiResult result)> initialize_callback_; + base::Callback<void(Result result)> initialize_callback_; // A map from <endpoint_number, cable_number> to the index of input jacks. base::hash_map<std::pair<int, int>, size_t> input_jack_dictionary_; diff --git a/media/midi/midi_manager_usb_unittest.cc b/media/midi/midi_manager_usb_unittest.cc index f43e93c..21dd236 100644 --- a/media/midi/midi_manager_usb_unittest.cc +++ b/media/midi/midi_manager_usb_unittest.cc @@ -91,7 +91,7 @@ class FakeMidiManagerClient : public MidiManagerClient { public: explicit FakeMidiManagerClient(Logger* logger) : complete_start_session_(false), - result_(MIDI_NOT_SUPPORTED), + result_(Result::NOT_SUPPORTED), logger_(logger) {} ~FakeMidiManagerClient() override {} @@ -107,7 +107,7 @@ class FakeMidiManagerClient : public MidiManagerClient { void SetOutputPortState(uint32 port_index, MidiPortState state) override {} - void CompleteStartSession(MidiResult result) override { + void CompleteStartSession(Result result) override { complete_start_session_ = true; result_ = result; } @@ -131,7 +131,7 @@ class FakeMidiManagerClient : public MidiManagerClient { } bool complete_start_session_; - MidiResult result_; + Result result_; MidiPortInfoList input_ports_; MidiPortInfoList output_ports_; @@ -163,7 +163,7 @@ class MidiManagerUsbForTesting : public MidiManagerUsb { : MidiManagerUsb(device_factory.Pass()) {} ~MidiManagerUsbForTesting() override {} - void CallCompleteInitialization(MidiResult result) { + void CallCompleteInitialization(Result result) { CompleteInitialization(result); base::RunLoop run_loop; run_loop.RunUntilIdle(); @@ -201,9 +201,7 @@ class MidiManagerUsbTest : public ::testing::Test { return client_->complete_start_session_; } - MidiResult GetInitializationResult() { - return client_->result_; - } + Result GetInitializationResult() { return client_->result_; } void RunCallbackUntilCallbackInvoked( bool result, UsbMidiDevice::Devices* devices) { @@ -258,7 +256,7 @@ TEST_F(MidiManagerUsbTest, Initialize) { devices.push_back(device.Pass()); EXPECT_FALSE(IsInitializationCallbackInvoked()); RunCallbackUntilCallbackInvoked(true, &devices); - EXPECT_EQ(MIDI_OK, GetInitializationResult()); + EXPECT_EQ(Result::OK, GetInitializationResult()); ASSERT_EQ(1u, input_ports().size()); EXPECT_EQ("port-0-2", input_ports()[0].id); @@ -319,7 +317,7 @@ TEST_F(MidiManagerUsbTest, InitializeMultipleDevices) { devices.push_back(device2.Pass()); EXPECT_FALSE(IsInitializationCallbackInvoked()); RunCallbackUntilCallbackInvoked(true, &devices); - EXPECT_EQ(MIDI_OK, GetInitializationResult()); + EXPECT_EQ(Result::OK, GetInitializationResult()); ASSERT_EQ(2u, input_ports().size()); EXPECT_EQ("port-0-2", input_ports()[0].id); @@ -368,7 +366,7 @@ TEST_F(MidiManagerUsbTest, InitializeFail) { EXPECT_FALSE(IsInitializationCallbackInvoked()); RunCallbackUntilCallbackInvoked(false, NULL); - EXPECT_EQ(MIDI_INITIALIZATION_ERROR, GetInitializationResult()); + EXPECT_EQ(Result::INITIALIZATION_ERROR, GetInitializationResult()); } TEST_F(MidiManagerUsbTest, InitializeFailBecauseOfInvalidDescriptors) { @@ -381,7 +379,7 @@ TEST_F(MidiManagerUsbTest, InitializeFailBecauseOfInvalidDescriptors) { devices.push_back(device.Pass()); EXPECT_FALSE(IsInitializationCallbackInvoked()); RunCallbackUntilCallbackInvoked(true, &devices); - EXPECT_EQ(MIDI_INITIALIZATION_ERROR, GetInitializationResult()); + EXPECT_EQ(Result::INITIALIZATION_ERROR, GetInitializationResult()); EXPECT_EQ("UsbMidiDevice::GetDescriptors\n", logger_.TakeLog()); } @@ -415,7 +413,7 @@ TEST_F(MidiManagerUsbTest, Send) { devices.push_back(device.Pass()); EXPECT_FALSE(IsInitializationCallbackInvoked()); RunCallbackUntilCallbackInvoked(true, &devices); - EXPECT_EQ(MIDI_OK, GetInitializationResult()); + EXPECT_EQ(Result::OK, GetInitializationResult()); ASSERT_EQ(2u, manager_->output_streams().size()); manager_->DispatchSendMidiData(client_.get(), 1, ToVector(data), 0); @@ -462,7 +460,7 @@ TEST_F(MidiManagerUsbTest, SendFromCompromizedRenderer) { devices.push_back(device.Pass()); EXPECT_FALSE(IsInitializationCallbackInvoked()); RunCallbackUntilCallbackInvoked(true, &devices); - EXPECT_EQ(MIDI_OK, GetInitializationResult()); + EXPECT_EQ(Result::OK, GetInitializationResult()); ASSERT_EQ(2u, manager_->output_streams().size()); EXPECT_EQ("UsbMidiDevice::GetDescriptors\n", logger_.TakeLog()); @@ -508,7 +506,7 @@ TEST_F(MidiManagerUsbTest, Receive) { devices.push_back(device.Pass()); EXPECT_FALSE(IsInitializationCallbackInvoked()); RunCallbackUntilCallbackInvoked(true, &devices); - EXPECT_EQ(MIDI_OK, GetInitializationResult()); + EXPECT_EQ(Result::OK, GetInitializationResult()); manager_->ReceiveUsbMidiData(device_raw, 2, data, arraysize(data), base::TimeTicks()); @@ -545,7 +543,7 @@ TEST_F(MidiManagerUsbTest, AttachDevice) { ScopedVector<UsbMidiDevice> devices; EXPECT_FALSE(IsInitializationCallbackInvoked()); RunCallbackUntilCallbackInvoked(true, &devices); - EXPECT_EQ(MIDI_OK, GetInitializationResult()); + EXPECT_EQ(Result::OK, GetInitializationResult()); ASSERT_EQ(0u, input_ports().size()); ASSERT_EQ(0u, output_ports().size()); diff --git a/media/midi/midi_manager_win.cc b/media/midi/midi_manager_win.cc index 8843040..4b7170a 100644 --- a/media/midi/midi_manager_win.cc +++ b/media/midi/midi_manager_win.cc @@ -489,7 +489,7 @@ class MidiServiceWinImpl : public MidiServiceWin, task_thread_.message_loop()->PostTask( FROM_HERE, base::Bind(&MidiServiceWinImpl::CompleteInitializationOnTaskThread, - base::Unretained(this), MIDI_OK)); + base::Unretained(this), Result::OK)); } void SendMidiDataAsync(uint32 port_number, @@ -1033,7 +1033,7 @@ class MidiServiceWinImpl : public MidiServiceWin, state->start_time_initialized = true; } - void CompleteInitializationOnTaskThread(MidiResult result) { + void CompleteInitializationOnTaskThread(Result result) { AssertOnTaskThread(); delegate_->OnCompleteInitialization(result); } @@ -1139,7 +1139,7 @@ void MidiManagerWin::DispatchSendMidiData(MidiManagerClient* client, client->AccumulateMidiBytesSent(data.size()); } -void MidiManagerWin::OnCompleteInitialization(MidiResult result) { +void MidiManagerWin::OnCompleteInitialization(Result result) { CompleteInitialization(result); } diff --git a/media/midi/midi_manager_win.h b/media/midi/midi_manager_win.h index f559841..dbee7e1 100644 --- a/media/midi/midi_manager_win.h +++ b/media/midi/midi_manager_win.h @@ -19,7 +19,7 @@ namespace midi { class MidiServiceWinDelegate { public: virtual ~MidiServiceWinDelegate() {} - virtual void OnCompleteInitialization(MidiResult result) = 0; + virtual void OnCompleteInitialization(Result result) = 0; virtual void OnAddInputPort(MidiPortInfo info) = 0; virtual void OnAddOutputPort(MidiPortInfo info) = 0; virtual void OnSetInputPortState(uint32 port_index, MidiPortState state) = 0; @@ -53,7 +53,7 @@ class MidiManagerWin final : public MidiManager, public MidiServiceWinDelegate { double timestamp) final; // MidiServiceWinDelegate overrides: - void OnCompleteInitialization(MidiResult result) final; + void OnCompleteInitialization(Result result) final; void OnAddInputPort(MidiPortInfo info) final; void OnAddOutputPort(MidiPortInfo info) final; void OnSetInputPortState(uint32 port_index, MidiPortState state) final; diff --git a/media/midi/midi_result.h b/media/midi/midi_result.h deleted file mode 100644 index 5432dca..0000000 --- a/media/midi/midi_result.h +++ /dev/null @@ -1,27 +0,0 @@ -// 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 MEDIA_MIDI_MIDI_RESULT_H_ -#define MEDIA_MIDI_MIDI_RESULT_H_ - -namespace media { -namespace midi { - -// Result codes for MIDI. -enum MidiResult { - MIDI_NOT_INITIALIZED = -1, - MIDI_OK = 0, - MIDI_NOT_SUPPORTED, - MIDI_INITIALIZATION_ERROR, - - // |MIDI_RESULT_LAST| is used in content/common/media/midi_messages.h with - // IPC_ENUM_TRAITS_MAX_VALUE macro. Keep the value up to date. Otherwise - // a new value can not be passed to the renderer. - MIDI_RESULT_LAST = MIDI_INITIALIZATION_ERROR, -}; - -} // namespace midi -} // namespace media - -#endif // MEDIA_MIDI_MIDI_RESULT_H_ diff --git a/media/midi/result.h b/media/midi/result.h new file mode 100644 index 0000000..8214cd2 --- /dev/null +++ b/media/midi/result.h @@ -0,0 +1,30 @@ +// Copyright 2015 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 MEDIA_MIDI_RESULT_H_ +#define MEDIA_MIDI_RESULT_H_ + +namespace media { +namespace midi { + +// Result codes for MIDI. +enum class Result { + NOT_INITIALIZED = 0, + OK, + NOT_SUPPORTED, + INITIALIZATION_ERROR, + // New code should be inserted here so that existing members keep the same + // assigned value. tools/metrics/histograms/histograms.xml contains Result + // enum entry, and it should be consistent with enum class Result. + + // |MAX| is used in content/common/media/midi_messages.h with + // IPC_ENUM_TRAITS_MAX_VALUE macro. Keep the value up to date. Otherwise + // a new value can not be passed to the renderer. + MAX = INITIALIZATION_ERROR, +}; + +} // namespace midi +} // namespace media + +#endif // MEDIA_MIDI_RESULT_H_ diff --git a/tools/metrics/histograms/histograms.xml b/tools/metrics/histograms/histograms.xml index ea29cad..e28eb8a 100644 --- a/tools/metrics/histograms/histograms.xml +++ b/tools/metrics/histograms/histograms.xml @@ -16092,6 +16092,11 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries. </summary> </histogram> +<histogram name="Media.Midi.ResultOnShutdown" enum="MidiResult"> + <owner>toyoshim@chromium.org</owner> + <summary>The final status of MidiManager on browser shutdown.</summary> +</histogram> + <histogram name="Media.MSE.AudioCodec" enum="MSECodec"> <owner>acolwell@chromium.org</owner> <summary> @@ -61728,6 +61733,13 @@ To add a new entry, add it with any value and run test to compute valid value. <int value="1" label="Not muted"/> </enum> +<enum name="MidiResult" type="int"> + <int value="0" label="Not initialized"/> + <int value="1" label="Successfully initialized"/> + <int value="2" label="Not supported"/> + <int value="3" label="Generic initialization error"/> +</enum> + <enum name="MigrationNssToPemNetworkTypes" type="int"> <int value="0" label="EAP"/> <int value="1" label="OpenVPN"/> |