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.
5 #ifndef CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_RESOURCE_GETTER_IMPL_H_
6 #define CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_RESOURCE_GETTER_IMPL_H_
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"
20 class FileSystemContext
;
24 class URLRequestContextGetter
;
30 class ResourceContext
;
32 // This class implements media::MediaResourceGetter to retrieve resources
33 // asynchronously on the UI thread.
34 class MediaResourceGetterImpl
: public media::MediaResourceGetter
{
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 storage::FileSystemContext
* file_system_context
,
41 int render_process_id
,
43 virtual ~MediaResourceGetterImpl();
45 // media::MediaResourceGetter implementation.
46 // Must be called on the UI thread.
47 virtual void GetAuthCredentials(
49 const GetAuthCredentialsCB
& callback
) OVERRIDE
;
50 virtual void GetCookies(
52 const GURL
& first_party_for_cookies
,
53 const GetCookieCB
& callback
) OVERRIDE
;
54 virtual void GetPlatformPathFromURL(
56 const GetPlatformPathCB
& callback
) OVERRIDE
;
57 virtual void ExtractMediaMetadata(
58 const std::string
& url
,
59 const std::string
& cookies
,
60 const std::string
& user_agent
,
61 const ExtractMediaMetadataCB
& callback
) OVERRIDE
;
62 virtual void ExtractMediaMetadata(
66 const ExtractMediaMetadataCB
& callback
) OVERRIDE
;
68 static bool RegisterMediaResourceGetter(JNIEnv
* env
);
71 // Called when GetAuthCredentials() finishes.
72 void GetAuthCredentialsCallback(
73 const GetAuthCredentialsCB
& callback
,
74 const net::AuthCredentials
& credentials
);
76 // Called when GetCookies() finishes.
77 void GetCookiesCallback(
78 const GetCookieCB
& callback
, const std::string
& cookies
);
80 // Called when GetPlatformPathFromFileSystemURL() finishes.
81 void GetPlatformPathCallback(
82 const GetPlatformPathCB
& callback
, const std::string
& platform_path
);
84 // BrowserContext to retrieve URLRequestContext and ResourceContext.
85 BrowserContext
* browser_context_
;
87 // FileSystemContext to be used on FILE thread.
88 storage::FileSystemContext
* file_system_context_
;
90 // Render process id, used to check whether the process can access cookies.
91 int render_process_id_
;
93 // Render frame id, used to check tab specific cookie policy.
96 // NOTE: Weak pointers must be invalidated before all other member variables.
97 base::WeakPtrFactory
<MediaResourceGetterImpl
> weak_factory_
;
99 DISALLOW_COPY_AND_ASSIGN(MediaResourceGetterImpl
);
102 } // namespace content
104 #endif // CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_RESOURCE_GETTER_IMPL_H_