device_id_fetcher.h revision a02191e04bc25c4935f804f2c080ae28663d096d
1f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Copyright (c) 2013 The Chromium Authors. All rights reserved. 2f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Use of this source code is governed by a BSD-style license that can be 3f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// found in the LICENSE file. 4f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 5f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef CHROME_BROWSER_RENDERER_HOST_PEPPER_DEVICE_ID_FETCHER_H_ 6f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define CHROME_BROWSER_RENDERER_HOST_PEPPER_DEVICE_ID_FETCHER_H_ 7f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 8f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <string> 9f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 10f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "base/basictypes.h" 11f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "base/callback.h" 12f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "base/compiler_specific.h" 13f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "base/files/file_path.h" 14f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "base/memory/ref_counted.h" 15f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "ppapi/c/pp_instance.h" 16f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 17f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass Profile; 18f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 19f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgnamespace content { 20f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass BrowserPpapiHost; 21f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 22f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 23f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgnamespace user_prefs { 24f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass PrefRegistrySyncable; 25f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 26f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 27f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgnamespace chrome { 28f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 29f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// This class allows asynchronously fetching a unique device ID. The callback 30f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// passed in when calling Start() will be called when the ID has been fetched 31f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// or on error. 32f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass DeviceIDFetcher : public base::RefCountedThreadSafe<DeviceIDFetcher> { 33f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org public: 34f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org typedef base::Callback<void(const std::string&, int32_t)> IDCallback; 35f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 36f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org explicit DeviceIDFetcher(int render_process_id); 37f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 38f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org // Schedules the request operation. Returns false if a request is in progress, 39f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org // true otherwise. 40f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org bool Start(const IDCallback& callback); 41f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 42f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org // Called to register the |kEnableDRM| and |kDRMSalt| preferences. 43f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* prefs); 44f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 45f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org // Return the path where the legacy device ID is stored (for ChromeOS only). 46f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static base::FilePath GetLegacyDeviceIDPath( 47f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const base::FilePath& profile_path); 48f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 49f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org private: 50f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org ~DeviceIDFetcher(); 51f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 52f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org // Checks the preferences for DRM (whether DRM is enabled and getting the drm 53f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org // salt) on the UI thread. 54f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org void CheckPrefsOnUIThread(); 55f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 56f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org // Compute the device ID on the UI thread with the given salt and machine ID. 57f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org void ComputeOnUIThread(const std::string& salt, 58f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const std::string& machine_id); 59f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 60f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org // Legacy method used to get the device ID for ChromeOS. 61f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org void LegacyComputeOnBlockingPool(const base::FilePath& profile_path, 62f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const std::string& salt); 63f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 64f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org // Runs the callback passed into Start() on the IO thread with the device ID 65f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org // or the empty string on failure. 66f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org void RunCallbackOnIOThread(const std::string& id, int32_t result); 67f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 68f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org friend class base::RefCountedThreadSafe<DeviceIDFetcher>; 69f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 70f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org // The callback to run when the ID has been fetched. 71f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org IDCallback callback_; 72f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 73f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org // Whether a request is in progress. 74f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org bool in_progress_; 75f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 76f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org int render_process_id_; 77f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 78f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org DISALLOW_COPY_AND_ASSIGN(DeviceIDFetcher); 79f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}; 80f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 81f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} // namespace chrome 82f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 83f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif // CHROME_BROWSER_RENDERER_HOST_PEPPER_DEVICE_ID_FETCHER_H_ 84f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org