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

Side by Side Diff: chrome/browser/download/download_file_picker_chromeos.cc

Issue 14773004: Move download filename determination into a separate class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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/download/download_file_picker_chromeos.h"
6
7 #include "base/bind.h"
8 #include "base/i18n/file_util_icu.h"
9 #include "chrome/browser/chromeos/drive/download_handler.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "content/public/browser/download_item.h"
12 #include "content/public/browser/download_manager.h"
13 #include "ui/shell_dialogs/selected_file_info.h"
14
15 using content::DownloadItem;
16 using content::DownloadManager;
17
18 DownloadFilePickerChromeOS::DownloadFilePickerChromeOS() {
19 }
20
21 DownloadFilePickerChromeOS::~DownloadFilePickerChromeOS() {
22 }
23
24 void DownloadFilePickerChromeOS::InitSuggestedPath(DownloadItem* item,
25 const base::FilePath& path) {
26 // For Drive downloads, we should pass the drive path instead of the temporary
27 // file path.
28 Profile* profile =
29 Profile::FromBrowserContext(download_manager_->GetBrowserContext());
30 drive::DownloadHandler* drive_download_handler =
31 drive::DownloadHandler::GetForProfile(profile);
32 base::FilePath suggested_path = path;
33 if (drive_download_handler && drive_download_handler->IsDriveDownload(item))
34 suggested_path = drive_download_handler->GetTargetPath(item);
35
36 DownloadFilePicker::InitSuggestedPath(item, suggested_path);
37 }
38
39 void DownloadFilePickerChromeOS::FileSelected(
40 const base::FilePath& selected_path,
41 int index,
42 void* params) {
43 FileSelectedWithExtraInfo(
44 ui::SelectedFileInfo(selected_path, selected_path),
45 index,
46 params);
47 }
48
49 void DownloadFilePickerChromeOS::FileSelectedWithExtraInfo(
50 const ui::SelectedFileInfo& file_info,
51 int index,
52 void* params) {
53 base::FilePath path = file_info.file_path;
54 file_util::NormalizeFileNameEncoding(&path);
55
56 // Need to do this before we substitute with a temporary path. Otherwise we
57 // won't be able to detect path changes.
58 RecordFileSelected(path);
59
60 if (download_manager_) {
61 Profile* profile =
62 Profile::FromBrowserContext(download_manager_->GetBrowserContext());
63 drive::DownloadHandler* drive_download_handler =
64 drive::DownloadHandler::GetForProfile(profile);
65 if (drive_download_handler) {
66 DownloadItem* download = download_manager_->GetDownload(download_id_);
67 drive_download_handler->SubstituteDriveDownloadPath(
68 path, download,
69 base::Bind(&DownloadFilePickerChromeOS::OnFileSelected,
70 base::Unretained(this)));
71 } else {
72 OnFileSelected(path);
73 }
74 } else {
75 OnFileSelected(base::FilePath());
76 }
77 // The OnFileSelected() call deletes |this|
78 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698