Remove PlatformFile from profile_browsertest
[chromium-blink-merge.git] / content / browser / android / download_controller_android_impl.h
blobdb9b9cf99bba623f907b606c2e95fdb53976b5af
1 // Copyright (c) 2012 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 // This class pairs with DownloadController on Java side to forward requests
6 // for GET downloads to the current DownloadListener. POST downloads are
7 // handled on the native side.
8 //
9 // Both classes are Singleton classes. C++ object owns Java object.
11 // Call sequence
12 // GET downloads:
13 // DownloadControllerAndroid::CreateGETDownload() =>
14 // DownloadController.newHttpGetDownload() =>
15 // DownloadListener.onDownloadStart() /
16 // DownloadListener2.requestHttpGetDownload()
19 #ifndef CONTENT_BROWSER_ANDROID_DOWNLOAD_CONTROLLER_ANDROID_IMPL_H_
20 #define CONTENT_BROWSER_ANDROID_DOWNLOAD_CONTROLLER_ANDROID_IMPL_H_
22 #include <string>
24 #include "base/android/jni_helper.h"
25 #include "base/android/scoped_java_ref.h"
26 #include "base/callback.h"
27 #include "base/memory/singleton.h"
28 #include "content/public/browser/android/download_controller_android.h"
29 #include "content/public/browser/download_item.h"
30 #include "net/cookies/cookie_monster.h"
31 #include "url/gurl.h"
33 namespace net {
34 class URLRequest;
37 namespace content {
38 struct GlobalRequestID;
39 class RenderViewHost;
40 class WebContents;
42 class DownloadControllerAndroidImpl : public DownloadControllerAndroid,
43 public DownloadItem::Observer {
44 public:
45 static DownloadControllerAndroidImpl* GetInstance();
47 static bool RegisterDownloadController(JNIEnv* env);
49 // Called when DownloadController Java object is instantiated.
50 void Init(JNIEnv* env, jobject obj);
51 private:
52 // Used to store all the information about an Android download.
53 struct DownloadInfoAndroid {
54 explicit DownloadInfoAndroid(net::URLRequest* request);
55 ~DownloadInfoAndroid();
57 // The URL from which we are downloading. This is the final URL after any
58 // redirection by the server for |original_url_|.
59 GURL url;
60 // The original URL before any redirection by the server for this URL.
61 GURL original_url;
62 int64 total_bytes;
63 std::string content_disposition;
64 std::string original_mime_type;
65 std::string user_agent;
66 std::string cookie;
67 std::string referer;
69 WebContents* web_contents;
70 // Default copy constructor is used for passing this struct by value.
72 struct JavaObject;
73 friend struct DefaultSingletonTraits<DownloadControllerAndroidImpl>;
74 DownloadControllerAndroidImpl();
75 virtual ~DownloadControllerAndroidImpl();
77 // DownloadControllerAndroid implementation.
78 virtual void CreateGETDownload(int render_process_id, int render_view_id,
79 int request_id) OVERRIDE;
80 virtual void OnDownloadStarted(DownloadItem* download_item) OVERRIDE;
81 virtual void StartContextMenuDownload(
82 const ContextMenuParams& params, WebContents* web_contents,
83 bool is_link) OVERRIDE;
84 virtual void DangerousDownloadValidated(
85 WebContents* web_contents, int download_id, bool accept) OVERRIDE;
87 // DownloadItem::Observer interface.
88 virtual void OnDownloadUpdated(DownloadItem* item) OVERRIDE;
90 typedef base::Callback<void(const DownloadInfoAndroid&)>
91 GetDownloadInfoCB;
92 void PrepareDownloadInfo(const GlobalRequestID& global_id,
93 const GetDownloadInfoCB& callback);
94 void CheckPolicyAndLoadCookies(const DownloadInfoAndroid& info,
95 const GetDownloadInfoCB& callback,
96 const GlobalRequestID& global_id,
97 const net::CookieList& cookie_list);
98 void DoLoadCookies(const DownloadInfoAndroid& info,
99 const GetDownloadInfoCB& callback,
100 const GlobalRequestID& global_id);
101 void OnCookieResponse(DownloadInfoAndroid info,
102 const GetDownloadInfoCB& callback,
103 const std::string& cookie);
104 void StartDownloadOnUIThread(const GetDownloadInfoCB& callback,
105 const DownloadInfoAndroid& info);
106 void StartAndroidDownload(int render_process_id,
107 int render_view_id,
108 const DownloadInfoAndroid& info);
110 // The download item contains dangerous file types.
111 void OnDangerousDownload(DownloadItem *item);
113 base::android::ScopedJavaLocalRef<jobject> GetContentViewCoreFromWebContents(
114 WebContents* web_contents);
116 base::android::ScopedJavaLocalRef<jobject> GetContentView(
117 int render_process_id, int render_view_id);
119 // Creates Java object if it is not created already and returns it.
120 JavaObject* GetJavaObject();
122 JavaObject* java_object_;
124 DISALLOW_COPY_AND_ASSIGN(DownloadControllerAndroidImpl);
127 } // namespace content
129 #endif // CONTENT_BROWSER_ANDROID_DOWNLOAD_CONTROLLER_ANDROID_IMPL_H_