1868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
2868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// found in the LICENSE file.
4868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
5868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#ifndef CHROME_BROWSER_EXTENSIONS_API_MUSIC_MANAGER_PRIVATE_DEVICE_ID_H_
6868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#define CHROME_BROWSER_EXTENSIONS_API_MUSIC_MANAGER_PRIVATE_DEVICE_ID_H_
7868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
8868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include <string>
9868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
10868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/bind.h"
11868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
12868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)namespace extensions {
13868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)namespace api {
14868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
15868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class DeviceId {
16868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) public:
17868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  typedef base::Callback<void(const std::string&)> IdCallback;
18868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Calls |callback| with a unique device identifier as argument. The device
205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // identifier has the following characteristics:
215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // 1. It is shared across users of a device.
225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // 2. It is resilient to device reboots.
235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // 3. It can be reset in *some* way by the user. In Particular, it can *not*
245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //    be based only on a MAC address of a physical device.
25868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // The specific implementation varies across platforms, some of them requiring
265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // a round trip to the IO or FILE thread. "callback" will always be called on
275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // the UI thread though (sometimes directly if the implementation allows
28868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // running on the UI thread).
295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // The returned value is HMAC_SHA256(|raw_device_id|, |extension_id|), so that
305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // the actual device identifier value is not exposed directly to the caller.
31868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static void GetDeviceId(const std::string& extension_id,
32868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                          const IdCallback& callback);
33868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
34868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) private:
35868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Platform specific implementation of "raw" machine ID retrieval.
365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  static void GetRawDeviceId(const IdCallback& callback);
375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // On some platforms, part of the machine ID is the MAC address. This function
395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // is shared across platforms to filter out MAC addresses that have been
405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // identified as invalid, i.e. not unique. For example, some VM hosts assign a
415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // new MAC addresses at each reboot.
425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  static bool IsValidMacAddress(const void* bytes, size_t size);
43868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)};
44868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
45868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}  // namespace api
46868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}  // namespace extensions
47868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
48868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#endif  // CHROME_BROWSER_EXTENSIONS_API_MUSIC_MANAGER_PRIVATE_DEVICE_ID_H_
49