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