[MacViews] Show comboboxes with a native NSMenu
[chromium-blink-merge.git] / chrome / browser / android / download / chrome_download_manager_overwrite_infobar_delegate.cc
blobc40a584f58e6201df65b00b1f0b046334cc56ec9
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/chrome_download_manager_overwrite_infobar_delegate.h"
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h"
9 #include "base/files/file_util.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/strings/stringprintf.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 namespace chrome {
19 namespace android {
21 ChromeDownloadManagerOverwriteInfoBarDelegate::
22 ~ChromeDownloadManagerOverwriteInfoBarDelegate() {
25 // static
26 void ChromeDownloadManagerOverwriteInfoBarDelegate::Create(
27 InfoBarService* infobar_service,
28 const base::FilePath& suggested_path,
29 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) {
30 infobar_service->AddInfoBar(DownloadOverwriteInfoBar::CreateInfoBar(
31 make_scoped_ptr(new ChromeDownloadManagerOverwriteInfoBarDelegate(
32 suggested_path, callback))));
35 ChromeDownloadManagerOverwriteInfoBarDelegate::
36 ChromeDownloadManagerOverwriteInfoBarDelegate(
37 const base::FilePath& suggested_download_path,
38 const DownloadTargetDeterminerDelegate::FileSelectedCallback&
39 file_selected_callback)
40 : suggested_download_path_(suggested_download_path),
41 file_selected_callback_(file_selected_callback) {
44 bool ChromeDownloadManagerOverwriteInfoBarDelegate::OverwriteExistingFile() {
45 file_selected_callback_.Run(suggested_download_path_);
46 return true;
49 bool ChromeDownloadManagerOverwriteInfoBarDelegate::CreateNewFile() {
50 content::BrowserThread::PostTask(
51 content::BrowserThread::FILE, FROM_HERE,
52 base::Bind(
53 &ChromeDownloadManagerOverwriteInfoBarDelegate::CreateNewFileInternal,
54 suggested_download_path_, file_selected_callback_));
55 return true;
58 std::string ChromeDownloadManagerOverwriteInfoBarDelegate::GetFileName() const {
59 return suggested_download_path_.BaseName().value();
62 std::string ChromeDownloadManagerOverwriteInfoBarDelegate::GetDirName() const {
63 return suggested_download_path_.DirName().BaseName().value();
66 std::string ChromeDownloadManagerOverwriteInfoBarDelegate::GetDirFullPath()
67 const {
68 return suggested_download_path_.DirName().value();
71 void ChromeDownloadManagerOverwriteInfoBarDelegate::InfoBarDismissed() {
72 file_selected_callback_.Run(base::FilePath());
75 void ChromeDownloadManagerOverwriteInfoBarDelegate::CreateNewFileInternal(
76 const base::FilePath& suggested_download_path,
77 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) {
78 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE);
79 int uniquifier = base::GetUniquePathNumber(suggested_download_path,
80 base::FilePath::StringType());
81 base::FilePath new_path = suggested_download_path;
82 if (uniquifier > 0) {
83 new_path = suggested_download_path.InsertBeforeExtensionASCII(
84 base::StringPrintf(" (%d)", uniquifier));
86 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
87 base::Bind(callback, new_path));
90 } // namespace android
91 } // namespace chrome