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

Side by Side Diff: chrome/browser/extensions/api/music_manager_private/device_id.cc

Issue 81683002: Prevent GetDeviceId from invoking its callback multiple times in failure cases. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: +TODO Created 7 years 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
« no previous file with comments | « no previous file | chrome/browser/prefs/pref_metrics_service.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/prefs/pref_metrics_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698