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

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

Issue 2424163004: Factor out authorization from AudioRendererHost. (Closed)
Patch Set: Dale's 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..5a5b043ed03afeae84578abdb3d287983265d8cd
--- /dev/null
+++ b/content/browser/renderer_host/media/audio_output_authorization_handler.h
@@ -0,0 +1,92 @@
+// 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 =
o1ka 2016/11/03 10:07:22 Please explain parameters meaning in the comment -
Max Morin 2016/11/10 14:59:52 I added this to the comment on RequestDeviceAuthor
+ base::Callback<void(media::OutputDeviceStatus,
+ const 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,
o1ka 2016/11/03 10:07:22 const method?
Max Morin 2016/11/10 14:59:52 Done.
+ int session_id,
+ const std::string& device_id,
+ const url::Origin& security_origin,
+ AuthorizationCompletedCallback cb);
+
+ MediaDevicesPermissionChecker& GetMediaDevicesPermissionCheckerForTesting() {
o1ka 2016/11/03 10:07:22 I feel like it should be const ref. Probably fix M
Max Morin 2016/11/10 14:59:52 The purpose was actually to allow the caller to mo
+ return permission_checker_;
+ }
+
+ private:
+ void CheckOutputDeviceAccess(AuthorizationCompletedCallback cb,
o1ka 2016/11/03 10:07:22 all methods const?
Max Morin 2016/11/10 14:59:52 Done.
+ int render_frame_id,
+ const std::string& device_id,
+ const url::Origin& security_origin);
+
+ void AccessChecked(AuthorizationCompletedCallback cb,
o1ka 2016/11/03 10:07:22 We need to explain each of the methods here.
Max Morin 2016/11/10 14:59:52 I added an overview of how the implementation of R
+ 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,
+ const 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_

Powered by Google App Engine
This is Rietveld 408576698