OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/media/desktop_streams_registry.h" | 5 #include "chrome/browser/media/desktop_streams_registry.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 } // namespace | 28 } // namespace |
29 | 29 |
30 DesktopStreamsRegistry::DesktopStreamsRegistry() {} | 30 DesktopStreamsRegistry::DesktopStreamsRegistry() {} |
31 DesktopStreamsRegistry::~DesktopStreamsRegistry() {} | 31 DesktopStreamsRegistry::~DesktopStreamsRegistry() {} |
32 | 32 |
33 std::string DesktopStreamsRegistry::RegisterStream( | 33 std::string DesktopStreamsRegistry::RegisterStream( |
34 int render_process_id, | 34 int render_process_id, |
35 int render_view_id, | 35 int render_view_id, |
36 const GURL& origin, | 36 const GURL& origin, |
37 const content::DesktopMediaID& source) { | 37 const content::DesktopMediaID& source, |
| 38 const std::string& extension_name) { |
38 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 39 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
39 | 40 |
40 std::string id = GenerateRandomStreamId(); | 41 std::string id = GenerateRandomStreamId(); |
41 ApprovedDesktopMediaStream& stream = approved_streams_[id]; | 42 ApprovedDesktopMediaStream& stream = approved_streams_[id]; |
42 stream.render_process_id = render_process_id; | 43 stream.render_process_id = render_process_id; |
43 stream.render_view_id = render_view_id; | 44 stream.render_view_id = render_view_id; |
44 stream.origin = origin; | 45 stream.origin = origin; |
45 stream.source = source; | 46 stream.source = source; |
| 47 stream.extension_name = extension_name; |
46 | 48 |
47 content::BrowserThread::PostDelayedTask( | 49 content::BrowserThread::PostDelayedTask( |
48 content::BrowserThread::UI, FROM_HERE, | 50 content::BrowserThread::UI, FROM_HERE, |
49 base::Bind(&DesktopStreamsRegistry::CleanupStream, | 51 base::Bind(&DesktopStreamsRegistry::CleanupStream, |
50 base::Unretained(this), id), | 52 base::Unretained(this), id), |
51 base::TimeDelta::FromSeconds(kApprovedStreamTimeToLiveSeconds)); | 53 base::TimeDelta::FromSeconds(kApprovedStreamTimeToLiveSeconds)); |
52 | 54 |
53 return id; | 55 return id; |
54 } | 56 } |
55 | 57 |
56 content::DesktopMediaID DesktopStreamsRegistry::RequestMediaForStreamId( | 58 content::DesktopMediaID DesktopStreamsRegistry::RequestMediaForStreamId( |
57 const std::string& id, | 59 const std::string& id, |
58 int render_process_id, | 60 int render_process_id, |
59 int render_view_id, | 61 int render_view_id, |
60 const GURL& origin) { | 62 const GURL& origin, |
| 63 std::string* extension_name) { |
61 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 64 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
62 | 65 |
63 StreamsMap::iterator it = approved_streams_.find(id); | 66 StreamsMap::iterator it = approved_streams_.find(id); |
64 | 67 |
65 // Verify that if there is a request with the specified ID it was created for | 68 // Verify that if there is a request with the specified ID it was created for |
66 // the same origin and the same renderer. | 69 // the same origin and the same renderer. |
67 if (it == approved_streams_.end() || | 70 if (it == approved_streams_.end() || |
68 render_process_id != it->second.render_process_id || | 71 render_process_id != it->second.render_process_id || |
69 render_view_id != it->second.render_view_id || | 72 render_view_id != it->second.render_view_id || |
70 origin != it->second.origin) { | 73 origin != it->second.origin) { |
71 return content::DesktopMediaID(); | 74 return content::DesktopMediaID(); |
72 } | 75 } |
73 | 76 |
74 content::DesktopMediaID result = it->second.source; | 77 content::DesktopMediaID result = it->second.source; |
| 78 *extension_name = it->second.extension_name; |
75 approved_streams_.erase(it); | 79 approved_streams_.erase(it); |
76 return result; | 80 return result; |
77 } | 81 } |
78 | 82 |
79 void DesktopStreamsRegistry::CleanupStream(const std::string& id) { | 83 void DesktopStreamsRegistry::CleanupStream(const std::string& id) { |
80 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 84 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
81 approved_streams_.erase(id); | 85 approved_streams_.erase(id); |
82 } | 86 } |
| 87 |
| 88 DesktopStreamsRegistry::ApprovedDesktopMediaStream::ApprovedDesktopMediaStream() |
| 89 : render_process_id(-1), render_view_id(-1) {} |
OLD | NEW |