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

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

Issue 1369723003: Do not hash default and communications media device ID (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months 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/browser/renderer_host/media/audio_renderer_host.cc ('k') | no next file » | 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/logging.h" 6 #include "base/logging.h"
7 #include "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "content/browser/browser_main_loop.h" 9 #include "content/browser/browser_main_loop.h"
10 #include "content/browser/renderer_host/media/media_stream_manager.h" 10 #include "content/browser/renderer_host/media/media_stream_manager.h"
11 #include "crypto/hmac.h" 11 #include "crypto/hmac.h"
12 12
13 namespace content { 13 namespace content {
14 14
15 namespace {
16
17 const char kDefaultDeviceId[] = "default";
tommi (sloooow) - chröme 2015/09/26 09:27:23 Can we use the constants from media/ instead? http
Guido Urdaneta 2015/09/26 09:48:58 I originally tried that, but, unfortunaetly, it is
tommi (sloooow) - chröme 2015/09/26 10:13:47 Ah right. I didn't realize we're in public/. Hmm.
18 const char kCommunicationsDeviceId[] = "communications";
19
20 bool IsDefaultMediaDeviceID(const std::string& source_id) {
21 return (source_id == kDefaultDeviceId) ||
tommi (sloooow) - chröme 2015/09/26 09:27:24 nit: () not necessary
Guido Urdaneta 2015/09/26 09:48:58 Done.
22 (source_id == kCommunicationsDeviceId);
23 }
24
25 } // namespace
26
15 std::string GetHMACForMediaDeviceID(const ResourceContext::SaltCallback& sc, 27 std::string GetHMACForMediaDeviceID(const ResourceContext::SaltCallback& sc,
16 const GURL& security_origin, 28 const GURL& security_origin,
17 const std::string& raw_unique_id) { 29 const std::string& raw_unique_id) {
30 if (IsDefaultMediaDeviceID(raw_unique_id))
31 return raw_unique_id;
32
18 DCHECK(security_origin.is_valid()); 33 DCHECK(security_origin.is_valid());
19 DCHECK(!raw_unique_id.empty()); 34 DCHECK(!raw_unique_id.empty());
20 crypto::HMAC hmac(crypto::HMAC::SHA256); 35 crypto::HMAC hmac(crypto::HMAC::SHA256);
21 const size_t digest_length = hmac.DigestLength(); 36 const size_t digest_length = hmac.DigestLength();
22 std::vector<uint8> digest(digest_length); 37 std::vector<uint8> digest(digest_length);
23 std::string salt = sc.Run(); 38 std::string salt = sc.Run();
24 bool result = hmac.Init(security_origin.spec()) && 39 bool result = hmac.Init(security_origin.spec()) &&
25 hmac.Sign(raw_unique_id + salt, &digest[0], digest.size()); 40 hmac.Sign(raw_unique_id + salt, &digest[0], digest.size());
26 DCHECK(result); 41 DCHECK(result);
27 return base::ToLowerASCII(base::HexEncode(&digest[0], digest.size())); 42 return base::ToLowerASCII(base::HexEncode(&digest[0], digest.size()));
(...skipping 20 matching lines...) Expand all
48 63
49 return manager->TranslateSourceIdToDeviceId( 64 return manager->TranslateSourceIdToDeviceId(
50 content::MEDIA_DEVICE_VIDEO_CAPTURE, 65 content::MEDIA_DEVICE_VIDEO_CAPTURE,
51 rc, 66 rc,
52 security_origin, 67 security_origin,
53 source_id, 68 source_id,
54 device_id); 69 device_id);
55 } 70 }
56 71
57 } // namespace content 72 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/media/audio_renderer_host.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698