Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // This class implements authorization checking for AudioRendererHost. | |
| 6 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_AUTHORIZATION_HANDLER_H _ | |
| 7 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_AUTHORIZATION_HANDLER_H _ | |
| 8 | |
| 9 #include <memory> | |
| 10 #include <string> | |
| 11 #include <utility> | |
| 12 | |
| 13 #include "base/callback_forward.h" | |
| 14 #include "base/memory/weak_ptr.h" | |
| 15 #include "content/browser/media/media_devices_permission_checker.h" | |
| 16 #include "content/browser/renderer_host/media/media_stream_manager.h" | |
| 17 #include "media/audio/audio_device_description.h" | |
| 18 #include "media/audio/audio_manager.h" | |
| 19 #include "media/base/audio_parameters.h" | |
| 20 #include "media/base/output_device_info.h" | |
| 21 | |
| 22 namespace content { | |
| 23 | |
| 24 // This class, which lives on the IO thread, handles the logic of an IPC device | |
| 25 // request from the renderer. It checks which device to use (in case of using | |
| 26 // session_id to select device), verifies that the renderer is authorized to use | |
| 27 // the device, and gets the default device parameters for the selected audio | |
| 28 // device. | |
| 29 class CONTENT_EXPORT AudioOutputAuthorizationHandler { | |
| 30 public: | |
| 31 // TODO(maxmorin): Change to OnceCallback once base:: code is ready for it. | |
| 32 using AuthorizationCompletedCallback = | |
| 33 base::Callback<void(media::OutputDeviceStatus status, | |
| 34 const media::AudioParameters& params, | |
| 35 const std::string& translated_device_id)>; | |
| 36 | |
| 37 AudioOutputAuthorizationHandler(MediaStreamManager* media_stream_manager, | |
| 38 int render_process_id_, | |
| 39 const std::string& salt); | |
| 40 | |
| 41 ~AudioOutputAuthorizationHandler(); | |
| 42 | |
| 43 // Checks authorization of the device with the hashed id device_id for the | |
| 44 // given render frame id and security origin, or uses session_id for | |
| 45 // authorization. Looks up device id (if session_id is used for device | |
| 46 // selection) and default device parameters. |cb| will be called with the | |
| 47 // result by |this| on the IO thread. The device_id returned in the callback | |
| 48 // will be translated, i.e. not hashed. | |
|
Guido Urdaneta
2016/11/10 15:26:05
remove "i.e. not hashed".
"translated" is precise
Max Morin
2016/11/11 09:26:55
It is translated from hashed to non-hashed. The AR
| |
| 49 void RequestDeviceAuthorization(int render_frame_id, | |
| 50 int session_id, | |
| 51 const std::string& device_id, | |
| 52 const url::Origin& security_origin, | |
| 53 AuthorizationCompletedCallback cb) const; | |
| 54 | |
| 55 void OverridePermissionsForTesting(bool override_value); | |
| 56 | |
| 57 private: | |
| 58 // A simplified overview of implementation: | |
| 59 // RequestDeviceAuthorization: | |
| 60 // Check if session_id should be used. If yes, fetch saved device and | |
| 61 // parameters and we can skip to DeviceParametersRecieved. Otherwise, | |
| 62 // check whether the renderer has access to the output device | |
| 63 // (async in case of a nondefault device). Result goes to AccessChecked. | |
| 64 // AccessChecked: | |
| 65 // Queries audio parameters for default devices and calls | |
| 66 // DeviceParametersRecieved. Nondefault devices go | |
| 67 // through TranslateDeviceID. | |
| 68 // TranslateDeviceID: | |
| 69 // Checks which raw device id corresponds to the hashed device_id, | |
| 70 // and then gets default parameters for it and calls | |
| 71 // DeviceParametersRecieved with the parameters and the translated id. | |
| 72 // DeviceParametersRecieved: | |
| 73 // Returns by calling the callback. | |
| 74 // | |
| 75 // This sequence of calls can be broken at various places, e.g. if access | |
| 76 // rights are missing or the device cannot be found. In this case, a non-Ok | |
| 77 // status indicating the error is returned through the callback. | |
| 78 | |
| 79 void AccessChecked(AuthorizationCompletedCallback cb, | |
| 80 const std::string& device_id, | |
| 81 const url::Origin& security_origin, | |
| 82 bool have_access) const; | |
| 83 | |
| 84 void TranslateDeviceID(AuthorizationCompletedCallback cb, | |
| 85 const std::string& device_id, | |
| 86 const url::Origin& security_origin, | |
| 87 const MediaDeviceEnumeration& enumeration) const; | |
| 88 | |
| 89 void DeviceParametersReceived( | |
| 90 AuthorizationCompletedCallback cb, | |
| 91 const std::string& translated_device_id, | |
| 92 const media::AudioParameters& output_params) const; | |
| 93 | |
| 94 MediaStreamManager* const media_stream_manager_; | |
| 95 std::unique_ptr<MediaDevicesPermissionChecker> permission_checker_; | |
| 96 const int render_process_id_; | |
| 97 const std::string salt_; | |
| 98 // All access is on IO thread, and taking a weak pointer to const looks | |
| 99 // const, so this can be mutable. | |
| 100 mutable base::WeakPtrFactory<const AudioOutputAuthorizationHandler> | |
| 101 weak_factory_; | |
| 102 | |
| 103 DISALLOW_COPY_AND_ASSIGN(AudioOutputAuthorizationHandler); | |
| 104 }; | |
| 105 | |
| 106 } // namespace content | |
| 107 | |
| 108 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_AUTHORIZATION_HANDLE R_H_ | |
| OLD | NEW |