forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdownload_impl.h
89 lines (71 loc) · 2.87 KB
/
download_impl.h
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
// Copyright 2020 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 WEBLAYER_BROWSER_DOWNLOAD_IMPL_H_
#define WEBLAYER_BROWSER_DOWNLOAD_IMPL_H_
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/supports_user_data.h"
#include "build/build_config.h"
#include "url/gurl.h"
#include "weblayer/public/download.h"
#if defined(OS_ANDROID)
#include "base/android/scoped_java_ref.h"
#endif
class SkBitmap;
namespace weblayer {
// Base class for downloads that should be represented in the UI.
class DownloadImpl : public Download, public base::SupportsUserData::Data {
public:
~DownloadImpl() override;
DownloadImpl(const DownloadImpl&) = delete;
DownloadImpl& operator=(const DownloadImpl&) = delete;
#if defined(OS_ANDROID)
void SetJavaDownload(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& java_download);
int GetStateImpl(JNIEnv* env) { return static_cast<int>(GetState()); }
jlong GetTotalBytesImpl(JNIEnv* env) { return GetTotalBytes(); }
jlong GetReceivedBytesImpl(JNIEnv* env) { return GetReceivedBytes(); }
void PauseImpl(JNIEnv* env) { Pause(); }
void ResumeImpl(JNIEnv* env) { Resume(); }
void CancelImpl(JNIEnv* env) { Cancel(); }
void OnFinishedImpl(JNIEnv* env, jboolean activated) {
OnFinished(activated);
}
base::android::ScopedJavaLocalRef<jstring> GetLocationImpl(JNIEnv* env);
base::android::ScopedJavaLocalRef<jstring> GetFileNameToReportToUserImpl(
JNIEnv* env);
base::android::ScopedJavaLocalRef<jstring> GetMimeTypeImpl(JNIEnv* env);
int GetErrorImpl(JNIEnv* env) { return static_cast<int>(GetError()); }
base::android::ScopedJavaLocalRef<jobject> GetLargeIconImpl(JNIEnv* env);
base::android::ScopedJavaGlobalRef<jobject> java_download() {
return java_download_;
}
#endif
// Returns an ID suitable for use as an Android notification ID. This must be
// unique across all DownloadImpls.
virtual int GetNotificationId() = 0;
// A transient download is not persisted to disk, which affects its UI
// treatment.
virtual bool IsTransient() = 0;
// Returns the originating URL for this download.
virtual GURL GetSourceUrl() = 0;
// Gets the icon to display. If the return value is null or draws nothing, no
// icon will be displayed.
virtual const SkBitmap* GetLargeIcon() = 0;
// Called when the UI is gone. |activated| is true if the UI was activated, or
// false if it was simply dismissed.
virtual void OnFinished(bool activated) = 0;
// Returns whether this download has been added to the UI via
// DownloadDelegate::OnDownloadStarted.
bool HasBeenAddedToUi();
protected:
DownloadImpl();
private:
#if defined(OS_ANDROID)
base::android::ScopedJavaGlobalRef<jobject> java_download_;
#endif
};
} // namespace weblayer
#endif // WEBLAYER_BROWSER_DOWNLOAD_IMPL_H_