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