Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / android / download / chrome_download_manager_overwrite_infobar_delegate.cc
blobd4c0cf8c4c7fdbc88895c1076a8e2c92f8fa4c5a
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 void ChromeDownloadManagerOverwriteInfoBarDelegate::OverwriteExistingFile() {
45 file_selected_callback_.Run(suggested_download_path_);
48 void ChromeDownloadManagerOverwriteInfoBarDelegate::CreateNewFile() {
49 content::BrowserThread::PostTask(
50 content::BrowserThread::FILE, FROM_HERE,
51 base::Bind(
52 &ChromeDownloadManagerOverwriteInfoBarDelegate::CreateNewFileInternal,
53 suggested_download_path_, file_selected_callback_));
56 std::string ChromeDownloadManagerOverwriteInfoBarDelegate::GetFileName() const {
57 return suggested_download_path_.BaseName().value();
60 std::string ChromeDownloadManagerOverwriteInfoBarDelegate::GetDirName() const {
61 return suggested_download_path_.DirName().BaseName().value();
64 std::string ChromeDownloadManagerOverwriteInfoBarDelegate::GetDirFullPath()
65 const {
66 return suggested_download_path_.DirName().value();
69 void ChromeDownloadManagerOverwriteInfoBarDelegate::InfoBarDismissed() {
70 file_selected_callback_.Run(base::FilePath());
73 void ChromeDownloadManagerOverwriteInfoBarDelegate::CreateNewFileInternal(
74 const base::FilePath& suggested_download_path,
75 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) {
76 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE);
77 int uniquifier = base::GetUniquePathNumber(suggested_download_path,
78 base::FilePath::StringType());
79 base::FilePath new_path = suggested_download_path;
80 if (uniquifier > 0) {
81 new_path = suggested_download_path.InsertBeforeExtensionASCII(
82 base::StringPrintf(" (%d)", uniquifier));
84 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
85 base::Bind(callback, new_path));
88 } // namespace android
89 } // namespace chrome