Chromium Code Reviews| 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 13 matching lines...) Expand all Loading... | |
| 24 &result); | 24 &result); |
| 25 return result; | 25 return result; |
| 26 } | 26 } |
| 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 const content::WebContents* web_contents, |
| 35 int render_view_id, | |
| 36 const GURL& origin, | 35 const GURL& origin, |
| 37 const content::DesktopMediaID& source, | 36 const content::DesktopMediaID& source, |
| 38 const std::string& extension_name) { | 37 const std::string& extension_name) { |
| 39 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 38 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 40 | 39 |
| 41 std::string id = GenerateRandomStreamId(); | 40 std::string id = GenerateRandomStreamId(); |
| 42 ApprovedDesktopMediaStream& stream = approved_streams_[id]; | 41 ApprovedDesktopMediaStream& stream = approved_streams_[id]; |
| 43 stream.render_process_id = render_process_id; | 42 DCHECK(web_contents); |
| 44 stream.render_view_id = render_view_id; | 43 stream.web_contents = web_contents; |
| 45 stream.origin = origin; | 44 stream.origin = origin; |
| 46 stream.source = source; | 45 stream.source = source; |
| 47 stream.extension_name = extension_name; | 46 stream.extension_name = extension_name; |
| 48 | 47 |
| 49 content::BrowserThread::PostDelayedTask( | 48 content::BrowserThread::PostDelayedTask( |
| 50 content::BrowserThread::UI, FROM_HERE, | 49 content::BrowserThread::UI, FROM_HERE, |
| 51 base::Bind(&DesktopStreamsRegistry::CleanupStream, | 50 base::Bind(&DesktopStreamsRegistry::CleanupStream, |
| 52 base::Unretained(this), id), | 51 base::Unretained(this), id), |
| 53 base::TimeDelta::FromSeconds(kApprovedStreamTimeToLiveSeconds)); | 52 base::TimeDelta::FromSeconds(kApprovedStreamTimeToLiveSeconds)); |
| 54 | 53 |
| 55 return id; | 54 return id; |
| 56 } | 55 } |
| 57 | 56 |
| 58 content::DesktopMediaID DesktopStreamsRegistry::RequestMediaForStreamId( | 57 content::DesktopMediaID DesktopStreamsRegistry::RequestMediaForStreamId( |
| 59 const std::string& id, | 58 const std::string& id, |
| 60 int render_process_id, | 59 const content::WebContents* web_contents, |
| 61 int render_view_id, | |
| 62 const GURL& origin, | 60 const GURL& origin, |
| 63 std::string* extension_name) { | 61 std::string* extension_name) { |
| 64 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 62 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 65 | 63 |
| 66 StreamsMap::iterator it = approved_streams_.find(id); | 64 StreamsMap::iterator it = approved_streams_.find(id); |
| 67 | 65 |
| 68 // Verify that if there is a request with the specified ID it was created for | 66 // Verify that if there is a request with the specified ID it was created for |
| 69 // the same origin and the same renderer. | 67 // the same origin and the same renderer. |
| 70 if (it == approved_streams_.end() || | 68 if (it == approved_streams_.end() || |
| 71 render_process_id != it->second.render_process_id || | 69 web_contents != it->second.web_contents || |
|
ncarter (slow)
2014/07/10 01:17:51
You can only match against a pointer value like th
miu
2014/07/10 22:16:12
Done.
| |
| 72 render_view_id != it->second.render_view_id || | |
| 73 origin != it->second.origin) { | 70 origin != it->second.origin) { |
| 74 return content::DesktopMediaID(); | 71 return content::DesktopMediaID(); |
| 75 } | 72 } |
| 76 | 73 |
| 77 content::DesktopMediaID result = it->second.source; | 74 content::DesktopMediaID result = it->second.source; |
| 78 *extension_name = it->second.extension_name; | 75 *extension_name = it->second.extension_name; |
| 79 approved_streams_.erase(it); | 76 approved_streams_.erase(it); |
| 80 return result; | 77 return result; |
| 81 } | 78 } |
| 82 | 79 |
| 83 void DesktopStreamsRegistry::CleanupStream(const std::string& id) { | 80 void DesktopStreamsRegistry::CleanupStream(const std::string& id) { |
| 84 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 81 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 85 approved_streams_.erase(id); | 82 approved_streams_.erase(id); |
| 86 } | 83 } |
| 87 | 84 |
| 88 DesktopStreamsRegistry::ApprovedDesktopMediaStream::ApprovedDesktopMediaStream() | 85 DesktopStreamsRegistry::ApprovedDesktopMediaStream::ApprovedDesktopMediaStream() |
| 89 : render_process_id(-1), render_view_id(-1) {} | 86 : web_contents(NULL) {} |
| OLD | NEW |