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

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

Issue 1809203006: Switch to use download GUID to indentify download items (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix merge error Created 4 years, 9 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #ifndef CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_MANAGER_SERVICE_H_ 5 #ifndef CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_MANAGER_SERVICE_H_
6 #define CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_MANAGER_SERVICE_H_ 6 #define CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_MANAGER_SERVICE_H_
7 7
8 #include <jni.h> 8 #include <jni.h>
9 #include <string> 9 #include <string>
10 10
11 #include "base/android/scoped_java_ref.h" 11 #include "base/android/scoped_java_ref.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "content/public/browser/download_manager.h" 14 #include "content/public/browser/download_manager.h"
15 15
16 using base::android::JavaParamRef;
17
16 namespace content { 18 namespace content {
17 class DownloadItem; 19 class DownloadItem;
18 } 20 }
19 21
20 // Native side of DownloadManagerService.java. The native object is owned by its 22 // Native side of DownloadManagerService.java. The native object is owned by its
21 // Java object. 23 // Java object.
22 class DownloadManagerService : public content::DownloadManager::Observer { 24 class DownloadManagerService : public content::DownloadManager::Observer {
23 public: 25 public:
24 // JNI registration. 26 // JNI registration.
25 static bool RegisterDownloadManagerService(JNIEnv* env); 27 static bool RegisterDownloadManagerService(JNIEnv* env);
26 28
27 DownloadManagerService(JNIEnv* env, 29 DownloadManagerService(JNIEnv* env,
28 jobject jobj, 30 jobject jobj,
29 content::DownloadManager* manager); 31 content::DownloadManager* manager);
30 ~DownloadManagerService() override; 32 ~DownloadManagerService() override;
31 33
32 // Called to resume downloading the item that has ID equal to |download_id|. 34 // Called to resume downloading the item that has GUID equal to
33 // If the DownloadItem is not yet created, retry after a while. 35 // |jdownload_guid|. If the DownloadItem is not yet created, retry after
36 // a while.
34 void ResumeDownload(JNIEnv* env, 37 void ResumeDownload(JNIEnv* env,
35 jobject obj, 38 jobject obj,
36 uint32_t download_id, 39 uint32_t download_id,
40 const JavaParamRef<jstring>& jdownload_guid,
37 jstring fileName); 41 jstring fileName);
38 42
39 // Called to cancel a download item that has ID equal to |download_id|. 43 // Called to cancel a download item that has GUID equal to |jdownload_guid|.
40 // If the DownloadItem is not yet created, retry after a while. 44 // If the DownloadItem is not yet created, retry after a while.
41 void CancelDownload(JNIEnv* env, jobject obj, uint32_t download_id); 45 void CancelDownload(JNIEnv* env,
46 jobject obj,
47 const JavaParamRef<jstring>& jdownload_guid);
42 48
43 // Called to pause a download item that has ID equal to |download_id|. 49 // Called to pause a download item that has GUID equal to |jdownload_guid|.
44 // If the DownloadItem is not yet created, do nothing as it is already paused. 50 // If the DownloadItem is not yet created, do nothing as it is already paused.
45 void PauseDownload(JNIEnv* env, jobject obj, uint32_t download_id); 51 void PauseDownload(JNIEnv* env,
52 jobject obj,
53 const JavaParamRef<jstring>& jdownload_guid);
46 54
47 // content::DownloadManager::Observer methods. 55 // content::DownloadManager::Observer methods.
48 void ManagerGoingDown(content::DownloadManager* manager) override; 56 void ManagerGoingDown(content::DownloadManager* manager) override;
49 57
50 private: 58 private:
51 // For testing. 59 // For testing.
52 friend class DownloadManagerServiceTest; 60 friend class DownloadManagerServiceTest;
53 61
54 // Resume downloading the given DownloadItem. 62 // Resume downloading the given DownloadItem.
55 void ResumeDownloadItem(content::DownloadItem* item, 63 void ResumeDownloadItem(content::DownloadItem* item,
56 const std::string& fileName); 64 const std::string& fileName);
57 65
58 // Helper function to start the download resumption. If |retry| is true, 66 // Helper function to start the download resumption. If |retry| is true,
59 // chrome will retry the resumption if the download item is not loaded. 67 // chrome will retry the resumption if the download item is not loaded.
60 void ResumeDownloadInternal(uint32_t download_id, 68 void ResumeDownloadInternal(uint32_t download_id,
69 const std::string& download_guid,
61 const std::string& fileName, 70 const std::string& fileName,
62 bool retry); 71 bool retry);
63 72
64 // Helper function to cancel a download. If |retry| is true, 73 // Helper function to cancel a download. If |retry| is true,
65 // chrome will retry the cancellation if the download item is not loaded. 74 // chrome will retry the cancellation if the download item is not loaded.
66 void CancelDownloadInternal(uint32_t download_id, bool retry); 75 void CancelDownloadInternal(const std::string& download_guid, bool retry);
67 76
68 // Called to notify the java side that download resumption failed. 77 // Called to notify the java side that download resumption failed.
69 void OnResumptionFailed(uint32_t download_id, const std::string& fileName); 78 void OnResumptionFailed(uint32_t download_id, const std::string& fileName);
70 79
71 typedef base::Callback<void(bool)> ResumeCallback; 80 typedef base::Callback<void(bool)> ResumeCallback;
72 void set_resume_callback_for_testing(const ResumeCallback& resume_cb) { 81 void set_resume_callback_for_testing(const ResumeCallback& resume_cb) {
73 resume_callback_for_testing_ = resume_cb; 82 resume_callback_for_testing_ = resume_cb;
74 } 83 }
75 84
76 // Reference to the Java object. 85 // Reference to the Java object.
77 base::android::ScopedJavaGlobalRef<jobject> java_ref_; 86 base::android::ScopedJavaGlobalRef<jobject> java_ref_;
78 87
79 // Download manager this class observes 88 // Download manager this class observes
80 content::DownloadManager* manager_; 89 content::DownloadManager* manager_;
81 90
82 ResumeCallback resume_callback_for_testing_; 91 ResumeCallback resume_callback_for_testing_;
83 92
84 DISALLOW_COPY_AND_ASSIGN(DownloadManagerService); 93 DISALLOW_COPY_AND_ASSIGN(DownloadManagerService);
85 }; 94 };
86 95
87 #endif // CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_MANAGER_SERVICE_H_ 96 #endif // CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_MANAGER_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698