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

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

Issue 6995013: More progress towards removing content settings code from the content layer. We can't use Cookie... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: review comments and sync Created 9 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
« no previous file with comments | « chrome/browser/download/save_file_manager.h ('k') | chrome/browser/download/save_package.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/save_file.h" 15 #include "chrome/browser/download/save_file.h"
16 #include "chrome/browser/download/save_package.h" 16 #include "chrome/browser/download/save_package.h"
17 #include "chrome/browser/platform_util.h" 17 #include "chrome/browser/platform_util.h"
18 #include "chrome/browser/tab_contents/tab_util.h" 18 #include "chrome/browser/tab_contents/tab_util.h"
19 #include "chrome/browser/ui/download/download_tab_helper.h" 19 #include "chrome/browser/ui/download/download_tab_helper.h"
20 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 20 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
21 #include "chrome/common/chrome_paths.h" 21 #include "chrome/common/chrome_paths.h"
22 #include "content/browser/browser_thread.h" 22 #include "content/browser/browser_thread.h"
23 #include "content/browser/renderer_host/resource_dispatcher_host.h" 23 #include "content/browser/renderer_host/resource_dispatcher_host.h"
24 #include "content/browser/tab_contents/tab_contents.h" 24 #include "content/browser/tab_contents/tab_contents.h"
25 #include "googleurl/src/gurl.h" 25 #include "googleurl/src/gurl.h"
26 #include "net/base/net_util.h" 26 #include "net/base/net_util.h"
27 #include "net/base/io_buffer.h" 27 #include "net/base/io_buffer.h"
28 #include "net/url_request/url_request_context.h"
29 #include "net/url_request/url_request_context_getter.h"
30 28
31 SaveFileManager::SaveFileManager(ResourceDispatcherHost* rdh) 29 SaveFileManager::SaveFileManager(ResourceDispatcherHost* rdh)
32 : next_id_(0), 30 : next_id_(0),
33 resource_dispatcher_host_(rdh) { 31 resource_dispatcher_host_(rdh) {
34 DCHECK(resource_dispatcher_host_); 32 DCHECK(resource_dispatcher_host_);
35 } 33 }
36 34
37 SaveFileManager::~SaveFileManager() { 35 SaveFileManager::~SaveFileManager() {
38 // Check for clean shutdown. 36 // Check for clean shutdown.
39 DCHECK(save_file_map_.empty()); 37 DCHECK(save_file_map_.empty());
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 } 114 }
117 115
118 // Call from SavePackage for starting a saving job 116 // Call from SavePackage for starting a saving job
119 void SaveFileManager::SaveURL( 117 void SaveFileManager::SaveURL(
120 const GURL& url, 118 const GURL& url,
121 const GURL& referrer, 119 const GURL& referrer,
122 int render_process_host_id, 120 int render_process_host_id,
123 int render_view_id, 121 int render_view_id,
124 SaveFileCreateInfo::SaveFileSource save_source, 122 SaveFileCreateInfo::SaveFileSource save_source,
125 const FilePath& file_full_path, 123 const FilePath& file_full_path,
126 net::URLRequestContextGetter* request_context_getter, 124 const content::ResourceContext& context,
127 SavePackage* save_package) { 125 SavePackage* save_package) {
128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
129 127
130 // Register a saving job. 128 // Register a saving job.
131 RegisterStartingRequest(url, save_package); 129 RegisterStartingRequest(url, save_package);
132 if (save_source == SaveFileCreateInfo::SAVE_FILE_FROM_NET) { 130 if (save_source == SaveFileCreateInfo::SAVE_FILE_FROM_NET) {
133 DCHECK(url.is_valid()); 131 DCHECK(url.is_valid());
134 132
135 BrowserThread::PostTask( 133 BrowserThread::PostTask(
136 BrowserThread::IO, FROM_HERE, 134 BrowserThread::IO, FROM_HERE,
137 NewRunnableMethod(this, 135 NewRunnableMethod(this,
138 &SaveFileManager::OnSaveURL, 136 &SaveFileManager::OnSaveURL,
139 url, 137 url,
140 referrer, 138 referrer,
141 render_process_host_id, 139 render_process_host_id,
142 render_view_id, 140 render_view_id,
143 make_scoped_refptr(request_context_getter))); 141 &context));
144 } else { 142 } else {
145 // We manually start the save job. 143 // We manually start the save job.
146 SaveFileCreateInfo* info = new SaveFileCreateInfo(file_full_path, 144 SaveFileCreateInfo* info = new SaveFileCreateInfo(file_full_path,
147 url, 145 url,
148 save_source, 146 save_source,
149 -1); 147 -1);
150 info->render_process_id = render_process_host_id; 148 info->render_process_id = render_process_host_id;
151 info->render_view_id = render_view_id; 149 info->render_view_id = render_view_id;
152 150
153 // Since the data will come from render process, so we need to start 151 // Since the data will come from render process, so we need to start
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 save_package->SaveFailed(save_url); 355 save_package->SaveFailed(save_url);
358 } 356 }
359 357
360 // Notifications sent from the UI thread and run on the IO thread. 358 // Notifications sent from the UI thread and run on the IO thread.
361 359
362 void SaveFileManager::OnSaveURL( 360 void SaveFileManager::OnSaveURL(
363 const GURL& url, 361 const GURL& url,
364 const GURL& referrer, 362 const GURL& referrer,
365 int render_process_host_id, 363 int render_process_host_id,
366 int render_view_id, 364 int render_view_id,
367 net::URLRequestContextGetter* request_context_getter) { 365 const content::ResourceContext* context) {
368 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 366 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
369 net::URLRequestContext* context =
370 request_context_getter->GetURLRequestContext();
371 resource_dispatcher_host_->BeginSaveFile(url, 367 resource_dispatcher_host_->BeginSaveFile(url,
372 referrer, 368 referrer,
373 render_process_host_id, 369 render_process_host_id,
374 render_view_id, 370 render_view_id,
375 context); 371 *context);
376 } 372 }
377 373
378 void SaveFileManager::OnRequireSaveJobFromOtherSource( 374 void SaveFileManager::OnRequireSaveJobFromOtherSource(
379 SaveFileCreateInfo* info) { 375 SaveFileCreateInfo* info) {
380 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 376 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
381 DCHECK_EQ(info->save_id, -1); 377 DCHECK_EQ(info->save_id, -1);
382 // Generate a unique save id. 378 // Generate a unique save id.
383 info->save_id = GetNextId(); 379 info->save_id = GetNextId();
384 // Start real saving action. 380 // Start real saving action.
385 BrowserThread::PostTask( 381 BrowserThread::PostTask(
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 SaveFileMap::iterator it = save_file_map_.find(*i); 532 SaveFileMap::iterator it = save_file_map_.find(*i);
537 if (it != save_file_map_.end()) { 533 if (it != save_file_map_.end()) {
538 SaveFile* save_file = it->second; 534 SaveFile* save_file = it->second;
539 DCHECK(!save_file->in_progress()); 535 DCHECK(!save_file->in_progress());
540 file_util::Delete(save_file->full_path(), false); 536 file_util::Delete(save_file->full_path(), false);
541 delete save_file; 537 delete save_file;
542 save_file_map_.erase(it); 538 save_file_map_.erase(it);
543 } 539 }
544 } 540 }
545 } 541 }
OLDNEW
« no previous file with comments | « chrome/browser/download/save_file_manager.h ('k') | chrome/browser/download/save_package.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698