Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / android / download / android_download_manager_overwrite_infobar_delegate.cc
blob5bb6bf1e09e13a36055bafe9cfeea9e39709793b
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
3 // found in the LICENSE file.
5 #include "chrome/browser/android/download/android_download_manager_overwrite_infobar_delegate.h"
7 #include "base/android/jni_string.h"
8 #include "base/files/file_util.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/stringprintf.h"
11 #include "chrome/browser/android/download/chrome_download_delegate.h"
12 #include "chrome/browser/infobars/infobar_service.h"
13 #include "chrome/browser/ui/android/infobars/download_overwrite_infobar.h"
14 #include "components/infobars/core/infobar.h"
15 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/web_contents.h"
18 using base::android::ScopedJavaLocalRef;
20 namespace chrome {
21 namespace android {
23 AndroidDownloadManagerOverwriteInfoBarDelegate::
24 ~AndroidDownloadManagerOverwriteInfoBarDelegate() {
27 // static
28 void AndroidDownloadManagerOverwriteInfoBarDelegate::Create(
29 InfoBarService* infobar_service,
30 const std::string& file_name,
31 const std::string& dir_name,
32 const std::string& dir_full_path,
33 jobject chrome_download_delegate,
34 jobject download_info) {
35 infobar_service->AddInfoBar(DownloadOverwriteInfoBar::CreateInfoBar(
36 make_scoped_ptr(new AndroidDownloadManagerOverwriteInfoBarDelegate(
37 file_name, dir_name, dir_full_path, chrome_download_delegate,
38 download_info))));
41 AndroidDownloadManagerOverwriteInfoBarDelegate::
42 AndroidDownloadManagerOverwriteInfoBarDelegate(
43 const std::string& file_name,
44 const std::string& dir_name,
45 const std::string& dir_full_path,
46 jobject chrome_download_delegate,
47 jobject download_info)
48 : file_name_(file_name),
49 dir_name_(dir_name),
50 dir_full_path_(dir_full_path) {
51 JNIEnv* env = base::android::AttachCurrentThread();
52 chrome_download_delegate_.Reset(env, chrome_download_delegate);
53 download_info_.Reset(env, download_info);
56 bool AndroidDownloadManagerOverwriteInfoBarDelegate::OverwriteExistingFile() {
57 bool tab_closed = ChromeDownloadDelegate::EnqueueDownloadManagerRequest(
58 chrome_download_delegate_.obj(), true, download_info_.obj());
59 return !tab_closed;
62 bool AndroidDownloadManagerOverwriteInfoBarDelegate::CreateNewFile() {
63 bool tab_closed = ChromeDownloadDelegate::EnqueueDownloadManagerRequest(
64 chrome_download_delegate_.obj(), false, download_info_.obj());
65 return !tab_closed;
68 std::string AndroidDownloadManagerOverwriteInfoBarDelegate::GetFileName()
69 const {
70 return file_name_;
73 std::string AndroidDownloadManagerOverwriteInfoBarDelegate::GetDirName() const {
74 return dir_name_;
77 std::string AndroidDownloadManagerOverwriteInfoBarDelegate::GetDirFullPath()
78 const {
79 return dir_full_path_;
82 } // namespace android
83 } // namespace chrome