Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: content/public/browser/media_device_id.cc

Issue 2424163004: Factor out authorization from AudioRendererHost. (Closed)
Patch Set: const& Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/public/browser/media_device_id.h ('k') | content/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "content/public/browser/media_device_id.h" 4 #include "content/public/browser/media_device_id.h"
5 5
6 #include "base/strings/string_util.h"
6 #include "content/browser/browser_main_loop.h" 7 #include "content/browser/browser_main_loop.h"
7 #include "content/browser/renderer_host/media/media_stream_manager.h" 8 #include "content/browser/renderer_host/media/media_stream_manager.h"
9 #include "media/audio/audio_device_description.h"
8 10
9 namespace content { 11 namespace content {
10 12
11 std::string GetHMACForMediaDeviceID(const std::string& salt, 13 std::string GetHMACForMediaDeviceID(const std::string& salt,
12 const url::Origin& security_origin, 14 const url::Origin& security_origin,
13 const std::string& raw_unique_id) { 15 const std::string& raw_unique_id) {
14 return MediaStreamManager::GetHMACForMediaDeviceID(salt, security_origin, 16 return MediaStreamManager::GetHMACForMediaDeviceID(salt, security_origin,
15 raw_unique_id); 17 raw_unique_id);
16 } 18 }
17 19
(...skipping 11 matching lines...) Expand all
29 const std::string& source_id, 31 const std::string& source_id,
30 std::string* device_id) { 32 std::string* device_id) {
31 content::MediaStreamManager* manager = 33 content::MediaStreamManager* manager =
32 content::BrowserMainLoop::GetInstance()->media_stream_manager(); 34 content::BrowserMainLoop::GetInstance()->media_stream_manager();
33 35
34 return manager->TranslateSourceIdToDeviceId( 36 return manager->TranslateSourceIdToDeviceId(
35 content::MEDIA_DEVICE_VIDEO_CAPTURE, salt, security_origin, source_id, 37 content::MEDIA_DEVICE_VIDEO_CAPTURE, salt, security_origin, source_id,
36 device_id); 38 device_id);
37 } 39 }
38 40
41 bool IsValidDeviceId(const std::string& device_id) {
42 constexpr int hash_size = 64; // 32 bytes * 2 char/byte hex encoding
43 if (media::AudioDeviceDescription::IsDefaultDevice(device_id) ||
44 device_id == media::AudioDeviceDescription::kCommunicationsDeviceId)
45 return true;
46
47 if (device_id.length() != hash_size)
48 return false;
49
50 return std::all_of(device_id.cbegin(), device_id.cend(), [](const char& c) {
51 return base::IsAsciiLower(c) || base::IsAsciiDigit(c);
52 });
53 }
54
39 } // namespace content 55 } // namespace content
OLDNEW
« no previous file with comments | « content/public/browser/media_device_id.h ('k') | content/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698