Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(561)

Side by Side Diff: chrome/browser/android/download_overwrite_infobar_delegate.cc

Issue 580043002: [Android] Prompt with infobar on filename conflict (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed ted's comments Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 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.
4
5 #include "chrome/browser/android/download_overwrite_infobar_delegate.h"
6
7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/infobars/infobar_service.h"
10 #include "chrome/browser/ui/android/infobars/download_overwrite_infobar.h"
11 #include "chrome/grit/generated_resources.h"
12 #include "components/infobars/core/infobar.h"
13 #include "content/public/browser/download_item.h"
14 #include "content/public/browser/web_contents.h"
15 #include "grit/theme_resources.h"
16 #include "ui/base/l10n/l10n_util.h"
17
18 namespace chrome {
19 namespace android {
20
21 DownloadOverwriteInfoBarDelegate::~DownloadOverwriteInfoBarDelegate() {
22 }
23
24 // static
25 infobars::InfoBar* DownloadOverwriteInfoBarDelegate::Create(
26 content::DownloadItem* download,
27 const base::FilePath& suggested_path,
28 const FileSelectedCallback& callback) {
29 DCHECK(download);
30 if (!download)
31 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
32 content::WebContents* web_contents = download->GetWebContents();
33 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
34 return NULL;
35
36 InfoBarService* infobar_service =
37 InfoBarService::FromWebContents(web_contents);
38
39 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.
40 new DownloadOverwriteInfoBarDelegate(download, suggested_path, callback);
41 infobars::InfoBar* infobar = DownloadOverwriteInfoBar::CreateInfoBar(
42 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.
43 return infobar_service->AddInfoBar(scoped_ptr<infobars::InfoBar>(infobar));
44 }
45
46 DownloadOverwriteInfoBarDelegate*
47 DownloadOverwriteInfoBarDelegate::AsDownloadOverwriteInfoBarDelegate() {
48 return this;
49 }
50
51 bool DownloadOverwriteInfoBarDelegate::Accept() {
52 callback_.Run(suggested_path_);
53 return true;
54 }
55
56 bool DownloadOverwriteInfoBarDelegate::Cancel() {
57 callback_.Run(base::FilePath());
58 return true;
59 }
60
61 DownloadOverwriteInfoBarDelegate::DownloadOverwriteInfoBarDelegate(
62 content::DownloadItem* download,
63 const base::FilePath& suggested_path,
64 const FileSelectedCallback& callback)
65 : pending_id_(download->GetId()),
66 suggested_path_(suggested_path),
67 callback_(callback) {
68 }
69
70 std::string DownloadOverwriteInfoBarDelegate::GetFileName() const {
71 return suggested_path_.BaseName().value();
72 }
73
74 std::string DownloadOverwriteInfoBarDelegate::GetDirName() const {
75 return suggested_path_.DirName().BaseName().value();
76 }
77
78 std::string DownloadOverwriteInfoBarDelegate::GetDirFullPath() const {
79 return suggested_path_.DirName().value();
80 }
81
82 } // namespace android
83 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698