| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_AUTHORIZATION_HANDLER_H
_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_AUTHORIZATION_HANDLER_H
_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_AUTHORIZATION_HANDLER_H
_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_AUTHORIZATION_HANDLER_H
_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/callback_forward.h" | 12 #include "base/callback_forward.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "content/browser/media/media_devices_permission_checker.h" | 14 #include "content/browser/media/media_devices_permission_checker.h" |
| 15 #include "content/browser/renderer_host/media/media_stream_manager.h" | 15 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 16 #include "media/audio/audio_device_description.h" | 16 #include "media/audio/audio_device_description.h" |
| 17 #include "media/audio/audio_manager.h" | |
| 18 #include "media/base/audio_parameters.h" | 17 #include "media/base/audio_parameters.h" |
| 19 #include "media/base/output_device_info.h" | 18 #include "media/base/output_device_info.h" |
| 20 | 19 |
| 20 namespace media { |
| 21 class AudioSystem; |
| 22 } |
| 23 |
| 21 namespace content { | 24 namespace content { |
| 22 | 25 |
| 23 // This class, which lives on the IO thread, handles the logic of an IPC device | 26 // This class, which lives on the IO thread, handles the logic of an IPC device |
| 24 // request from the renderer. It checks which device to use (in case of using | 27 // request from the renderer. It checks which device to use (in case of using |
| 25 // |session_id| to select device), verifies that the renderer is authorized to | 28 // |session_id| to select device), verifies that the renderer is authorized to |
| 26 // use the device, and gets the default device parameters for the selected audio | 29 // use the device, and gets the default device parameters for the selected audio |
| 27 // device. | 30 // device. |
| 28 class CONTENT_EXPORT AudioOutputAuthorizationHandler { | 31 class CONTENT_EXPORT AudioOutputAuthorizationHandler { |
| 29 public: | 32 public: |
| 30 // The result of an authorization check. In addition to the status, it | 33 // The result of an authorization check. In addition to the status, it |
| 31 // indicates whether a device was found using the |session_id| in the variable | 34 // indicates whether a device was found using the |session_id| in the variable |
| 32 // |should_send_id|, in which case the renderer expects to get the id hash. It | 35 // |should_send_id|, in which case the renderer expects to get the id hash. It |
| 33 // also has the default audio parameters for the device, and the id for the | 36 // also has the default audio parameters for the device, and the id for the |
| 34 // device, which is needed to open a stream for the device. This id is not | 37 // device, which is needed to open a stream for the device. This id is not |
| 35 // hashed, so it must be hashed before sending it to the renderer. | 38 // hashed, so it must be hashed before sending it to the renderer. |
| 36 // TODO(maxmorin): Change to OnceCallback once base:: code is ready for it. | 39 // TODO(maxmorin): Change to OnceCallback once base:: code is ready for it. |
| 37 using AuthorizationCompletedCallback = | 40 using AuthorizationCompletedCallback = |
| 38 base::Callback<void(media::OutputDeviceStatus status, | 41 base::Callback<void(media::OutputDeviceStatus status, |
| 39 bool should_send_id, | 42 bool should_send_id, |
| 40 const media::AudioParameters& params, | 43 const media::AudioParameters& params, |
| 41 const std::string& raw_device_id)>; | 44 const std::string& raw_device_id)>; |
| 42 | 45 |
| 43 AudioOutputAuthorizationHandler(media::AudioManager* audio_manager, | 46 AudioOutputAuthorizationHandler(media::AudioSystem* audio_system, |
| 44 MediaStreamManager* media_stream_manager, | 47 MediaStreamManager* media_stream_manager, |
| 45 int render_process_id_, | 48 int render_process_id_, |
| 46 const std::string& salt); | 49 const std::string& salt); |
| 47 | 50 |
| 48 ~AudioOutputAuthorizationHandler(); | 51 ~AudioOutputAuthorizationHandler(); |
| 49 | 52 |
| 50 // Checks authorization of the device with the hashed id |device_id| for the | 53 // Checks authorization of the device with the hashed id |device_id| for the |
| 51 // given render frame id and security origin, or uses |session_id| for | 54 // given render frame id and security origin, or uses |session_id| for |
| 52 // authorization. Looks up device id (if |session_id| is used for device | 55 // authorization. Looks up device id (if |session_id| is used for device |
| 53 // selection) and default device parameters. | 56 // selection) and default device parameters. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 77 | 80 |
| 78 void GetDeviceParameters(AuthorizationCompletedCallback cb, | 81 void GetDeviceParameters(AuthorizationCompletedCallback cb, |
| 79 const std::string& raw_device_id) const; | 82 const std::string& raw_device_id) const; |
| 80 | 83 |
| 81 void DeviceParametersReceived( | 84 void DeviceParametersReceived( |
| 82 AuthorizationCompletedCallback cb, | 85 AuthorizationCompletedCallback cb, |
| 83 bool should_send_id, | 86 bool should_send_id, |
| 84 const std::string& raw_device_id, | 87 const std::string& raw_device_id, |
| 85 const media::AudioParameters& output_params) const; | 88 const media::AudioParameters& output_params) const; |
| 86 | 89 |
| 87 media::AudioManager* audio_manager_; | 90 media::AudioSystem* audio_system_; |
| 88 MediaStreamManager* const media_stream_manager_; | 91 MediaStreamManager* const media_stream_manager_; |
| 89 std::unique_ptr<MediaDevicesPermissionChecker> permission_checker_; | 92 std::unique_ptr<MediaDevicesPermissionChecker> permission_checker_; |
| 90 const int render_process_id_; | 93 const int render_process_id_; |
| 91 const std::string salt_; | 94 const std::string salt_; |
| 92 // All access is on the IO thread, and taking a weak pointer to const looks | 95 // All access is on the IO thread, and taking a weak pointer to const looks |
| 93 // const, so this can be mutable. | 96 // const, so this can be mutable. |
| 94 mutable base::WeakPtrFactory<const AudioOutputAuthorizationHandler> | 97 mutable base::WeakPtrFactory<const AudioOutputAuthorizationHandler> |
| 95 weak_factory_; | 98 weak_factory_; |
| 96 | 99 |
| 97 DISALLOW_COPY_AND_ASSIGN(AudioOutputAuthorizationHandler); | 100 DISALLOW_COPY_AND_ASSIGN(AudioOutputAuthorizationHandler); |
| 98 }; | 101 }; |
| 99 | 102 |
| 100 } // namespace content | 103 } // namespace content |
| 101 | 104 |
| 102 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_AUTHORIZATION_HANDLE
R_H_ | 105 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_AUTHORIZATION_HANDLE
R_H_ |
| OLD | NEW |