| 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 14 matching lines...) Expand all Loading... |
| 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 int render_process_id, |
| 35 int render_view_id, | 35 int render_frame_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 const std::string& extension_name) { |
| 39 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 39 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 40 | 40 |
| 41 std::string id = GenerateRandomStreamId(); | 41 std::string id; |
| 42 do { |
| 43 id = GenerateRandomStreamId(); |
| 44 } while (approved_streams_.find(id) != approved_streams_.end()); |
| 42 ApprovedDesktopMediaStream& stream = approved_streams_[id]; | 45 ApprovedDesktopMediaStream& stream = approved_streams_[id]; |
| 43 stream.render_process_id = render_process_id; | 46 stream.render_process_id = render_process_id; |
| 44 stream.render_view_id = render_view_id; | 47 stream.render_frame_id = render_frame_id; |
| 45 stream.origin = origin; | 48 stream.origin = origin; |
| 46 stream.source = source; | 49 stream.source = source; |
| 47 stream.extension_name = extension_name; | 50 stream.extension_name = extension_name; |
| 48 | 51 |
| 49 content::BrowserThread::PostDelayedTask( | 52 content::BrowserThread::PostDelayedTask( |
| 50 content::BrowserThread::UI, FROM_HERE, | 53 content::BrowserThread::UI, FROM_HERE, |
| 51 base::Bind(&DesktopStreamsRegistry::CleanupStream, | 54 base::Bind(&DesktopStreamsRegistry::CleanupStream, |
| 52 base::Unretained(this), id), | 55 base::Unretained(this), id), |
| 53 base::TimeDelta::FromSeconds(kApprovedStreamTimeToLiveSeconds)); | 56 base::TimeDelta::FromSeconds(kApprovedStreamTimeToLiveSeconds)); |
| 54 | 57 |
| 55 return id; | 58 return id; |
| 56 } | 59 } |
| 57 | 60 |
| 58 content::DesktopMediaID DesktopStreamsRegistry::RequestMediaForStreamId( | 61 content::DesktopMediaID DesktopStreamsRegistry::RequestMediaForStreamId( |
| 59 const std::string& id, | 62 const std::string& id, |
| 60 int render_process_id, | 63 int render_process_id, |
| 61 int render_view_id, | 64 int render_frame_id, |
| 62 const GURL& origin, | 65 const GURL& origin, |
| 63 std::string* extension_name) { | 66 std::string* extension_name) { |
| 64 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 67 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 65 | 68 |
| 66 StreamsMap::iterator it = approved_streams_.find(id); | 69 StreamsMap::iterator it = approved_streams_.find(id); |
| 67 | 70 |
| 68 // Verify that if there is a request with the specified ID it was created for | 71 // Verify that if there is a request with the specified ID it was created for |
| 69 // the same origin and the same renderer. | 72 // the same origin and the same renderer. |
| 70 if (it == approved_streams_.end() || | 73 if (it == approved_streams_.end() || |
| 71 render_process_id != it->second.render_process_id || | 74 render_process_id != it->second.render_process_id || |
| 72 render_view_id != it->second.render_view_id || | 75 render_frame_id != it->second.render_frame_id || |
| 73 origin != it->second.origin) { | 76 origin != it->second.origin) { |
| 74 return content::DesktopMediaID(); | 77 return content::DesktopMediaID(); |
| 75 } | 78 } |
| 76 | 79 |
| 77 content::DesktopMediaID result = it->second.source; | 80 content::DesktopMediaID result = it->second.source; |
| 78 *extension_name = it->second.extension_name; | 81 *extension_name = it->second.extension_name; |
| 79 approved_streams_.erase(it); | 82 approved_streams_.erase(it); |
| 80 return result; | 83 return result; |
| 81 } | 84 } |
| 82 | 85 |
| 83 void DesktopStreamsRegistry::CleanupStream(const std::string& id) { | 86 void DesktopStreamsRegistry::CleanupStream(const std::string& id) { |
| 84 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 87 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 85 approved_streams_.erase(id); | 88 approved_streams_.erase(id); |
| 86 } | 89 } |
| 87 | 90 |
| 88 DesktopStreamsRegistry::ApprovedDesktopMediaStream::ApprovedDesktopMediaStream() | 91 DesktopStreamsRegistry::ApprovedDesktopMediaStream::ApprovedDesktopMediaStream() |
| 89 : render_process_id(-1), render_view_id(-1) {} | 92 : render_process_id(-1), render_frame_id(-1) {} |
| OLD | NEW |