summaryrefslogtreecommitdiffstats
path: root/chrome/browser/renderer_host/pepper/device_id_fetcher.h
blob: 21acb10198c8dbc40ee37be405316e421b32bd48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_RENDERER_HOST_PEPPER_DEVICE_ID_FETCHER_H_
#define CHROME_BROWSER_RENDERER_HOST_PEPPER_DEVICE_ID_FETCHER_H_

#include <string>

#include "base/basictypes.h"
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
#include "ppapi/c/pp_instance.h"

class Profile;

namespace content {
class BrowserPpapiHost;
}

namespace user_prefs {
class PrefRegistrySyncable;
}

namespace chrome {

// This class allows asynchronously fetching a unique device ID. The callback
// passed in when calling Start() will be called when the ID has been fetched
// or on error.
class DeviceIDFetcher : public base::RefCountedThreadSafe<DeviceIDFetcher> {
 public:
  typedef base::Callback<void(const std::string&, int32_t)> IDCallback;

  explicit DeviceIDFetcher(int render_process_id);

  // Schedules the request operation. Returns false if a request is in progress,
  // true otherwise.
  bool Start(const IDCallback& callback);

  // Called to register the |kEnableDRM| and |kDRMSalt| preferences.
  static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* prefs);

  // Return the path where the legacy device ID is stored (for ChromeOS only).
  static base::FilePath GetLegacyDeviceIDPath(
      const base::FilePath& profile_path);

 private:
  ~DeviceIDFetcher();

  // Checks the preferences for DRM (whether DRM is enabled and getting the drm
  // salt) on the UI thread.
  void CheckPrefsOnUIThread();

  // Compute the device ID on the UI thread with the given salt and machine ID.
  void ComputeOnUIThread(const std::string& salt,
                         const std::string& machine_id);

  // Legacy method used to get the device ID for ChromeOS.
  void LegacyComputeOnBlockingPool(const base::FilePath& profile_path,
                                   const std::string& salt);

  // Runs the callback passed into Start() on the IO thread with the device ID
  // or the empty string on failure.
  void RunCallbackOnIOThread(const std::string& id,
                             int32_t result);

  friend class base::RefCountedThreadSafe<DeviceIDFetcher>;

  // The callback to run when the ID has been fetched.
  IDCallback callback_;

  // Whether a request is in progress.
  bool in_progress_;

  int render_process_id_;

  DISALLOW_COPY_AND_ASSIGN(DeviceIDFetcher);
};

}  // namespace chrome

#endif  // CHROME_BROWSER_RENDERER_HOST_PEPPER_DEVICE_ID_FETCHER_H_