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

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: 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/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/singleton.h"
15 #include "chrome/browser/android/download/download_controller.h" 16 #include "chrome/browser/android/download/download_controller.h"
16 #include "chrome/browser/download/all_download_item_notifier.h" 17 #include "chrome/browser/download/all_download_item_notifier.h"
17 #include "chrome/browser/download/download_history.h" 18 #include "chrome/browser/download/download_history.h"
18 #include "content/public/browser/download_manager.h" 19 #include "content/public/browser/download_manager.h"
19 20
20 using base::android::JavaParamRef; 21 using base::android::JavaParamRef;
21 22
22 namespace content { 23 namespace content {
23 class DownloadItem; 24 class DownloadItem;
24 } 25 }
25 26
26 // Native side of DownloadManagerService.java. The native object is owned by its 27 // Native side of DownloadManagerService.java. The native object is owned by its
27 // Java object. 28 // Java object.
28 class DownloadManagerService : public AllDownloadItemNotifier::Observer, 29 class DownloadManagerService : public AllDownloadItemNotifier::Observer,
29 public DownloadHistory::Observer { 30 public DownloadHistory::Observer {
30 public: 31 public:
31 // JNI registration. 32 // JNI registration.
32 static bool RegisterDownloadManagerService(JNIEnv* env); 33 static bool RegisterDownloadManagerService(JNIEnv* env);
33 34
34 static void OnDownloadCanceled( 35 static void OnDownloadCanceled(
35 content::DownloadItem* download, 36 content::DownloadItem* download,
36 DownloadController::DownloadCancelReason reason); 37 DownloadController::DownloadCancelReason reason);
37 38
38 DownloadManagerService(JNIEnv* env, 39 static DownloadManagerService* GetInstance();
39 jobject jobj); 40
41 DownloadManagerService();
40 ~DownloadManagerService() override; 42 ~DownloadManagerService() override;
41 43
44 // Called to Initialize this object.
45 void Init(JNIEnv* env, jobject obj);
46
42 // Called to resume downloading the item that has GUID equal to 47 // Called to resume downloading the item that has GUID equal to
43 // |jdownload_guid|.. 48 // |jdownload_guid|..
44 void ResumeDownload(JNIEnv* env, 49 void ResumeDownload(JNIEnv* env,
45 jobject obj, 50 jobject obj,
46 const JavaParamRef<jstring>& jdownload_guid, 51 const JavaParamRef<jstring>& jdownload_guid,
47 bool is_off_the_record); 52 bool is_off_the_record);
48 53
49 // Called to cancel a download item that has GUID equal to |jdownload_guid|. 54 // 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. 55 // If the DownloadItem is not yet created, retry after a while.
51 void CancelDownload(JNIEnv* env, 56 void CancelDownload(JNIEnv* env,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 void OnDownloadRemoved(content::DownloadManager* manager, 93 void OnDownloadRemoved(content::DownloadManager* manager,
89 content::DownloadItem* item) override; 94 content::DownloadItem* item) override;
90 95
91 protected: 96 protected:
92 // Called to get the content::DownloadManager instance. 97 // Called to get the content::DownloadManager instance.
93 virtual content::DownloadManager* GetDownloadManager(bool is_off_the_record); 98 virtual content::DownloadManager* GetDownloadManager(bool is_off_the_record);
94 99
95 private: 100 private:
96 // For testing. 101 // For testing.
97 friend class DownloadManagerServiceTest; 102 friend class DownloadManagerServiceTest;
103 friend struct base::DefaultSingletonTraits<DownloadManagerService>;
98 104
99 // Helper function to start the download resumption. 105 // Helper function to start the download resumption.
100 void ResumeDownloadInternal(const std::string& download_guid, 106 void ResumeDownloadInternal(const std::string& download_guid,
101 bool is_off_the_record); 107 bool is_off_the_record);
102 108
103 // Helper function to cancel a download. 109 // Helper function to cancel a download.
104 void CancelDownloadInternal(const std::string& download_guid, 110 void CancelDownloadInternal(const std::string& download_guid,
105 bool is_off_the_record); 111 bool is_off_the_record);
106 112
107 // Helper function to pause a download. 113 // Helper function to pause a download.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 153
148 ResumeCallback resume_callback_for_testing_; 154 ResumeCallback resume_callback_for_testing_;
149 155
150 std::unique_ptr<AllDownloadItemNotifier> original_notifier_; 156 std::unique_ptr<AllDownloadItemNotifier> original_notifier_;
151 std::unique_ptr<AllDownloadItemNotifier> off_the_record_notifier_; 157 std::unique_ptr<AllDownloadItemNotifier> off_the_record_notifier_;
152 158
153 DISALLOW_COPY_AND_ASSIGN(DownloadManagerService); 159 DISALLOW_COPY_AND_ASSIGN(DownloadManagerService);
154 }; 160 };
155 161
156 #endif // CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_MANAGER_SERVICE_H_ 162 #endif // CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_MANAGER_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698