Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(303)

Side by Side Diff: chrome/browser/android/download/download_controller_android_impl.h

Issue 2014803002: Move DownloadControllerAndroid from content/ to chrome/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved DownloadControllerAndroid(Impl) to chrome/ Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This class pairs with DownloadController on Java side to forward requests 5 // This class pairs with DownloadController on Java side to forward requests
6 // for GET downloads to the current DownloadListener. POST downloads are 6 // for GET downloads to the current DownloadListener. POST downloads are
7 // handled on the native side. 7 // handled on the native side.
8 // 8 //
9 // Both classes are Singleton classes. C++ object owns Java object. 9 // Both classes are Singleton classes. C++ object owns Java object.
10 // 10 //
11 // Call sequence 11 // Call sequence
12 // GET downloads: 12 // GET downloads:
13 // DownloadControllerAndroid::CreateGETDownload() => 13 // DownloadControllerAndroid::CreateGETDownload() =>
14 // DownloadController.newHttpGetDownload() => 14 // DownloadController.newHttpGetDownload() =>
15 // DownloadListener.onDownloadStart() / 15 // DownloadListener.onDownloadStart() /
16 // DownloadListener2.requestHttpGetDownload() 16 // DownloadListener2.requestHttpGetDownload()
17 // 17 //
18 18
19 #ifndef CONTENT_BROWSER_ANDROID_DOWNLOAD_CONTROLLER_ANDROID_IMPL_H_ 19 #ifndef CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_CONTROLLER_ANDROID_IMPL_H_
20 #define CONTENT_BROWSER_ANDROID_DOWNLOAD_CONTROLLER_ANDROID_IMPL_H_ 20 #define CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_CONTROLLER_ANDROID_IMPL_H_
21
22 #include <stdint.h>
21 23
22 #include <string> 24 #include <string>
23 25
24 #include <stdint.h>
25
26 #include "base/android/jni_weak_ref.h" 26 #include "base/android/jni_weak_ref.h"
27 #include "base/android/scoped_java_ref.h" 27 #include "base/android/scoped_java_ref.h"
28 #include "base/callback.h" 28 #include "base/callback.h"
29 #include "base/macros.h" 29 #include "base/macros.h"
30 #include "base/memory/scoped_vector.h" 30 #include "base/memory/scoped_vector.h"
31 #include "base/memory/singleton.h" 31 #include "base/memory/singleton.h"
32 #include "content/public/browser/android/download_controller_android.h" 32 #include "chrome/browser/android/download/download_controller_android.h"
33 #include "chrome/browser/ui/android/view_android_helper.h"
33 #include "net/cookies/cookie_monster.h" 34 #include "net/cookies/cookie_monster.h"
34 #include "url/gurl.h" 35 #include "url/gurl.h"
35 36
36 namespace net { 37 namespace net {
37 class URLRequest; 38 class URLRequest;
38 } 39 }
39 40
41 namespace ui {
42 class WindowAndroid;
43 }
44
40 namespace content { 45 namespace content {
41 struct GlobalRequestID; 46 struct GlobalRequestID;
42 class DeferredDownloadObserver;
43 class RenderViewHost; 47 class RenderViewHost;
44 class WebContents; 48 class WebContents;
49 }
45 50
46 class DownloadControllerAndroidImpl : public DownloadControllerAndroid { 51 class DownloadControllerAndroidImpl : public DownloadControllerAndroid {
no sievers 2016/06/07 21:35:23 nit: I think this could just be DownloadController
Jinsuk Kim 2016/06/08 06:29:08 Done.
47 public: 52 public:
48 static DownloadControllerAndroidImpl* GetInstance(); 53 static DownloadControllerAndroidImpl* GetInstance();
49 54
50 static bool RegisterDownloadController(JNIEnv* env); 55 static bool RegisterDownloadController(JNIEnv* env);
51 56
52 // Called when DownloadController Java object is instantiated. 57 // Called when DownloadController Java object is instantiated.
53 void Init(JNIEnv* env, jobject obj); 58 void Init(JNIEnv* env, jobject obj);
54 59
55 // Removes a deferred download from |deferred_downloads_|.
56 void CancelDeferredDownload(DeferredDownloadObserver* observer);
57
58 // DownloadControllerAndroid implementation. 60 // DownloadControllerAndroid implementation.
59 void AcquireFileAccessPermission( 61 void AcquireFileAccessPermission(
60 WebContents* web_contents, 62 content::WebContents* web_contents,
61 const AcquireFileAccessPermissionCallback& callback) override; 63 const AcquireFileAccessPermissionCallback& callback) override;
62 void SetDefaultDownloadFileName(const std::string& file_name) override; 64 void SetDefaultDownloadFileName(const std::string& file_name) override;
63 65
64 private: 66 private:
65 // Used to store all the information about an Android download. 67 // Used to store all the information about an Android download.
66 struct DownloadInfoAndroid { 68 struct DownloadInfoAndroid {
67 explicit DownloadInfoAndroid(net::URLRequest* request); 69 explicit DownloadInfoAndroid(net::URLRequest* request);
68 DownloadInfoAndroid(const DownloadInfoAndroid& other); 70 DownloadInfoAndroid(const DownloadInfoAndroid& other);
69 ~DownloadInfoAndroid(); 71 ~DownloadInfoAndroid();
70 72
71 // The URL from which we are downloading. This is the final URL after any 73 // The URL from which we are downloading. This is the final URL after any
72 // redirection by the server for |original_url_|. 74 // redirection by the server for |original_url_|.
73 GURL url; 75 GURL url;
74 // The original URL before any redirection by the server for this URL. 76 // The original URL before any redirection by the server for this URL.
75 GURL original_url; 77 GURL original_url;
76 int64_t total_bytes; 78 int64_t total_bytes;
77 std::string content_disposition; 79 std::string content_disposition;
78 std::string original_mime_type; 80 std::string original_mime_type;
79 std::string user_agent; 81 std::string user_agent;
80 std::string cookie; 82 std::string cookie;
81 std::string referer; 83 std::string referer;
82 bool has_user_gesture; 84 bool has_user_gesture;
83 85
84 WebContents* web_contents; 86 content::WebContents* web_contents;
85 // Default copy constructor is used for passing this struct by value. 87 // Default copy constructor is used for passing this struct by value.
86 }; 88 };
87 struct JavaObject; 89 struct JavaObject;
88 friend struct base::DefaultSingletonTraits<DownloadControllerAndroidImpl>; 90 friend struct base::DefaultSingletonTraits<DownloadControllerAndroidImpl>;
89 DownloadControllerAndroidImpl(); 91 DownloadControllerAndroidImpl();
90 ~DownloadControllerAndroidImpl() override; 92 ~DownloadControllerAndroidImpl() override;
91 93
92 // Helper method for implementing AcquireFileAccessPermission(). 94 // Helper method for implementing AcquireFileAccessPermission().
93 bool HasFileAccessPermission( 95 bool HasFileAccessPermission(ui::WindowAndroid* window_android);
94 base::android::ScopedJavaLocalRef<jobject> j_content_view_core);
95 96
96 // DownloadControllerAndroid implementation. 97 // DownloadControllerAndroid implementation.
97 void CreateGETDownload(int render_process_id, 98 void CreateGETDownload(int render_process_id,
98 int render_view_id, 99 int render_view_id,
99 int request_id, 100 int request_id,
100 bool must_download) override; 101 bool must_download) override;
101 void OnDownloadStarted(DownloadItem* download_item) override; 102 void OnDownloadStarted(content::DownloadItem* download_item) override;
102 void StartContextMenuDownload(const ContextMenuParams& params, 103 void StartContextMenuDownload(const content::ContextMenuParams& params,
103 WebContents* web_contents, 104 content::WebContents* web_contents,
104 bool is_link, 105 bool is_link,
105 const std::string& extra_headers) override; 106 const std::string& extra_headers) override;
106 void DangerousDownloadValidated(WebContents* web_contents, 107 void DangerousDownloadValidated(content::WebContents* web_contents,
107 const std::string& download_guid, 108 const std::string& download_guid,
108 bool accept) override; 109 bool accept) override;
109 110
110 // DownloadItem::Observer interface. 111 // DownloadItem::Observer interface.
111 void OnDownloadUpdated(DownloadItem* item) override; 112 void OnDownloadUpdated(content::DownloadItem* item) override;
112 113
113 typedef base::Callback<void(const DownloadInfoAndroid&)> 114 typedef base::Callback<void(const DownloadInfoAndroid&)>
114 GetDownloadInfoCB; 115 GetDownloadInfoCB;
115 void PrepareDownloadInfo(const GlobalRequestID& global_id, 116 void PrepareDownloadInfo(const content::GlobalRequestID& global_id,
116 const GetDownloadInfoCB& callback); 117 const GetDownloadInfoCB& callback);
117 void CheckPolicyAndLoadCookies(const DownloadInfoAndroid& info, 118 void CheckPolicyAndLoadCookies(const DownloadInfoAndroid& info,
118 const GetDownloadInfoCB& callback, 119 const GetDownloadInfoCB& callback,
119 const GlobalRequestID& global_id, 120 const content::GlobalRequestID& global_id,
120 const net::CookieList& cookie_list); 121 const net::CookieList& cookie_list);
121 void DoLoadCookies(const DownloadInfoAndroid& info, 122 void DoLoadCookies(const DownloadInfoAndroid& info,
122 const GetDownloadInfoCB& callback, 123 const GetDownloadInfoCB& callback,
123 const GlobalRequestID& global_id); 124 const content::GlobalRequestID& global_id);
124 void OnCookieResponse(DownloadInfoAndroid info, 125 void OnCookieResponse(DownloadInfoAndroid info,
125 const GetDownloadInfoCB& callback, 126 const GetDownloadInfoCB& callback,
126 const std::string& cookie); 127 const std::string& cookie);
127 void StartDownloadOnUIThread(const GetDownloadInfoCB& callback, 128 void StartDownloadOnUIThread(const GetDownloadInfoCB& callback,
128 const DownloadInfoAndroid& info); 129 const DownloadInfoAndroid& info);
129 void StartAndroidDownload(int render_process_id, 130 void StartAndroidDownload(int render_process_id,
130 int render_view_id, 131 int render_view_id,
131 bool must_download, 132 bool must_download,
132 const DownloadInfoAndroid& info); 133 const DownloadInfoAndroid& info);
133 void StartAndroidDownloadInternal(int render_process_id, 134 void StartAndroidDownloadInternal(int render_process_id,
134 int render_view_id, 135 int render_view_id,
135 bool must_download, 136 bool must_download,
136 const DownloadInfoAndroid& info, 137 const DownloadInfoAndroid& info,
137 bool allowed); 138 bool allowed);
138 139
139 // The download item contains dangerous file types. 140 // The download item contains dangerous file types.
140 void OnDangerousDownload(DownloadItem *item); 141 void OnDangerousDownload(content::DownloadItem *item);
141 142
142 base::android::ScopedJavaLocalRef<jobject> GetContentViewCoreFromWebContents( 143 base::android::ScopedJavaLocalRef<jobject> GetContentViewCoreFromWebContents(
143 WebContents* web_contents); 144 content::WebContents* web_contents);
144 145
145 // Creates Java object if it is not created already and returns it. 146 // Creates Java object if it is not created already and returns it.
146 JavaObject* GetJavaObject(); 147 JavaObject* GetJavaObject();
147 148
148 JavaObject* java_object_; 149 JavaObject* java_object_;
149 150
150 std::string default_file_name_; 151 std::string default_file_name_;
151 152
152 ScopedVector<DeferredDownloadObserver> deferred_downloads_;
153
154 DISALLOW_COPY_AND_ASSIGN(DownloadControllerAndroidImpl); 153 DISALLOW_COPY_AND_ASSIGN(DownloadControllerAndroidImpl);
155 }; 154 };
156 155
157 } // namespace content 156 #endif // CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_CONTROLLER_ANDROID_IMPL_H_
158
159 #endif // CONTENT_BROWSER_ANDROID_DOWNLOAD_CONTROLLER_ANDROID_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698