OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 #include "chrome/browser/media/media_device_id_salt.h" | |
5 | |
6 #include "base/logging.h" | |
7 #include "base/prefs/pref_service.h" | |
8 #include "base/rand_util.h" | |
9 #include "chrome/browser/profiles/profile_io_data.h" | |
10 #include "chrome/common/pref_names.h" | |
11 #include "content/public/browser/browser_thread.h" | |
12 | |
13 using content::BrowserThread; | |
14 | |
15 namespace { | |
16 | |
17 std::string CreateSalt() { | |
Jói
2013/10/31 17:19:35
This should be tested, if nothing more than a manu
perkj_chrome
2013/11/01 13:39:34
I found another way. How about using a guid? I too
Jói
2013/11/01 14:29:37
Yep, that seems fine since our GUIDs are actually
| |
18 const size_t kSaltLength = 8; | |
19 static const char kAlphabet[] = "0123456789" | |
20 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
21 | |
22 std::string salt(kSaltLength, ' '); | |
23 for (size_t i = 0; i < salt.size(); ++i) { | |
24 int random_char = base::RandInt(0, sizeof(kAlphabet) - 1); | |
25 salt[i] = kAlphabet[random_char]; | |
26 } | |
27 return salt; | |
28 } | |
29 | |
30 } // namespace | |
31 | |
32 MediaDeviceIDSalt::MediaDeviceIDSalt(PrefService* pref_service, | |
33 bool incognito) { | |
34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
35 | |
36 if (!incognito) { | |
37 media_device_id_salt_.Init(prefs::kMediaDeviceIdSalt, pref_service, | |
38 base::Bind(&MediaDeviceIDSalt::OnValueReset, | |
39 base::Unretained(this))); | |
40 salt_ = media_device_id_salt_.GetValue(); | |
41 } | |
42 | |
43 if (salt_.empty()) { | |
44 salt_ = CreateSalt(); | |
45 } | |
46 | |
47 if (!incognito) { | |
48 media_device_id_salt_.SetValue(salt_); | |
49 } | |
50 } | |
51 | |
52 MediaDeviceIDSalt::~MediaDeviceIDSalt() { | |
53 } | |
54 | |
55 std::string MediaDeviceIDSalt::GetSalt() { | |
56 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
57 base::AutoLock salt_lock(lock_); | |
58 return salt_; | |
59 } | |
60 | |
61 void MediaDeviceIDSalt::RegisterProfilePrefs( | |
62 user_prefs::PrefRegistrySyncable* registry) { | |
63 registry->RegisterStringPref( | |
64 prefs::kMediaDeviceIdSalt, | |
65 std::string(), | |
66 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
67 } | |
68 | |
69 void MediaDeviceIDSalt::Reset(PrefService* pref_service) { | |
70 pref_service->ClearPref(prefs::kMediaDeviceIdSalt); | |
71 } | |
72 | |
73 void MediaDeviceIDSalt::OnValueReset(const std::string& name) { | |
Jói
2013/10/31 17:19:35
Are you sure this will trigger only when you reset
perkj_chrome
2013/11/01 13:39:34
YEs- it is only triggered once. I was afraid of th
Jói
2013/11/01 14:29:37
OK.
| |
74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
75 base::AutoLock salt_lock(lock_); | |
76 salt_ = CreateSalt(); | |
77 media_device_id_salt_.SetValue(salt_); | |
78 } | |
OLD | NEW |