| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/extensions/api/music_manager_private/device_id.h" | 5 #include "chrome/browser/extensions/api/music_manager_private/device_id.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 return result; | 28 return result; |
| 29 } | 29 } |
| 30 | 30 |
| 31 void GetMachineIdCallback(const std::string& extension_id, | 31 void GetMachineIdCallback(const std::string& extension_id, |
| 32 const extensions::api::DeviceId::IdCallback& callback, | 32 const extensions::api::DeviceId::IdCallback& callback, |
| 33 const std::string& machine_id) { | 33 const std::string& machine_id) { |
| 34 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 34 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 35 | 35 |
| 36 if (machine_id.empty()) { | 36 if (machine_id.empty()) { |
| 37 callback.Run(""); | 37 callback.Run(""); |
| 38 return; |
| 38 } | 39 } |
| 39 | 40 |
| 40 std::string device_id; | 41 std::string device_id; |
| 41 if (!ComputeHmacSha256(machine_id, extension_id, &device_id)) { | 42 if (!ComputeHmacSha256(machine_id, extension_id, &device_id)) { |
| 42 DLOG(ERROR) << "Error while computing HMAC-SHA256 of device id."; | 43 DLOG(ERROR) << "Error while computing HMAC-SHA256 of device id."; |
| 43 callback.Run(""); | 44 callback.Run(""); |
| 45 return; |
| 44 } | 46 } |
| 45 callback.Run(device_id); | 47 callback.Run(device_id); |
| 46 } | 48 } |
| 47 | 49 |
| 48 } | 50 } // namespace |
| 49 | 51 |
| 50 namespace extensions { | 52 namespace extensions { |
| 51 namespace api { | 53 namespace api { |
| 52 | 54 |
| 53 /* static */ | 55 /* static */ |
| 54 void DeviceId::GetDeviceId(const std::string& extension_id, | 56 void DeviceId::GetDeviceId(const std::string& extension_id, |
| 55 const IdCallback& callback) { | 57 const IdCallback& callback) { |
| 56 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 58 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 57 CHECK(!extension_id.empty()); | 59 CHECK(!extension_id.empty()); |
| 58 | 60 |
| 59 // Forward call to platform specific implementation, then compute the HMAC | 61 // Forward call to platform specific implementation, then compute the HMAC |
| 60 // in the callback. | 62 // in the callback. |
| 61 GetMachineId(base::Bind(&GetMachineIdCallback, extension_id, callback)); | 63 GetMachineId(base::Bind(&GetMachineIdCallback, extension_id, callback)); |
| 62 } | 64 } |
| 63 | 65 |
| 64 } // namespace api | 66 } // namespace api |
| 65 } // namespace extensions | 67 } // namespace extensions |
| OLD | NEW |