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

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

Issue 2424163004: Factor out authorization from AudioRendererHost. (Closed)
Patch Set: Guidos comments. Created 4 years, 1 month 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..c75e5b309f880780487dfe9b0bf1cb4f1cfe76c6
--- /dev/null
+++ b/content/browser/renderer_host/media/audio_output_authorization_handler.h
@@ -0,0 +1,90 @@
+// 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/media/media_devices_permission_checker.h"
+#include "content/browser/renderer_host/media/media_stream_manager.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 {
+
+// This class, which lives on the IO thread, handles the logic of an IPC device
+// request from the renderer. It checks which device to use (in case of using
+// session_id to select device), verifies that the renderer is authorized to use
+// the device, and gets the default device parameters for the selected audio
+// device.
+class CONTENT_EXPORT AudioOutputAuthorizationHandler {
+ public:
+ // TODO(maxmorin): Change to OnceCallback once base:: code is ready for it.
+ using AuthorizationCompletedCallback =
+ base::Callback<void(media::OutputDeviceStatus,
+ media::AudioParameters,
+ const std::string&)>;
+
+ AudioOutputAuthorizationHandler(MediaStreamManager* media_stream_manager,
+ int render_process_id_,
+ const std::string& salt);
+
+ ~AudioOutputAuthorizationHandler();
+
+ // Checks authorization of the device with the hashed id device_id for the
+ // given render frame id and security origin, or uses session_id for
+ // authorization. Looks up device id (if session_id is used for device
+ // selection) and default device parameters. |cb| will be called with the
+ // result by |this| on the IO thread.
+ void RequestDeviceAuthorization(int render_frame_id,
+ int session_id,
+ const std::string& device_id,
+ const url::Origin& security_origin,
+ AuthorizationCompletedCallback cb);
DaleCurtis 2016/11/01 22:01:13 "Pass `Callback` objects by value if ownership is
Max Morin 2016/11/02 11:47:06 By value makes sense here. Since we bind it in ano
+
+ MediaDevicesPermissionChecker& GetMediaDevicesPermissionCheckerForTesting() {
+ return permission_checker_;
+ }
+
+ private:
+ void CheckOutputDeviceAccess(AuthorizationCompletedCallback cb,
+ int render_frame_id,
+ const std::string& device_id,
+ const url::Origin& security_origin);
+
+ void AccessChecked(AuthorizationCompletedCallback cb,
+ 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);
+
+ // |output_params| is passed by value since it's possibly mutated by this
+ // function, so it would have to be copied anyways.
+ void DeviceParametersReceived(AuthorizationCompletedCallback cb,
+ bool device_found,
+ const std::string& unique_id,
+ media::AudioParameters output_params);
+
+ MediaStreamManager* const media_stream_manager_;
+ MediaDevicesPermissionChecker permission_checker_;
+ const int render_process_id_;
+ const std::string salt_;
+ base::WeakPtrFactory<AudioOutputAuthorizationHandler> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(AudioOutputAuthorizationHandler);
+};
+} // namespace content
+#endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_AUTHORIZATION_HANDLER_H_
Avi (use Gerrit) 2016/11/01 15:06:34 nit: two blank lines, one after the closing of the
Max Morin 2016/11/02 11:47:06 Done.

Powered by Google App Engine
This is Rietveld 408576698