device_id_fetcher.h revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
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
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_RENDERER_HOST_PEPPER_DEVICE_ID_FETCHER_H_
6#define CHROME_BROWSER_RENDERER_HOST_PEPPER_DEVICE_ID_FETCHER_H_
7
8#include <string>
9
10#include "base/basictypes.h"
11#include "base/callback.h"
12#include "base/compiler_specific.h"
13#include "base/files/file_path.h"
14#include "base/memory/ref_counted.h"
15#include "ppapi/c/pp_instance.h"
16
17class Profile;
18
19namespace content {
20class BrowserPpapiHost;
21}
22
23namespace user_prefs {
24class PrefRegistrySyncable;
25}
26
27namespace chrome {
28
29class PepperFlashDeviceIDHost;
30
31// This class allows asynchronously fetching a unique device ID. The callback
32// passed in on creation will be called when the ID has been fetched.
33class DeviceIDFetcher : public base::RefCountedThreadSafe<DeviceIDFetcher> {
34 public:
35  typedef base::Callback<void(const std::string&)> IDCallback;
36
37  explicit DeviceIDFetcher(const IDCallback& callback, PP_Instance instance);
38
39  // Schedules the request operation.
40  void Start(content::BrowserPpapiHost* browser_host);
41
42  // Called to register the |kEnableDRM| and |kDRMSalt| preferences.
43  static void RegisterUserPrefs(user_prefs::PrefRegistrySyncable* prefs);
44
45  // Return the path where the legacy device ID is stored (for ChromeOS only).
46  static base::FilePath GetLegacyDeviceIDPath(
47      const base::FilePath& profile_path);
48
49 private:
50  ~DeviceIDFetcher();
51
52  // Checks the preferences for DRM (whether DRM is enabled and getting the drm
53  // salt) on the UI thread. These are passed to |ComputeOnIOThread|.
54  void CheckPrefsOnUIThread(int process_id);
55
56  // Compute the device ID on the IO thread with the given salt.
57  void ComputeOnIOThread(const std::string& salt);
58  // Legacy method used to get the device ID for ChromeOS.
59  void ComputeOnBlockingPool(const base::FilePath& profile_path,
60                             const std::string& salt);
61
62  // Calls back into the PepperFlashDeviceIDHost on the IO thread with the
63  // device ID or the empty string on failure.
64  void RunCallbackOnIOThread(const std::string& id);
65
66  // Helper which returns an ID unique to the system. Returns an empty string if
67  // the call fails.
68  std::string GetMachineID();
69
70  friend class base::RefCountedThreadSafe<DeviceIDFetcher>;
71
72  // The callback to run when the ID has been fetched.
73  IDCallback callback_;
74
75  PP_Instance instance_;
76
77  DISALLOW_COPY_AND_ASSIGN(DeviceIDFetcher);
78};
79
80}  // namespace chrome
81
82#endif  // CHROME_BROWSER_RENDERER_HOST_PEPPER_DEVICE_ID_FETCHER_H_
83