OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/renderer_host/pepper/device_id_fetcher.h" | 5 #include "chrome/browser/renderer_host/pepper/device_id_fetcher.h" |
6 | 6 |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 // Not implemented for other platforms. | 49 // Not implemented for other platforms. |
50 NOTREACHED(); | 50 NOTREACHED(); |
51 callback.Run(std::string()); | 51 callback.Run(std::string()); |
52 #endif | 52 #endif |
53 } | 53 } |
54 | 54 |
55 } // namespace | 55 } // namespace |
56 | 56 |
57 DeviceIDFetcher::DeviceIDFetcher(int render_process_id) | 57 DeviceIDFetcher::DeviceIDFetcher(int render_process_id) |
58 : in_progress_(false), render_process_id_(render_process_id) { | 58 : in_progress_(false), render_process_id_(render_process_id) { |
59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 59 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
60 } | 60 } |
61 | 61 |
62 DeviceIDFetcher::~DeviceIDFetcher() {} | 62 DeviceIDFetcher::~DeviceIDFetcher() {} |
63 | 63 |
64 bool DeviceIDFetcher::Start(const IDCallback& callback) { | 64 bool DeviceIDFetcher::Start(const IDCallback& callback) { |
65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 65 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
66 | 66 |
67 if (in_progress_) | 67 if (in_progress_) |
68 return false; | 68 return false; |
69 | 69 |
70 in_progress_ = true; | 70 in_progress_ = true; |
71 callback_ = callback; | 71 callback_ = callback; |
72 | 72 |
73 BrowserThread::PostTask( | 73 BrowserThread::PostTask( |
74 BrowserThread::UI, | 74 BrowserThread::UI, |
75 FROM_HERE, | 75 FROM_HERE, |
76 base::Bind(&DeviceIDFetcher::CheckPrefsOnUIThread, this)); | 76 base::Bind(&DeviceIDFetcher::CheckPrefsOnUIThread, this)); |
77 return true; | 77 return true; |
78 } | 78 } |
79 | 79 |
80 // static | 80 // static |
81 void DeviceIDFetcher::RegisterProfilePrefs( | 81 void DeviceIDFetcher::RegisterProfilePrefs( |
82 user_prefs::PrefRegistrySyncable* prefs) { | 82 user_prefs::PrefRegistrySyncable* prefs) { |
83 prefs->RegisterBooleanPref(prefs::kEnableDRM, true); | 83 prefs->RegisterBooleanPref(prefs::kEnableDRM, true); |
84 prefs->RegisterStringPref(prefs::kDRMSalt, ""); | 84 prefs->RegisterStringPref(prefs::kDRMSalt, ""); |
85 } | 85 } |
86 | 86 |
87 // static | 87 // static |
88 base::FilePath DeviceIDFetcher::GetLegacyDeviceIDPath( | 88 base::FilePath DeviceIDFetcher::GetLegacyDeviceIDPath( |
89 const base::FilePath& profile_path) { | 89 const base::FilePath& profile_path) { |
90 return profile_path.AppendASCII(kDRMIdentifierFile); | 90 return profile_path.AppendASCII(kDRMIdentifierFile); |
91 } | 91 } |
92 | 92 |
93 void DeviceIDFetcher::CheckPrefsOnUIThread() { | 93 void DeviceIDFetcher::CheckPrefsOnUIThread() { |
94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 94 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
95 | 95 |
96 Profile* profile = NULL; | 96 Profile* profile = NULL; |
97 RenderProcessHost* render_process_host = | 97 RenderProcessHost* render_process_host = |
98 RenderProcessHost::FromID(render_process_id_); | 98 RenderProcessHost::FromID(render_process_id_); |
99 if (render_process_host && render_process_host->GetBrowserContext()) { | 99 if (render_process_host && render_process_host->GetBrowserContext()) { |
100 profile = | 100 profile = |
101 Profile::FromBrowserContext(render_process_host->GetBrowserContext()); | 101 Profile::FromBrowserContext(render_process_host->GetBrowserContext()); |
102 } | 102 } |
103 | 103 |
104 if (!profile || profile->IsOffTheRecord() || | 104 if (!profile || profile->IsOffTheRecord() || |
(...skipping 23 matching lines...) Expand all Loading... |
128 salt)); | 128 salt)); |
129 #else | 129 #else |
130 // Get the machine ID and call ComputeOnUIThread with salt + machine_id. | 130 // Get the machine ID and call ComputeOnUIThread with salt + machine_id. |
131 GetMachineIDAsync( | 131 GetMachineIDAsync( |
132 base::Bind(&DeviceIDFetcher::ComputeOnUIThread, this, salt)); | 132 base::Bind(&DeviceIDFetcher::ComputeOnUIThread, this, salt)); |
133 #endif | 133 #endif |
134 } | 134 } |
135 | 135 |
136 void DeviceIDFetcher::ComputeOnUIThread(const std::string& salt, | 136 void DeviceIDFetcher::ComputeOnUIThread(const std::string& salt, |
137 const std::string& machine_id) { | 137 const std::string& machine_id) { |
138 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 138 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
139 | 139 |
140 if (machine_id.empty()) { | 140 if (machine_id.empty()) { |
141 LOG(ERROR) << "Empty machine id"; | 141 LOG(ERROR) << "Empty machine id"; |
142 RunCallbackOnIOThread(std::string(), PP_ERROR_FAILED); | 142 RunCallbackOnIOThread(std::string(), PP_ERROR_FAILED); |
143 return; | 143 return; |
144 } | 144 } |
145 | 145 |
146 // Build the identifier as follows: | 146 // Build the identifier as follows: |
147 // SHA256(machine-id||service||SHA256(machine-id||service||salt)) | 147 // SHA256(machine-id||service||SHA256(machine-id||service||salt)) |
148 std::vector<uint8> salt_bytes; | 148 std::vector<uint8> salt_bytes; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 BrowserThread::IO, | 203 BrowserThread::IO, |
204 FROM_HERE, | 204 FROM_HERE, |
205 base::Bind(&DeviceIDFetcher::RunCallbackOnIOThread, this, id, result)); | 205 base::Bind(&DeviceIDFetcher::RunCallbackOnIOThread, this, id, result)); |
206 return; | 206 return; |
207 } | 207 } |
208 in_progress_ = false; | 208 in_progress_ = false; |
209 callback_.Run(id, result); | 209 callback_.Run(id, result); |
210 } | 210 } |
211 | 211 |
212 } // namespace chrome | 212 } // namespace chrome |
OLD | NEW |