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

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

Issue 2344483003: Ask download manager to remove a download if it is overwritten by another (Closed)
Patch Set: delete completed download with same path Created 4 years, 3 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 <map> 9 #include <map>
10 #include <string> 10 #include <string>
11 11
12 #include "base/android/scoped_java_ref.h" 12 #include "base/android/scoped_java_ref.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/files/file_path.h"
14 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/singleton.h"
15 #include "chrome/browser/android/download/download_controller.h" 17 #include "chrome/browser/android/download/download_controller.h"
16 #include "chrome/browser/download/all_download_item_notifier.h" 18 #include "chrome/browser/download/all_download_item_notifier.h"
17 #include "chrome/browser/download/download_history.h" 19 #include "chrome/browser/download/download_history.h"
18 #include "content/public/browser/download_manager.h" 20 #include "content/public/browser/download_manager.h"
19 21
20 using base::android::JavaParamRef; 22 using base::android::JavaParamRef;
21 23
22 namespace content { 24 namespace content {
23 class DownloadItem; 25 class DownloadItem;
24 } 26 }
25 27
26 // Native side of DownloadManagerService.java. The native object is owned by its 28 // Native side of DownloadManagerService.java. The native object is owned by its
27 // Java object. 29 // Java object.
28 class DownloadManagerService : public AllDownloadItemNotifier::Observer, 30 class DownloadManagerService : public AllDownloadItemNotifier::Observer,
29 public DownloadHistory::Observer { 31 public DownloadHistory::Observer {
30 public: 32 public:
31 // JNI registration. 33 // JNI registration.
32 static bool RegisterDownloadManagerService(JNIEnv* env); 34 static bool RegisterDownloadManagerService(JNIEnv* env);
33 35
34 static void OnDownloadCanceled( 36 static void OnDownloadCanceled(
35 content::DownloadItem* download, 37 content::DownloadItem* download,
36 DownloadController::DownloadCancelReason reason); 38 DownloadController::DownloadCancelReason reason);
37 39
38 DownloadManagerService(JNIEnv* env, 40 static DownloadManagerService* GetInstance();
39 jobject jobj); 41
42 DownloadManagerService();
40 ~DownloadManagerService() override; 43 ~DownloadManagerService() override;
41 44
45 // Called to Initialize this object.
46 void Init(JNIEnv* env, jobject obj);
47
42 // Called to resume downloading the item that has GUID equal to 48 // Called to resume downloading the item that has GUID equal to
43 // |jdownload_guid|.. 49 // |jdownload_guid|..
44 void ResumeDownload(JNIEnv* env, 50 void ResumeDownload(JNIEnv* env,
45 jobject obj, 51 jobject obj,
46 const JavaParamRef<jstring>& jdownload_guid, 52 const JavaParamRef<jstring>& jdownload_guid,
47 bool is_off_the_record); 53 bool is_off_the_record);
48 54
49 // Called to cancel a download item that has GUID equal to |jdownload_guid|. 55 // Called to cancel a download item that has GUID equal to |jdownload_guid|.
50 // If the DownloadItem is not yet created, retry after a while. 56 // If the DownloadItem is not yet created, retry after a while.
51 void CancelDownload(JNIEnv* env, 57 void CancelDownload(JNIEnv* env,
(...skipping 19 matching lines...) Expand all
71 // downloads in the user's history. 77 // downloads in the user's history.
72 void GetAllDownloads(JNIEnv* env, 78 void GetAllDownloads(JNIEnv* env,
73 const JavaParamRef<jobject>& obj, 79 const JavaParamRef<jobject>& obj,
74 bool is_off_the_record); 80 bool is_off_the_record);
75 81
76 // Called to check if the files associated with any downloads have been 82 // Called to check if the files associated with any downloads have been
77 // removed by an external action. 83 // removed by an external action.
78 void CheckForExternallyRemovedDownloads(JNIEnv* env, 84 void CheckForExternallyRemovedDownloads(JNIEnv* env,
79 const JavaParamRef<jobject>& obj, 85 const JavaParamRef<jobject>& obj,
80 bool is_off_the_record); 86 bool is_off_the_record);
87 // Remove externally removed downloads from history.
88 void RemoveExternallyRemovedDownloads(const base::FilePath& path);
Theresa 2016/09/21 17:40:43 Can this be something like RemoveDownloadsForPath(
qinmin 2016/09/21 21:20:29 Done.
81 89
82 // DownloadHistory::Observer methods. 90 // DownloadHistory::Observer methods.
83 void OnHistoryQueryComplete() override; 91 void OnHistoryQueryComplete() override;
84 92
85 // AllDownloadItemNotifier::Observer methods. 93 // AllDownloadItemNotifier::Observer methods.
86 void OnDownloadUpdated(content::DownloadManager* manager, 94 void OnDownloadUpdated(content::DownloadManager* manager,
87 content::DownloadItem* item) override; 95 content::DownloadItem* item) override;
88 void OnDownloadRemoved(content::DownloadManager* manager, 96 void OnDownloadRemoved(content::DownloadManager* manager,
89 content::DownloadItem* item) override; 97 content::DownloadItem* item) override;
90 98
91 protected: 99 protected:
92 // Called to get the content::DownloadManager instance. 100 // Called to get the content::DownloadManager instance.
93 virtual content::DownloadManager* GetDownloadManager(bool is_off_the_record); 101 virtual content::DownloadManager* GetDownloadManager(bool is_off_the_record);
94 102
95 private: 103 private:
96 // For testing. 104 // For testing.
97 friend class DownloadManagerServiceTest; 105 friend class DownloadManagerServiceTest;
106 friend struct base::DefaultSingletonTraits<DownloadManagerService>;
98 107
99 // Helper function to start the download resumption. 108 // Helper function to start the download resumption.
100 void ResumeDownloadInternal(const std::string& download_guid, 109 void ResumeDownloadInternal(const std::string& download_guid,
101 bool is_off_the_record); 110 bool is_off_the_record);
102 111
103 // Helper function to cancel a download. 112 // Helper function to cancel a download.
104 void CancelDownloadInternal(const std::string& download_guid, 113 void CancelDownloadInternal(const std::string& download_guid,
105 bool is_off_the_record); 114 bool is_off_the_record);
106 115
107 // Helper function to pause a download. 116 // Helper function to pause a download.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 156
148 ResumeCallback resume_callback_for_testing_; 157 ResumeCallback resume_callback_for_testing_;
149 158
150 std::unique_ptr<AllDownloadItemNotifier> original_notifier_; 159 std::unique_ptr<AllDownloadItemNotifier> original_notifier_;
151 std::unique_ptr<AllDownloadItemNotifier> off_the_record_notifier_; 160 std::unique_ptr<AllDownloadItemNotifier> off_the_record_notifier_;
152 161
153 DISALLOW_COPY_AND_ASSIGN(DownloadManagerService); 162 DISALLOW_COPY_AND_ASSIGN(DownloadManagerService);
154 }; 163 };
155 164
156 #endif // CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_MANAGER_SERVICE_H_ 165 #endif // CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_MANAGER_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698