[go: nahoru, domu]

Allow retrieval of media device ID salt even after ResourceContext has gone away.

TBR=willchan@chromium.org
BUG=341211

Review URL: https://codereview.chromium.org/143003031

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251024 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/media/media_device_id_salt.h b/chrome/browser/media/media_device_id_salt.h
index a98e3fb..46df854 100644
--- a/chrome/browser/media/media_device_id_salt.h
+++ b/chrome/browser/media/media_device_id_salt.h
@@ -7,6 +7,7 @@
 
 #include <string>
 
+#include "base/memory/ref_counted.h"
 #include "base/prefs/pref_member.h"
 #include "components/user_prefs/pref_registry_syncable.h"
 
@@ -15,11 +16,12 @@
 // MediaDeviceIDSalt is responsible for creating and retrieving a salt string
 // that is used for creating MediaSource IDs that can be cached by a web
 // service. If the cache is cleared, the  MediaSourceIds are invalidated.
-class MediaDeviceIDSalt {
+//
+// The class is reference counted so that it can be used in the
+// callback returned by ResourceContext::GetMediaDeviceIDSalt.
+class MediaDeviceIDSalt : public base::RefCountedThreadSafe<MediaDeviceIDSalt> {
  public:
-  MediaDeviceIDSalt(PrefService* pref_service,
-                    bool incognito);
-  ~MediaDeviceIDSalt();
+  MediaDeviceIDSalt(PrefService* pref_service, bool incognito);
   void ShutdownOnUIThread();
 
   std::string GetSalt() const;
@@ -28,6 +30,9 @@
   static void Reset(PrefService* pref_service);
 
  private:
+  friend class base::RefCountedThreadSafe<MediaDeviceIDSalt>;
+  ~MediaDeviceIDSalt();
+
   // |incognito_salt_| is initialized in ctor on UI thread but only read
   //  on the IO thread.
   std::string incognito_salt_;