1 // Copyright 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 CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_RESOURCE_GETTER_IMPL_H_ 6 #define CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_RESOURCE_GETTER_IMPL_H_ 7 8 #include <jni.h> 9 #include <string> 10 11 #include "base/memory/ref_counted.h" 12 #include "base/memory/weak_ptr.h" 13 #include "base/synchronization/waitable_event.h" 14 #include "media/base/android/media_resource_getter.h" 15 #include "media/base/android/media_url_interceptor.h" 16 #include "net/base/auth.h" 17 #include "net/cookies/canonical_cookie.h" 18 19 namespace fileapi { 20 class FileSystemContext; 21 } 22 23 namespace net { 24 class URLRequestContextGetter; 25 } 26 27 namespace content { 28 29 class BrowserContext; 30 class ResourceContext; 31 32 // This class implements media::MediaResourceGetter to retrieve resources 33 // asynchronously on the UI thread. 34 class MediaResourceGetterImpl : public media::MediaResourceGetter { 35 public: 36 // Construct a MediaResourceGetterImpl object. |browser_context| and 37 // |render_process_id| are passed to retrieve the CookieStore. 38 // |file_system_context| are used to get the platform path. 39 MediaResourceGetterImpl(BrowserContext* browser_context, 40 fileapi::FileSystemContext* file_system_context, 41 int render_process_id, int render_frame_id); 42 virtual ~MediaResourceGetterImpl(); 43 44 // media::MediaResourceGetter implementation. 45 // Must be called on the UI thread. 46 virtual void GetCookies(const GURL& url, 47 const GURL& first_party_for_cookies, 48 const GetCookieCB& callback) OVERRIDE; 49 virtual void GetPlatformPathFromURL( 50 const GURL& url, 51 const GetPlatformPathCB& callback) OVERRIDE; 52 virtual void ExtractMediaMetadata( 53 const std::string& url, const std::string& cookies, 54 const std::string& user_agent, 55 const ExtractMediaMetadataCB& callback) OVERRIDE; 56 virtual void ExtractMediaMetadata( 57 const int fd, 58 const int64 offset, 59 const int64 size, 60 const ExtractMediaMetadataCB& callback) OVERRIDE; 61 62 static bool RegisterMediaResourceGetter(JNIEnv* env); 63 64 private: 65 // Called when GetCookies() finishes. 66 void GetCookiesCallback( 67 const GetCookieCB& callback, const std::string& cookies); 68 69 // Called when GetPlatformPathFromFileSystemURL() finishes. 70 void GetPlatformPathCallback( 71 const GetPlatformPathCB& callback, const std::string& platform_path); 72 73 // BrowserContext to retrieve URLRequestContext and ResourceContext. 74 BrowserContext* browser_context_; 75 76 // FileSystemContext to be used on FILE thread. 77 fileapi::FileSystemContext* file_system_context_; 78 79 // Render process id, used to check whether the process can access cookies. 80 int render_process_id_; 81 82 // Render frame id, used to check tab specific cookie policy. 83 int render_frame_id_; 84 85 // NOTE: Weak pointers must be invalidated before all other member variables. 86 base::WeakPtrFactory<MediaResourceGetterImpl> weak_factory_; 87 88 DISALLOW_COPY_AND_ASSIGN(MediaResourceGetterImpl); 89 }; 90 91 } // namespace content 92 93 #endif // CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_RESOURCE_GETTER_IMPL_H_ 94