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

Side by Side Diff: content/browser/renderer_host/media/audio_output_authorization_handler.h

Issue 2424163004: Factor out authorization from AudioRendererHost. (Closed)
Patch Set: Guidos 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 unified diff | Download patch
OLDNEW
(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,
34 media::AudioParameters,
35 const std::string&)>;
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.
48 void RequestDeviceAuthorization(int render_frame_id,
49 int session_id,
50 const std::string& device_id,
51 const url::Origin& security_origin,
52 AuthorizationCompletedCallback cb);
DaleCurtis 2016/11/01 22:01:13 "Pass `Callback` objects by value if ownership is
Max Morin 2016/11/02 11:47:06 By value makes sense here. Since we bind it in ano
53
54 MediaDevicesPermissionChecker& GetMediaDevicesPermissionCheckerForTesting() {
55 return permission_checker_;
56 }
57
58 private:
59 void CheckOutputDeviceAccess(AuthorizationCompletedCallback cb,
60 int render_frame_id,
61 const std::string& device_id,
62 const url::Origin& security_origin);
63
64 void AccessChecked(AuthorizationCompletedCallback cb,
65 const std::string& device_id,
66 const url::Origin& security_origin,
67 bool have_access);
68
69 void TranslateDeviceID(AuthorizationCompletedCallback cb,
70 const std::string& device_id,
71 const url::Origin& security_origin,
72 const MediaDeviceEnumeration& enumeration);
73
74 // |output_params| is passed by value since it's possibly mutated by this
75 // function, so it would have to be copied anyways.
76 void DeviceParametersReceived(AuthorizationCompletedCallback cb,
77 bool device_found,
78 const std::string& unique_id,
79 media::AudioParameters output_params);
80
81 MediaStreamManager* const media_stream_manager_;
82 MediaDevicesPermissionChecker permission_checker_;
83 const int render_process_id_;
84 const std::string salt_;
85 base::WeakPtrFactory<AudioOutputAuthorizationHandler> weak_factory_;
86
87 DISALLOW_COPY_AND_ASSIGN(AudioOutputAuthorizationHandler);
88 };
89 } // namespace content
90 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_AUTHORIZATION_HANDLE R_H_
Avi (use Gerrit) 2016/11/01 15:06:34 nit: two blank lines, one after the closing of the
Max Morin 2016/11/02 11:47:06 Done.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698