blob: 47b3c804678105306a0251c995c953ec2e2dd5ee [file] [log] [blame]
[email protected]98d6f152011-09-29 19:35:511// Copyright (c) 2011 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 "content/shell/shell_download_manager_delegate.h"
6
7#include "base/bind.h"
8#include "base/file_util.h"
9#include "base/utf_string_conversions.h"
10#include "content/browser/browser_context.h"
11#include "content/browser/browser_thread.h"
12#include "content/browser/download/download_manager.h"
13#include "content/browser/download/download_state_info.h"
14#include "net/base/net_util.h"
15
16namespace content {
17
18ShellDownloadManagerDelegate::ShellDownloadManagerDelegate()
19 : download_manager_(NULL) {
20}
21
22ShellDownloadManagerDelegate::~ShellDownloadManagerDelegate(){
23}
24
25
26void ShellDownloadManagerDelegate::SetDownloadManager(
27 DownloadManager* download_manager) {
28 download_manager_ = download_manager;
29}
30
31void ShellDownloadManagerDelegate::Shutdown() {
32}
33
34bool ShellDownloadManagerDelegate::ShouldStartDownload(int32 download_id) {
35 DownloadItem* download =
36 download_manager_->GetActiveDownloadItem(download_id);
37 DownloadStateInfo state = download->state_info();
38
39 if (!state.force_file_name.empty())
40 return true;
41
42 FilePath generated_name = net::GenerateFileName(
43 download->GetURL(),
44 download->content_disposition(),
45 download->referrer_charset(),
46 download->suggested_filename(),
47 download->mime_type(),
48 string16(UTF8ToUTF16("download")));
49
50 BrowserThread::PostTask(
51 BrowserThread::FILE,
52 FROM_HERE,
53 base::Bind(
54 &ShellDownloadManagerDelegate::GenerateFilename,
55 this, download_id, state, generated_name));
56 return false;
57}
58
59void ShellDownloadManagerDelegate::GenerateFilename(
60 int32 download_id,
61 DownloadStateInfo state,
62 const FilePath& generated_name) {
63 if (state.suggested_path.empty()) {
64 state.suggested_path = download_manager_->browser_context()->GetPath().
65 Append(FILE_PATH_LITERAL("Downloads"));
66 if (!file_util::PathExists(state.suggested_path))
67 file_util::CreateDirectory(state.suggested_path);
68 }
69
70 state.suggested_path = state.suggested_path.Append(generated_name);
71
72 BrowserThread::PostTask(
73 BrowserThread::UI,
74 FROM_HERE,
75 base::Bind(
76 &ShellDownloadManagerDelegate::RestartDownload,
77 this, download_id, state));
78}
79
80void ShellDownloadManagerDelegate::RestartDownload(
81 int32 download_id,
82 DownloadStateInfo state) {
83 DownloadItem* download =
84 download_manager_->GetActiveDownloadItem(download_id);
85 if (!download)
86 return;
87 download->SetFileCheckResults(state);
88 download_manager_->RestartDownload(download_id);
89}
90
91void ShellDownloadManagerDelegate::ChooseDownloadPath(
92 TabContents* tab_contents,
93 const FilePath& suggested_path,
94 void* data) {
95}
96
97bool ShellDownloadManagerDelegate::OverrideIntermediatePath(
98 DownloadItem* item,
99 FilePath* intermediate_path) {
100 return false;
101}
102
103TabContents* ShellDownloadManagerDelegate::
104 GetAlternativeTabContentsToNotifyForDownload() {
105 return NULL;
106}
107
108bool ShellDownloadManagerDelegate::ShouldOpenFileBasedOnExtension(
109 const FilePath& path) {
110 return false;
111}
112
113bool ShellDownloadManagerDelegate::ShouldOpenDownload(DownloadItem* item) {
114 return true;
115}
116
117bool ShellDownloadManagerDelegate::ShouldCompleteDownload(DownloadItem* item) {
118 return true;
119}
120
121bool ShellDownloadManagerDelegate::GenerateFileHash() {
122 return false;
123}
124
125void ShellDownloadManagerDelegate::OnResponseCompleted(
126 DownloadItem* item,
127 const std::string& hash) {
128}
129
130void ShellDownloadManagerDelegate::AddItemToPersistentStore(
131 DownloadItem* item) {
132}
133
134void ShellDownloadManagerDelegate::UpdateItemInPersistentStore(
135 DownloadItem* item) {
136}
137
138void ShellDownloadManagerDelegate::UpdatePathForItemInPersistentStore(
139 DownloadItem* item,
140 const FilePath& new_path) {
141}
142
143void ShellDownloadManagerDelegate::RemoveItemFromPersistentStore(
144 DownloadItem* item) {
145}
146
147void ShellDownloadManagerDelegate::RemoveItemsFromPersistentStoreBetween(
148 const base::Time remove_begin,
149 const base::Time remove_end) {
150}
151
152void ShellDownloadManagerDelegate::GetSaveDir(
153 TabContents* tab_contents,
154 FilePath* website_save_dir,
155 FilePath* download_save_dir) {
156}
157
158void ShellDownloadManagerDelegate::ChooseSavePath(
159 const base::WeakPtr<SavePackage>& save_package,
160 const FilePath& suggested_path,
161 bool can_save_as_complete) {
162}
163
164void ShellDownloadManagerDelegate::DownloadProgressUpdated() {
165}
166
167} // namespace content