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 // The result of an authorization check. In addition to the status, | |
| 32 // it indicates whether a device was found using the session_id in the | |
| 33 // variable should_send_id, in which case the renderer expects to get the id | |
| 34 // hash. It also has the default audio parameters for the device, and the id | |
| 35 // for the device, which is needed to open a stream for the device. This id | |
| 36 // is not hashed, so it must be hashed before sending it to the renderer. | |
| 37 // TODO(maxmorin): Change to OnceCallback once base:: code is ready for it. | |
| 38 using AuthorizationCompletedCallback = | |
| 39 base::Callback<void(media::OutputDeviceStatus status, | |
| 40 bool should_send_id, | |
| 41 const media::AudioParameters& params, | |
| 42 const std::string& raw_device_id)>; | |
| 43 | |
| 44 AudioOutputAuthorizationHandler(MediaStreamManager* media_stream_manager, | |
| 45 int render_process_id_, | |
| 46 const std::string& salt); | |
| 47 | |
| 48 ~AudioOutputAuthorizationHandler(); | |
| 49 | |
| 50 // 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 | |
| 52 // authorization. Looks up device id (if session_id is used for device | |
| 53 // selection) and default device parameters. | |
| 54 void RequestDeviceAuthorization(int render_frame_id, | |
| 55 int session_id, | |
| 56 const std::string& device_id, | |
| 57 const url::Origin& security_origin, | |
| 58 AuthorizationCompletedCallback cb) const; | |
| 59 | |
| 60 // Calling this method will make the checks for permission from the user | |
| 61 // always return |override_value|. | |
| 62 void OverridePermissionsForTesting(bool override_value); | |
| 63 | |
| 64 private: | |
| 65 // The comments give a simplified overview of implementation. The sequence of | |
| 66 // calls can be broken at various places, e.g. if access rights are missing or | |
| 67 // the device cannot be found. In this case, a non-ok status indicating the | |
| 68 // error is returned through the callback. | |
| 69 | |
| 70 // RequestDeviceAuthorization will check if |session_id| should be used. If | |
| 71 // yes, fetch saved device and parameters and skip to | |
| 72 // DeviceParametersRecieved. Otherwise, check whether the renderer has access | |
| 73 // to the output device (async in case of a nondefault device). Result goes to | |
| 74 // AccessChecked. | |
| 75 | |
| 76 // Calls GetDeviceParameters for default devices. Nondefault devices first | |
| 77 // goes to TranslateDeviceId. | |
| 78 void AccessChecked(AuthorizationCompletedCallback cb, | |
| 79 const std::string& device_id, | |
| 80 const url::Origin& security_origin, | |
| 81 bool have_access) const; | |
|
o1ka
2016/11/16 15:11:28
has_access?
Max Morin
2016/11/16 15:54:36
Fixed. I'm surprised the compiler doesn't warn abo
| |
| 82 | |
| 83 // Takes the |device_id|,which is hashed, and finds the corresponding raw | |
| 84 // device id. After that, it calls GetDeviceParameters with the result. | |
|
o1ka
2016/11/16 15:11:28
Agree with Guido: we don;t need a description of w
Max Morin
2016/11/16 15:54:36
Done.
| |
| 85 void TranslateDeviceID(AuthorizationCompletedCallback cb, | |
| 86 const std::string& device_id, | |
| 87 const url::Origin& security_origin, | |
| 88 const MediaDeviceEnumeration& enumeration) const; | |
| 89 | |
| 90 // Takes a raw device id and gets the default device parameters for the device | |
| 91 // from the OS. Calls DeviceParametersReceived. | |
| 92 void GetDeviceParameters(AuthorizationCompletedCallback cb, | |
| 93 const std::string& raw_device_id) const; | |
| 94 | |
| 95 // Returns by calling the callback. |should_send_id| indicates whether the | |
| 96 // renderer expects to get the chosen id back, which is the case if a device | |
| 97 // was found using a session id. | |
| 98 void DeviceParametersReceived( | |
| 99 AuthorizationCompletedCallback cb, | |
| 100 bool should_send_id, | |
| 101 const std::string& raw_device_id, | |
| 102 const media::AudioParameters& output_params) const; | |
| 103 | |
| 104 MediaStreamManager* const media_stream_manager_; | |
| 105 std::unique_ptr<MediaDevicesPermissionChecker> permission_checker_; | |
| 106 const int render_process_id_; | |
| 107 const std::string salt_; | |
| 108 // All access is on the IO thread, and taking a weak pointer to const looks | |
| 109 // const, so this can be mutable. | |
| 110 mutable base::WeakPtrFactory<const AudioOutputAuthorizationHandler> | |
| 111 weak_factory_; | |
| 112 | |
| 113 DISALLOW_COPY_AND_ASSIGN(AudioOutputAuthorizationHandler); | |
| 114 }; | |
| 115 | |
| 116 } // namespace content | |
| 117 | |
| 118 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_AUTHORIZATION_HANDLE R_H_ | |
| OLD | NEW |