Chromium Code Reviews| Index: chrome/browser/android/download_overwrite_infobar_delegate.cc |
| diff --git a/chrome/browser/android/download_overwrite_infobar_delegate.cc b/chrome/browser/android/download_overwrite_infobar_delegate.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9d26fe44a3cbf811050fa3d1df8dd98a04740929 |
| --- /dev/null |
| +++ b/chrome/browser/android/download_overwrite_infobar_delegate.cc |
| @@ -0,0 +1,83 @@ |
| +// Copyright 2014 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. |
| + |
| +#include "chrome/browser/android/download_overwrite_infobar_delegate.h" |
| + |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/strings/utf_string_conversions.h" |
| +#include "chrome/browser/infobars/infobar_service.h" |
| +#include "chrome/browser/ui/android/infobars/download_overwrite_infobar.h" |
| +#include "chrome/grit/generated_resources.h" |
| +#include "components/infobars/core/infobar.h" |
| +#include "content/public/browser/download_item.h" |
| +#include "content/public/browser/web_contents.h" |
| +#include "grit/theme_resources.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| + |
| +namespace chrome { |
| +namespace android { |
| + |
| +DownloadOverwriteInfoBarDelegate::~DownloadOverwriteInfoBarDelegate() { |
| +} |
| + |
| +// static |
| +infobars::InfoBar* DownloadOverwriteInfoBarDelegate::Create( |
| + content::DownloadItem* download, |
| + const base::FilePath& suggested_path, |
| + const FileSelectedCallback& callback) { |
| + DCHECK(download); |
| + if (!download) |
| + return NULL; |
|
Peter Kasting
2014/10/24 01:32:22
Don't handle DCHECK failure. Either download can
Changwan Ryu
2014/10/27 06:40:04
Removed DCHECK. Infobar won't be created in this c
|
| + content::WebContents* web_contents = download->GetWebContents(); |
| + if (!web_contents) |
|
Peter Kasting
2014/10/24 01:32:22
When can this actually be NULL?
Changwan Ryu
2014/10/27 06:40:04
I'm not sure, but there were similar checks in oth
Ted C
2014/10/27 15:30:11
DownloadFilePicker (download_file_picker.cc) doesn
Peter Kasting
2014/10/27 17:49:27
Please find out for certain. We should never have
Changwan Ryu
2014/10/28 04:59:43
Ok, I digged a bit.
download_file_picker.cc has t
Peter Kasting
2014/10/29 04:08:03
If it has no comments about when/why this can be N
|
| + return NULL; |
| + |
| + InfoBarService* infobar_service = |
| + InfoBarService::FromWebContents(web_contents); |
| + |
| + DownloadOverwriteInfoBarDelegate* const delegate = |
|
Peter Kasting
2014/10/24 01:32:22
Nit: Foo* const, while fine with me, is unusual in
Changwan Ryu
2014/10/27 06:40:04
Done. Thanks for the detailed explanation.
|
| + new DownloadOverwriteInfoBarDelegate(download, suggested_path, callback); |
| + infobars::InfoBar* infobar = DownloadOverwriteInfoBar::CreateInfoBar( |
| + scoped_ptr<DownloadOverwriteInfoBarDelegate>(delegate)).release(); |
|
Peter Kasting
2014/10/24 01:32:22
Why are you releasing this just to make a scoped_p
Changwan Ryu
2014/10/27 06:40:04
Done.
|
| + return infobar_service->AddInfoBar(scoped_ptr<infobars::InfoBar>(infobar)); |
| +} |
| + |
| +DownloadOverwriteInfoBarDelegate* |
| + DownloadOverwriteInfoBarDelegate::AsDownloadOverwriteInfoBarDelegate() { |
| + return this; |
| +} |
| + |
| +bool DownloadOverwriteInfoBarDelegate::Accept() { |
| + callback_.Run(suggested_path_); |
| + return true; |
| +} |
| + |
| +bool DownloadOverwriteInfoBarDelegate::Cancel() { |
| + callback_.Run(base::FilePath()); |
| + return true; |
| +} |
| + |
| +DownloadOverwriteInfoBarDelegate::DownloadOverwriteInfoBarDelegate( |
| + content::DownloadItem* download, |
| + const base::FilePath& suggested_path, |
| + const FileSelectedCallback& callback) |
| + : pending_id_(download->GetId()), |
| + suggested_path_(suggested_path), |
| + callback_(callback) { |
| +} |
| + |
| +std::string DownloadOverwriteInfoBarDelegate::GetFileName() const { |
| + return suggested_path_.BaseName().value(); |
| +} |
| + |
| +std::string DownloadOverwriteInfoBarDelegate::GetDirName() const { |
| + return suggested_path_.DirName().BaseName().value(); |
| +} |
| + |
| +std::string DownloadOverwriteInfoBarDelegate::GetDirFullPath() const { |
| + return suggested_path_.DirName().value(); |
| +} |
| + |
| +} // namespace android |
| +} // namespace chrome |