| 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" |
| 11 #include "crypto/random.h" | 11 #include "crypto/random.h" |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 const int kStreamIdLengthBytes = 16; | 15 const int kStreamIdLengthBytes = 16; |
| 16 | 16 |
| 17 const int kApprovedStreamTimeToLiveSeconds = 10; | 17 const int kApprovedStreamTimeToLiveSeconds = 10; |
| 18 | 18 |
| 19 std::string GenerateRandomStreamId() { | 19 std::string GenerateRandomStreamId() { |
| 20 char buffer[kStreamIdLengthBytes]; | 20 char buffer[kStreamIdLengthBytes]; |
| 21 crypto::RandBytes(buffer, arraysize(buffer)); | 21 crypto::RandBytes(buffer, arraysize(buffer)); |
| 22 std::string result; | 22 std::string result; |
| 23 base::Base64Encode(base::StringPiece(buffer, arraysize(buffer)), | 23 if (!base::Base64Encode(base::StringPiece(buffer, arraysize(buffer)), |
| 24 &result); | 24 &result)) { |
| 25 LOG(FATAL) << "Base64Encode failed."; |
| 26 } |
| 25 return result; | 27 return result; |
| 26 } | 28 } |
| 27 | 29 |
| 28 } // namespace | 30 } // namespace |
| 29 | 31 |
| 30 DesktopStreamsRegistry::DesktopStreamsRegistry() {} | 32 DesktopStreamsRegistry::DesktopStreamsRegistry() {} |
| 31 DesktopStreamsRegistry::~DesktopStreamsRegistry() {} | 33 DesktopStreamsRegistry::~DesktopStreamsRegistry() {} |
| 32 | 34 |
| 33 std::string DesktopStreamsRegistry::RegisterStream( | 35 std::string DesktopStreamsRegistry::RegisterStream( |
| 34 int render_process_id, | 36 int render_process_id, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 | 75 |
| 74 content::DesktopMediaID result = it->second.source; | 76 content::DesktopMediaID result = it->second.source; |
| 75 approved_streams_.erase(it); | 77 approved_streams_.erase(it); |
| 76 return result; | 78 return result; |
| 77 } | 79 } |
| 78 | 80 |
| 79 void DesktopStreamsRegistry::CleanupStream(const std::string& id) { | 81 void DesktopStreamsRegistry::CleanupStream(const std::string& id) { |
| 80 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 82 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 81 approved_streams_.erase(id); | 83 approved_streams_.erase(id); |
| 82 } | 84 } |
| OLD | NEW |