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

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

Issue 6973052: When the download folder does not exist, change the download folder to a user's "Downloads" (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Overrides the user's "Downloads" folder in DownloadPrefs Created 9 years, 6 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "chrome/browser/download/save_file_manager.h" 7 #include "chrome/browser/download/save_file_manager.h"
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/stl_util-inl.h" 11 #include "base/stl_util-inl.h"
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "base/task.h" 13 #include "base/task.h"
14 #include "base/threading/thread.h" 14 #include "base/threading/thread.h"
15 #include "chrome/browser/download/download_manager.h"
16 #include "chrome/browser/download/download_prefs.h"
15 #include "chrome/browser/download/save_file.h" 17 #include "chrome/browser/download/save_file.h"
16 #include "chrome/browser/download/save_package.h" 18 #include "chrome/browser/download/save_package.h"
17 #include "chrome/browser/platform_util.h" 19 #include "chrome/browser/platform_util.h"
20 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/tab_contents/tab_util.h" 21 #include "chrome/browser/tab_contents/tab_util.h"
19 #include "chrome/browser/ui/download/download_tab_helper.h" 22 #include "chrome/browser/ui/download/download_tab_helper.h"
20 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 23 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
21 #include "chrome/common/chrome_paths.h" 24 #include "chrome/common/chrome_paths.h"
22 #include "content/browser/browser_thread.h" 25 #include "content/browser/browser_thread.h"
23 #include "content/browser/renderer_host/resource_dispatcher_host.h" 26 #include "content/browser/renderer_host/resource_dispatcher_host.h"
24 #include "content/browser/tab_contents/tab_contents.h" 27 #include "content/browser/tab_contents/tab_contents.h"
25 #include "googleurl/src/gurl.h" 28 #include "googleurl/src/gurl.h"
26 #include "net/base/net_util.h" 29 #include "net/base/net_util.h"
27 #include "net/base/io_buffer.h" 30 #include "net/base/io_buffer.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 const GURL& url, 121 const GURL& url,
119 const GURL& referrer, 122 const GURL& referrer,
120 int render_process_host_id, 123 int render_process_host_id,
121 int render_view_id, 124 int render_view_id,
122 SaveFileCreateInfo::SaveFileSource save_source, 125 SaveFileCreateInfo::SaveFileSource save_source,
123 const FilePath& file_full_path, 126 const FilePath& file_full_path,
124 const content::ResourceContext& context, 127 const content::ResourceContext& context,
125 SavePackage* save_package) { 128 SavePackage* save_package) {
126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
127 130
131 TabContents* contents =
132 tab_util::GetTabContentsByID(render_process_host_id, render_view_id);
133 DownloadPrefs* download_prefs =
134 contents->profile()->GetDownloadManager()->download_prefs();
135 FilePath default_download_dir = download_prefs->GetDefaultDownloadDirectory();
136
128 // Register a saving job. 137 // Register a saving job.
129 RegisterStartingRequest(url, save_package); 138 RegisterStartingRequest(url, save_package);
130 if (save_source == SaveFileCreateInfo::SAVE_FILE_FROM_NET) { 139 if (save_source == SaveFileCreateInfo::SAVE_FILE_FROM_NET) {
131 DCHECK(url.is_valid()); 140 DCHECK(url.is_valid());
132 141
133 BrowserThread::PostTask( 142 BrowserThread::PostTask(
134 BrowserThread::IO, FROM_HERE, 143 BrowserThread::IO, FROM_HERE,
135 NewRunnableMethod(this, 144 NewRunnableMethod(this,
136 &SaveFileManager::OnSaveURL, 145 &SaveFileManager::OnSaveURL,
137 url, 146 url,
138 referrer, 147 referrer,
139 render_process_host_id, 148 render_process_host_id,
140 render_view_id, 149 render_view_id,
150 default_download_dir,
141 &context)); 151 &context));
142 } else { 152 } else {
143 // We manually start the save job. 153 // We manually start the save job.
144 SaveFileCreateInfo* info = new SaveFileCreateInfo(file_full_path, 154 SaveFileCreateInfo* info = new SaveFileCreateInfo(file_full_path,
145 url, 155 url,
146 save_source, 156 save_source,
147 -1); 157 -1);
148 info->render_process_id = render_process_host_id; 158 info->render_process_id = render_process_host_id;
149 info->render_view_id = render_view_id; 159 info->render_view_id = render_view_id;
150 160
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 228
219 // The IO thread created |info|, but the file thread (this method) uses it 229 // The IO thread created |info|, but the file thread (this method) uses it
220 // to create a SaveFile which will hold and finally destroy |info|. It will 230 // to create a SaveFile which will hold and finally destroy |info|. It will
221 // then passes |info| to the UI thread for reporting saving status. 231 // then passes |info| to the UI thread for reporting saving status.
222 void SaveFileManager::StartSave(SaveFileCreateInfo* info) { 232 void SaveFileManager::StartSave(SaveFileCreateInfo* info) {
223 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
224 DCHECK(info); 234 DCHECK(info);
225 SaveFile* save_file = new SaveFile(info); 235 SaveFile* save_file = new SaveFile(info);
226 236
227 // TODO(phajdan.jr): We should check the return value and handle errors here. 237 // TODO(phajdan.jr): We should check the return value and handle errors here.
228 save_file->Initialize(false); // No need to calculate hash. 238 // No need to calculate hash.
239 save_file->Initialize(false, info->default_download_dir);
229 240
230 DCHECK(!LookupSaveFile(info->save_id)); 241 DCHECK(!LookupSaveFile(info->save_id));
231 save_file_map_[info->save_id] = save_file; 242 save_file_map_[info->save_id] = save_file;
232 info->path = save_file->full_path(); 243 info->path = save_file->full_path();
233 244
234 BrowserThread::PostTask( 245 BrowserThread::PostTask(
235 BrowserThread::UI, FROM_HERE, 246 BrowserThread::UI, FROM_HERE,
236 NewRunnableMethod(this, &SaveFileManager::OnStartSave, info)); 247 NewRunnableMethod(this, &SaveFileManager::OnStartSave, info));
237 } 248 }
238 249
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 save_package->SaveFailed(save_url); 366 save_package->SaveFailed(save_url);
356 } 367 }
357 368
358 // Notifications sent from the UI thread and run on the IO thread. 369 // Notifications sent from the UI thread and run on the IO thread.
359 370
360 void SaveFileManager::OnSaveURL( 371 void SaveFileManager::OnSaveURL(
361 const GURL& url, 372 const GURL& url,
362 const GURL& referrer, 373 const GURL& referrer,
363 int render_process_host_id, 374 int render_process_host_id,
364 int render_view_id, 375 int render_view_id,
376 const FilePath& default_download_dir,
365 const content::ResourceContext* context) { 377 const content::ResourceContext* context) {
366 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 378 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
367 resource_dispatcher_host_->BeginSaveFile(url, 379 resource_dispatcher_host_->BeginSaveFile(url,
368 referrer, 380 referrer,
369 render_process_host_id, 381 render_process_host_id,
370 render_view_id, 382 render_view_id,
383 default_download_dir,
371 *context); 384 *context);
372 } 385 }
373 386
374 void SaveFileManager::OnRequireSaveJobFromOtherSource( 387 void SaveFileManager::OnRequireSaveJobFromOtherSource(
375 SaveFileCreateInfo* info) { 388 SaveFileCreateInfo* info) {
376 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 389 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
377 DCHECK_EQ(info->save_id, -1); 390 DCHECK_EQ(info->save_id, -1);
378 // Generate a unique save id. 391 // Generate a unique save id.
379 info->save_id = GetNextId(); 392 info->save_id = GetNextId();
380 // Start real saving action. 393 // Start real saving action.
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 SaveFileMap::iterator it = save_file_map_.find(*i); 545 SaveFileMap::iterator it = save_file_map_.find(*i);
533 if (it != save_file_map_.end()) { 546 if (it != save_file_map_.end()) {
534 SaveFile* save_file = it->second; 547 SaveFile* save_file = it->second;
535 DCHECK(!save_file->in_progress()); 548 DCHECK(!save_file->in_progress());
536 file_util::Delete(save_file->full_path(), false); 549 file_util::Delete(save_file->full_path(), false);
537 delete save_file; 550 delete save_file;
538 save_file_map_.erase(it); 551 save_file_map_.erase(it);
539 } 552 }
540 } 553 }
541 } 554 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698