OLD | NEW |
| (Empty) |
1 // Copyright 2013 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 #ifndef CHROME_BROWSER_MEDIA_DESKTOP_STREAMS_REGISTRY_H_ | |
6 #define CHROME_BROWSER_MEDIA_DESKTOP_STREAMS_REGISTRY_H_ | |
7 | |
8 #include <map> | |
9 #include <string> | |
10 | |
11 #include "base/macros.h" | |
12 #include "chrome/browser/media/desktop_media_list.h" | |
13 #include "url/gurl.h" | |
14 | |
15 // DesktopStreamsRegistry is used to store accepted desktop media streams for | |
16 // Desktop Capture API. Single instance of this class is created per browser in | |
17 // MediaCaptureDevicesDispatcher. | |
18 class DesktopStreamsRegistry { | |
19 public: | |
20 DesktopStreamsRegistry(); | |
21 ~DesktopStreamsRegistry(); | |
22 | |
23 // Adds new stream to the registry. Called by the implementation of | |
24 // desktopCapture.chooseDesktopMedia() API after user has approved access to | |
25 // |source| for the |origin|. Returns identifier of the new stream. | |
26 // |render_frame_id| refers to the RenderFrame requesting the stream. | |
27 std::string RegisterStream(int render_process_id, | |
28 int render_frame_id, | |
29 const GURL& origin, | |
30 const content::DesktopMediaID& source, | |
31 const std::string& extension_name); | |
32 | |
33 // Validates stream identifier specified in getUserMedia(). Returns null | |
34 // DesktopMediaID if the specified |id| is invalid, i.e. wasn't generated | |
35 // using RegisterStream() or if it was generated for a different | |
36 // RenderFrame/origin. Otherwise returns ID of the source and removes it from | |
37 // the registry. | |
38 content::DesktopMediaID RequestMediaForStreamId(const std::string& id, | |
39 int render_process_id, | |
40 int render_frame_id, | |
41 const GURL& origin, | |
42 std::string* extension_name); | |
43 | |
44 private: | |
45 // Type used to store list of accepted desktop media streams. | |
46 struct ApprovedDesktopMediaStream { | |
47 ApprovedDesktopMediaStream(); | |
48 | |
49 int render_process_id; | |
50 int render_frame_id; | |
51 GURL origin; | |
52 content::DesktopMediaID source; | |
53 std::string extension_name; | |
54 }; | |
55 typedef std::map<std::string, ApprovedDesktopMediaStream> StreamsMap; | |
56 | |
57 // Helper function that removes an expired stream from the registry. | |
58 void CleanupStream(const std::string& id); | |
59 | |
60 StreamsMap approved_streams_; | |
61 | |
62 DISALLOW_COPY_AND_ASSIGN(DesktopStreamsRegistry); | |
63 }; | |
64 | |
65 #endif // CHROME_BROWSER_MEDIA_DESKTOP_STREAMS_REGISTRY_H_ | |
OLD | NEW |