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

Side by Side 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 more comments. Created 7 years, 1 month 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 | Annotate | Revision Log
OLDNEW
(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/guid.h"
7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/profiles/profile_io_data.h"
9 #include "chrome/common/pref_names.h"
10 #include "content/public/browser/browser_thread.h"
11
12 using content::BrowserThread;
13
14 namespace {
15
16 std::string CreateSalt() {
17 return base::GenerateGUID();
18 }
19
20 } // namespace
21
22 MediaDeviceIDSalt::MediaDeviceIDSalt(PrefService* pref_service,
23 bool incognito) {
24 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
25
26 if (incognito) {
27 incognito_salt_ = CreateSalt();
28 return;
29 }
30
31 media_device_id_salt_.Init(prefs::kMediaDeviceIdSalt, pref_service);
32 if (media_device_id_salt_.GetValue().empty())
33 media_device_id_salt_.SetValue(CreateSalt());
34
35 media_device_id_salt_.MoveToThread(
36 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
37 }
38
39 MediaDeviceIDSalt::~MediaDeviceIDSalt() {
40 }
41
42 std::string MediaDeviceIDSalt::GetSalt() const {
43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
44 if (incognito_salt_.size())
45 return incognito_salt_;
46 return media_device_id_salt_.GetValue();
47 }
48
49 void MediaDeviceIDSalt::RegisterProfilePrefs(
50 user_prefs::PrefRegistrySyncable* registry) {
51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
52 registry->RegisterStringPref(
53 prefs::kMediaDeviceIdSalt,
54 std::string(),
55 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
56 }
57
58 void MediaDeviceIDSalt::Reset(PrefService* pref_service) {
59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
60 pref_service->SetString(prefs::kMediaDeviceIdSalt,
61 CreateSalt());
62 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698