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/guid.h" | |
9 #include "base/rand_util.h" | |
10 #include "chrome/browser/profiles/profile_io_data.h" | |
11 #include "chrome/common/pref_names.h" | |
12 #include "content/public/browser/browser_thread.h" | |
13 | |
14 using content::BrowserThread; | |
15 | |
16 namespace { | |
17 | |
18 std::string CreateSalt() { | |
19 std::string salt = base::GenerateGUID(); | |
20 return !salt.empty() ? salt : base::RandBytesAsString(16); | |
Jói
2013/11/01 14:29:38
Wait, why would the salt be empty?
And why not ju
perkj_chrome
2013/11/01 15:49:06
/ Generate a 128-bit random GUID of the form: "%08
Jói
2013/11/01 16:30:31
Actually, I misread the GenerateGUID implementatio
perkj_chrome
2013/11/01 19:01:56
Done.
| |
21 } | |
22 | |
23 } // namespace | |
24 | |
25 MediaDeviceIDSalt::MediaDeviceIDSalt(PrefService* pref_service, | |
26 bool incognito) { | |
27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
28 | |
29 if (incognito) { | |
30 incognito_salt_ = CreateSalt(); | |
31 return; | |
32 } | |
33 | |
34 media_device_id_salt_.Init(prefs::kMediaDeviceIdSalt, pref_service); | |
35 if (media_device_id_salt_.GetValue().empty()) | |
36 media_device_id_salt_.SetValue(CreateSalt()); | |
37 | |
38 media_device_id_salt_.MoveToThread( | |
Jói
2013/11/01 14:29:38
Ah, cool, I had forgotten about this. Nice solutio
perkj_chrome
2013/11/01 15:49:06
Done.
| |
39 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); | |
40 } | |
41 | |
42 MediaDeviceIDSalt::~MediaDeviceIDSalt() { | |
43 } | |
44 | |
45 std::string MediaDeviceIDSalt::GetSalt() const { | |
46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
47 if (incognito_salt_.size()) | |
48 return incognito_salt_; | |
49 return media_device_id_salt_.GetValue(); | |
50 } | |
51 | |
52 void MediaDeviceIDSalt::RegisterProfilePrefs( | |
53 user_prefs::PrefRegistrySyncable* registry) { | |
54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
55 registry->RegisterStringPref( | |
56 prefs::kMediaDeviceIdSalt, | |
57 std::string(), | |
58 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
59 } | |
60 | |
61 void MediaDeviceIDSalt::Reset(PrefService* pref_service) { | |
62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
63 pref_service->SetString(prefs::kMediaDeviceIdSalt, | |
64 CreateSalt()); | |
65 } | |
OLD | NEW |