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

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

Issue 2014803002: Move DownloadControllerAndroid from content/ to chrome/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix failing tests/bugs 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
(Empty)
1 // Copyright 2016 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 // 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.
10 //
11 // Call sequence
12 // GET downloads:
13 // DownloadController::CreateGETDownload() =>
14 // DownloadController.newHttpGetDownload() =>
15 // DownloadListener.onDownloadStart() /
16 // DownloadListener2.requestHttpGetDownload()
17 //
18
19 #ifndef CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_CONTROLLER_H_
20 #define CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_CONTROLLER_H_
21
22 #include "base/android/scoped_java_ref.h"
23 #include "base/memory/singleton.h"
24 #include "chrome/browser/android/download/download_controller_base.h"
25
26 namespace net {
27 class URLRequest;
28 }
29
30 namespace ui {
31 class WindowAndroid;
32 }
33
34 namespace content {
35 class WebContents;
36 }
37
38 class DownloadController : public DownloadControllerBase {
39 public:
40 static DownloadController* GetInstance();
41
42 static bool RegisterDownloadController(JNIEnv* env);
43
44 // Called when DownloadController Java object is instantiated.
45 void Init(JNIEnv* env, jobject obj);
46
47 // DownloadControllerBase implementation.
48 void AcquireFileAccessPermission(
49 content::WebContents* web_contents,
50 const AcquireFileAccessPermissionCallback& callback) override;
51 void SetDefaultDownloadFileName(const std::string& file_name) override;
52
53 // UMA histogram enum for download cancellation reasons. Keep this
54 // in sync with MobileDownloadCancelReason in histograms.xml. This should be
55 // append only.
56 enum DownloadCancelReason {
57 CANCEL_REASON_NOT_CANCELED = 0,
58 CANCEL_REASON_ACTION_BUTTON,
59 CANCEL_REASON_NOTIFICATION_DISMISSED,
60 CANCEL_REASON_OVERWRITE_INFOBAR_DISMISSED,
61 CANCEL_REASON_NO_STORAGE_PERMISSION,
62 CANCEL_REASON_MAX
63 };
64 static void RecordDownloadCancelReason(DownloadCancelReason reason);
65
66 private:
67 struct JavaObject;
68 friend struct base::DefaultSingletonTraits<DownloadController>;
69 DownloadController();
70 ~DownloadController() override;
71
72 // Helper method for implementing AcquireFileAccessPermission().
73 bool HasFileAccessPermission(ui::WindowAndroid* window_android);
74
75 // DownloadControllerBase implementation.
76 void CreateGETDownload(int render_process_id,
77 int render_view_id,
78 bool must_download,
79 const DownloadInfo& info) override;
80 void OnDownloadStarted(content::DownloadItem* download_item) override;
81 void StartContextMenuDownload(const content::ContextMenuParams& params,
82 content::WebContents* web_contents,
83 bool is_link,
84 const std::string& extra_headers) override;
85 void DangerousDownloadValidated(content::WebContents* web_contents,
86 const std::string& download_guid,
87 bool accept) override;
88
89 // DownloadItem::Observer interface.
90 void OnDownloadUpdated(content::DownloadItem* item) override;
91
92 void StartAndroidDownload(int render_process_id,
93 int render_view_id,
94 bool must_download,
95 const DownloadInfo& info);
96 void StartAndroidDownloadInternal(int render_process_id,
97 int render_view_id,
98 bool must_download,
99 const DownloadInfo& info,
100 bool allowed);
101
102 // The download item contains dangerous file types.
103 void OnDangerousDownload(content::DownloadItem *item);
104
105 base::android::ScopedJavaLocalRef<jobject> GetContentViewCoreFromWebContents(
106 content::WebContents* web_contents);
107
108 // Creates Java object if it is not created already and returns it.
109 JavaObject* GetJavaObject();
110
111 JavaObject* java_object_;
112
113 std::string default_file_name_;
114
115 DISALLOW_COPY_AND_ASSIGN(DownloadController);
116 };
117
118 #endif // CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698