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

Unified Diff: content/browser/renderer_host/media/audio_output_authorization_handler.h

Issue 2424163004: Factor out authorization from AudioRendererHost. (Closed)
Patch Set: Remove unnecessary weak pointer use. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/media/audio_output_authorization_handler.h
diff --git a/content/browser/renderer_host/media/audio_output_authorization_handler.h b/content/browser/renderer_host/media/audio_output_authorization_handler.h
new file mode 100644
index 0000000000000000000000000000000000000000..24b119292a181ea7a35f4fe0932a41a6c097e2d6
--- /dev/null
+++ b/content/browser/renderer_host/media/audio_output_authorization_handler.h
@@ -0,0 +1,85 @@
+// Copyright 2016 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.
+
+// This class implements authorization checking for AudioRendererHost.
+#ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_AUTHORIZATION_HANDLER_H_
+#define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_AUTHORIZATION_HANDLER_H_
+
+#include <memory>
+#include <string>
+#include <utility>
+
+#include "base/callback_forward.h"
+#include "base/memory/weak_ptr.h"
+#include "content/browser/bad_message.h"
+#include "content/browser/renderer_host/media/media_stream_manager.h"
+#include "content/browser/renderer_host/media/media_stream_ui_proxy.h"
+#include "media/audio/audio_device_description.h"
+#include "media/audio/audio_manager.h"
+#include "media/base/audio_parameters.h"
+#include "media/base/output_device_info.h"
+
+namespace content {
+class AudioOutputAuthorizationHandler {
+ public:
+ using AuthorizationCompletedCallback =
+ base::Callback<void(media::OutputDeviceStatus,
+ media::AudioParameters,
+ const std::string&)>;
+
+ using BadMessageHandler =
+ base::Callback<void(content::bad_message::BadMessageReason)>;
+
+ AudioOutputAuthorizationHandler(MediaStreamManager* media_stream_manager,
+ int render_process_id_,
+ const std::string& salt);
+
+ ~AudioOutputAuthorizationHandler();
+
+ // Checks authorization of the device with device_id for the given
+ // render frame id and security origin, or uses session_id
+ // for authorization.
+ void RequestDeviceAuthorization(int render_frame_id,
+ int session_id,
+ const std::string& device_id,
+ const url::Origin& security_origin,
+ AuthorizationCompletedCallback cb);
o1ka 2016/10/27 13:58:09 everywhere: pass the callback around as const refe
Max Morin 2016/10/28 11:16:07 How would we guarantee that it's alive in that cas
+
+ // In case an invalid request is recieved, this handler will be called.
+ void SetBadMessageHandler(BadMessageHandler handler) {
+ bad_message_handler_ = std::move(handler);
+ }
+
+ private:
+ void CheckOutputDeviceAccess(AuthorizationCompletedCallback cb,
+ int render_frame_id,
+ const std::string& device_id,
+ const url::Origin& security_origin);
+
+ void AccessChecked(AuthorizationCompletedCallback cb,
+ std::unique_ptr<MediaStreamUIProxy> ui_proxy,
+ const std::string& device_id,
+ const url::Origin& security_origin,
+ bool have_access);
+
+ void TranslateDeviceID(AuthorizationCompletedCallback cb,
+ const std::string& device_id,
+ const url::Origin& security_origin,
+ const MediaDeviceEnumeration& enumeration);
+
+ void DeviceParametersReceived(AuthorizationCompletedCallback cb,
+ bool device_found,
+ const std::string& unique_id,
+ media::AudioParameters output_params);
+
+ MediaStreamManager* const media_stream_manager_;
+ const int render_process_id_;
+ const std::string salt_;
+ BadMessageHandler bad_message_handler_;
+ base::WeakPtrFactory<AudioOutputAuthorizationHandler> weak_factory;
+
+ DISALLOW_COPY_AND_ASSIGN(AudioOutputAuthorizationHandler);
+};
+} // namespace content
+#endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_AUTHORIZATION_HANDLER_H_

Powered by Google App Engine
This is Rietveld 408576698