Chromium Code Reviews| Index: chrome/browser/media/media_device_id_salt.cc |
| diff --git a/chrome/browser/media/media_device_id_salt.cc b/chrome/browser/media/media_device_id_salt.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c46f3cf64ca0236d12a241003878594ccc6d9a50 |
| --- /dev/null |
| +++ b/chrome/browser/media/media_device_id_salt.cc |
| @@ -0,0 +1,65 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| +#include "chrome/browser/media/media_device_id_salt.h" |
| + |
| +#include "base/logging.h" |
| +#include "base/prefs/pref_service.h" |
| +#include "base/guid.h" |
| +#include "base/rand_util.h" |
| +#include "chrome/browser/profiles/profile_io_data.h" |
| +#include "chrome/common/pref_names.h" |
| +#include "content/public/browser/browser_thread.h" |
| + |
| +using content::BrowserThread; |
| + |
| +namespace { |
| + |
| +std::string CreateSalt() { |
| + std::string salt = base::GenerateGUID(); |
| + 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.
|
| +} |
| + |
| +} // namespace |
| + |
| +MediaDeviceIDSalt::MediaDeviceIDSalt(PrefService* pref_service, |
| + bool incognito) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + |
| + if (incognito) { |
| + incognito_salt_ = CreateSalt(); |
| + return; |
| + } |
| + |
| + media_device_id_salt_.Init(prefs::kMediaDeviceIdSalt, pref_service); |
| + if (media_device_id_salt_.GetValue().empty()) |
| + media_device_id_salt_.SetValue(CreateSalt()); |
| + |
| + 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.
|
| + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); |
| +} |
| + |
| +MediaDeviceIDSalt::~MediaDeviceIDSalt() { |
| +} |
| + |
| +std::string MediaDeviceIDSalt::GetSalt() const { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + if (incognito_salt_.size()) |
| + return incognito_salt_; |
| + return media_device_id_salt_.GetValue(); |
| +} |
| + |
| +void MediaDeviceIDSalt::RegisterProfilePrefs( |
| + user_prefs::PrefRegistrySyncable* registry) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + registry->RegisterStringPref( |
| + prefs::kMediaDeviceIdSalt, |
| + std::string(), |
| + user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| +} |
| + |
| +void MediaDeviceIDSalt::Reset(PrefService* pref_service) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + pref_service->SetString(prefs::kMediaDeviceIdSalt, |
| + CreateSalt()); |
| +} |