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

Side by Side Diff: chrome/browser/media/media_device_id_salt.cc

Issue 1987643002: Make default media device ID salts random by default (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
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 "chrome/browser/media/media_device_id_salt.h" 4 #include "chrome/browser/media/media_device_id_salt.h"
5 5
6 #include "base/base64.h" 6 #include "base/base64.h"
7 #include "base/rand_util.h" 7 #include "base/rand_util.h"
8 #include "chrome/browser/profiles/profile_io_data.h" 8 #include "chrome/browser/profiles/profile_io_data.h"
9 #include "chrome/common/pref_names.h" 9 #include "chrome/common/pref_names.h"
10 #include "components/prefs/pref_service.h" 10 #include "components/prefs/pref_service.h"
11 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/resource_context.h"
12 13
13 using content::BrowserThread; 14 using content::BrowserThread;
14 15
15 namespace {
16
17 std::string CreateSalt() {
18 std::string salt;
19 base::Base64Encode(base::RandBytesAsString(16), &salt);
20 DCHECK(!salt.empty());
21 return salt;
22 }
23
24 } // namespace
25
26 MediaDeviceIDSalt::MediaDeviceIDSalt(PrefService* pref_service, 16 MediaDeviceIDSalt::MediaDeviceIDSalt(PrefService* pref_service,
27 bool incognito) { 17 bool incognito) {
28 DCHECK_CURRENTLY_ON(BrowserThread::UI); 18 DCHECK_CURRENTLY_ON(BrowserThread::UI);
29 19
30 if (incognito) { 20 if (incognito) {
31 incognito_salt_ = CreateSalt(); 21 incognito_salt_ = content::ResourceContext::CreateRandomMediaDeviceIDSalt();
32 return; 22 return;
33 } 23 }
34 24
35 media_device_id_salt_.Init(prefs::kMediaDeviceIdSalt, pref_service); 25 media_device_id_salt_.Init(prefs::kMediaDeviceIdSalt, pref_service);
36 if (media_device_id_salt_.GetValue().empty()) 26 if (media_device_id_salt_.GetValue().empty())
37 media_device_id_salt_.SetValue(CreateSalt()); 27 media_device_id_salt_.SetValue(
28 content::ResourceContext::CreateRandomMediaDeviceIDSalt());
38 29
39 media_device_id_salt_.MoveToThread( 30 media_device_id_salt_.MoveToThread(
40 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); 31 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
41 } 32 }
42 33
43 MediaDeviceIDSalt::~MediaDeviceIDSalt() { 34 MediaDeviceIDSalt::~MediaDeviceIDSalt() {
44 } 35 }
45 36
46 void MediaDeviceIDSalt::ShutdownOnUIThread() { 37 void MediaDeviceIDSalt::ShutdownOnUIThread() {
47 DCHECK_CURRENTLY_ON(BrowserThread::UI); 38 DCHECK_CURRENTLY_ON(BrowserThread::UI);
48 if (incognito_salt_.empty()) 39 if (incognito_salt_.empty())
49 media_device_id_salt_.Destroy(); 40 media_device_id_salt_.Destroy();
50 } 41 }
51 42
52 std::string MediaDeviceIDSalt::GetSalt() const { 43 std::string MediaDeviceIDSalt::GetSalt() const {
53 DCHECK_CURRENTLY_ON(BrowserThread::IO); 44 DCHECK_CURRENTLY_ON(BrowserThread::IO);
54 if (incognito_salt_.size()) 45 if (incognito_salt_.size())
55 return incognito_salt_; 46 return incognito_salt_;
56 return media_device_id_salt_.GetValue(); 47 return media_device_id_salt_.GetValue();
57 } 48 }
58 49
59 void MediaDeviceIDSalt::RegisterProfilePrefs( 50 void MediaDeviceIDSalt::RegisterProfilePrefs(
60 user_prefs::PrefRegistrySyncable* registry) { 51 user_prefs::PrefRegistrySyncable* registry) {
61 registry->RegisterStringPref(prefs::kMediaDeviceIdSalt, std::string()); 52 registry->RegisterStringPref(prefs::kMediaDeviceIdSalt, std::string());
62 } 53 }
63 54
64 void MediaDeviceIDSalt::Reset(PrefService* pref_service) { 55 void MediaDeviceIDSalt::Reset(PrefService* pref_service) {
65 pref_service->SetString(prefs::kMediaDeviceIdSalt, 56 pref_service->SetString(
66 CreateSalt()); 57 prefs::kMediaDeviceIdSalt,
58 content::ResourceContext::CreateRandomMediaDeviceIDSalt());
67 } 59 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698