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

Unified Diff: chrome/browser/media/media_device_id_salt.cc

Issue 54863002: Implement a salt for MediaSource IDs that can be cleared by a user. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed review comments- unit tests still don't compile Created 7 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 side-by-side diff with in-line comments
Download patch
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..ca491760cf87f25fd5b95c624613beeec284ae02
--- /dev/null
+++ b/chrome/browser/media/media_device_id_salt.cc
@@ -0,0 +1,78 @@
+// 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/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() {
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
+ const size_t kSaltLength = 8;
+ static const char kAlphabet[] = "0123456789"
+ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
+
+ std::string salt(kSaltLength, ' ');
+ for (size_t i = 0; i < salt.size(); ++i) {
+ int random_char = base::RandInt(0, sizeof(kAlphabet) - 1);
+ salt[i] = kAlphabet[random_char];
+ }
+ return salt;
+}
+
+} // namespace
+
+MediaDeviceIDSalt::MediaDeviceIDSalt(PrefService* pref_service,
+ bool incognito) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ if (!incognito) {
+ media_device_id_salt_.Init(prefs::kMediaDeviceIdSalt, pref_service,
+ base::Bind(&MediaDeviceIDSalt::OnValueReset,
+ base::Unretained(this)));
+ salt_ = media_device_id_salt_.GetValue();
+ }
+
+ if (salt_.empty()) {
+ salt_ = CreateSalt();
+ }
+
+ if (!incognito) {
+ media_device_id_salt_.SetValue(salt_);
+ }
+}
+
+MediaDeviceIDSalt::~MediaDeviceIDSalt() {
+}
+
+std::string MediaDeviceIDSalt::GetSalt() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ base::AutoLock salt_lock(lock_);
+ return salt_;
+}
+
+void MediaDeviceIDSalt::RegisterProfilePrefs(
+ user_prefs::PrefRegistrySyncable* registry) {
+ registry->RegisterStringPref(
+ prefs::kMediaDeviceIdSalt,
+ std::string(),
+ user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
+}
+
+void MediaDeviceIDSalt::Reset(PrefService* pref_service) {
+ pref_service->ClearPref(prefs::kMediaDeviceIdSalt);
+}
+
+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.
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ base::AutoLock salt_lock(lock_);
+ salt_ = CreateSalt();
+ media_device_id_salt_.SetValue(salt_);
+}

Powered by Google App Engine
This is Rietveld 408576698