Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / renderer_host / pepper / device_id_fetcher.h
blob79001a220b4cfa80834878194273c58814cce7a3
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.
5 #ifndef CHROME_BROWSER_RENDERER_HOST_PEPPER_DEVICE_ID_FETCHER_H_
6 #define CHROME_BROWSER_RENDERER_HOST_PEPPER_DEVICE_ID_FETCHER_H_
8 #include <string>
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"
17 class Profile;
19 namespace content {
20 class BrowserPpapiHost;
23 namespace user_prefs {
24 class PrefRegistrySyncable;
27 namespace chrome {
29 // This class allows asynchronously fetching a unique device ID. The callback
30 // passed in when calling Start() will be called when the ID has been fetched
31 // or on error.
32 class DeviceIDFetcher : public base::RefCountedThreadSafe<DeviceIDFetcher> {
33 public:
34 typedef base::Callback<void(const std::string&, int32_t)> IDCallback;
36 explicit DeviceIDFetcher(int render_process_id);
38 // Schedules the request operation. Returns false if a request is in progress,
39 // true otherwise.
40 bool Start(const IDCallback& callback);
42 // Called to register the |kEnableDRM| and |kDRMSalt| preferences.
43 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* prefs);
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);
49 private:
50 ~DeviceIDFetcher();
52 // Checks the preferences for DRM (whether DRM is enabled and getting the drm
53 // salt) on the UI thread.
54 void CheckPrefsOnUIThread();
56 // Compute the device ID on the UI thread with the given salt and machine ID.
57 void ComputeOnUIThread(const std::string& salt,
58 const std::string& machine_id);
60 // Legacy method used to get the device ID for ChromeOS.
61 void LegacyComputeOnBlockingPool(const base::FilePath& profile_path,
62 const std::string& salt);
64 // Runs the callback passed into Start() on the IO thread with the device ID
65 // or the empty string on failure.
66 void RunCallbackOnIOThread(const std::string& id, int32_t result);
68 friend class base::RefCountedThreadSafe<DeviceIDFetcher>;
70 // The callback to run when the ID has been fetched.
71 IDCallback callback_;
73 // Whether a request is in progress.
74 bool in_progress_;
76 int render_process_id_;
78 DISALLOW_COPY_AND_ASSIGN(DeviceIDFetcher);
81 } // namespace chrome
83 #endif // CHROME_BROWSER_RENDERER_HOST_PEPPER_DEVICE_ID_FETCHER_H_