- add sources.
[platform/framework/web/crosswalk.git] / src / content / browser / media / android / media_resource_getter_impl.h
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 "net/cookies/canonical_cookie.h"
16
17 namespace fileapi {
18 class FileSystemContext;
19 }
20
21 namespace net {
22 class URLRequestContextGetter;
23 }
24
25 namespace content {
26
27 class BrowserContext;
28 class ResourceContext;
29
30 // This class implements media::MediaResourceGetter to retrieve resources
31 // asynchronously on the UI thread.
32 class MediaResourceGetterImpl : public media::MediaResourceGetter {
33  public:
34   // Construct a MediaResourceGetterImpl object. |browser_context| and
35   // |renderer_id| are passed to retrieve the CookieStore.
36   // |file_system_context| are used to get the platform path.
37   MediaResourceGetterImpl(BrowserContext* browser_context,
38                           fileapi::FileSystemContext* file_system_context,
39                           int renderer_id, int routing_id);
40   virtual ~MediaResourceGetterImpl();
41
42   // media::MediaResourceGetter implementation.
43   // Must be called on the UI thread.
44   virtual void GetCookies(const GURL& url,
45                           const GURL& first_party_for_cookies,
46                           const GetCookieCB& callback) OVERRIDE;
47   virtual void GetPlatformPathFromFileSystemURL(
48       const GURL& url,
49       const GetPlatformPathCB& callback) OVERRIDE;
50   virtual void ExtractMediaMetadata(
51       const std::string& url, const std::string& cookies,
52       const ExtractMediaMetadataCB& callback) OVERRIDE;
53
54   static bool RegisterMediaResourceGetter(JNIEnv* env);
55
56  private:
57   // Called when GetCookies() finishes.
58   void GetCookiesCallback(
59       const GetCookieCB& callback, const std::string& cookies);
60
61   // Called when GetPlatformPathFromFileSystemURL() finishes.
62   void GetPlatformPathCallback(
63       const GetPlatformPathCB& callback, const std::string& platform_path);
64
65   // BrowserContext to retrieve URLRequestContext and ResourceContext.
66   BrowserContext* browser_context_;
67
68   // FileSystemContext to be used on FILE thread.
69   fileapi::FileSystemContext* file_system_context_;
70
71   // Used to post tasks.
72   base::WeakPtrFactory<MediaResourceGetterImpl> weak_this_;
73
74   // Render process id, used to check whether the process can access cookies.
75   int renderer_id_;
76
77   // Routing id for the render view, used to check tab specific cookie policy.
78   int routing_id_;
79
80   DISALLOW_COPY_AND_ASSIGN(MediaResourceGetterImpl);
81 };
82
83 }  // namespace content
84
85 #endif  // CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_RESOURCE_GETTER_IMPL_H_