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