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

Side by Side Diff: content/browser/download/save_package.cc

Issue 8503018: Split DownloadItem into an ABC, an Impl, and a Mock. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: merge Created 9 years, 1 month 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 "content/browser/download/save_package.h" 5 #include "content/browser/download/save_package.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/i18n/file_util_icu.h" 12 #include "base/i18n/file_util_icu.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/message_loop.h" 14 #include "base/message_loop.h"
15 #include "base/stl_util.h" 15 #include "base/stl_util.h"
16 #include "base/string_piece.h" 16 #include "base/string_piece.h"
17 #include "base/string_split.h" 17 #include "base/string_split.h"
18 #include "base/sys_string_conversions.h" 18 #include "base/sys_string_conversions.h"
19 #include "base/threading/thread.h" 19 #include "base/threading/thread.h"
20 #include "base/utf_string_conversions.h" 20 #include "base/utf_string_conversions.h"
21 #include "content/browser/browser_context.h" 21 #include "content/browser/browser_context.h"
22 #include "content/browser/download/download_file_manager.h" 22 #include "content/browser/download/download_file_manager.h"
23 #include "content/browser/download/download_item.h" 23 #include "content/browser/download/download_item_impl.h"
24 #include "content/browser/download/download_manager.h" 24 #include "content/browser/download/download_manager.h"
25 #include "content/browser/download/save_file.h" 25 #include "content/browser/download/save_file.h"
26 #include "content/browser/download/save_file_manager.h" 26 #include "content/browser/download/save_file_manager.h"
27 #include "content/browser/download/save_item.h" 27 #include "content/browser/download/save_item.h"
28 #include "content/browser/renderer_host/render_process_host_impl.h" 28 #include "content/browser/renderer_host/render_process_host_impl.h"
29 #include "content/browser/renderer_host/render_view_host.h" 29 #include "content/browser/renderer_host/render_view_host.h"
30 #include "content/browser/renderer_host/render_view_host_delegate.h" 30 #include "content/browser/renderer_host/render_view_host_delegate.h"
31 #include "content/browser/renderer_host/resource_dispatcher_host.h" 31 #include "content/browser/renderer_host/resource_dispatcher_host.h"
32 #include "content/browser/resource_context.h" 32 #include "content/browser/resource_context.h"
33 #include "content/browser/tab_contents/tab_contents.h" 33 #include "content/browser/tab_contents/tab_contents.h"
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 wait_state_ = START_PROCESS; 259 wait_state_ = START_PROCESS;
260 260
261 // Initialize the request context and resource dispatcher. 261 // Initialize the request context and resource dispatcher.
262 content::BrowserContext* browser_context = tab_contents()->browser_context(); 262 content::BrowserContext* browser_context = tab_contents()->browser_context();
263 if (!browser_context) { 263 if (!browser_context) {
264 NOTREACHED(); 264 NOTREACHED();
265 return false; 265 return false;
266 } 266 }
267 267
268 // Create the download item, and add ourself as an observer. 268 // Create the download item, and add ourself as an observer.
269 download_ = new DownloadItem(download_manager_, 269 download_ = new DownloadItemImpl(download_manager_,
270 saved_main_file_path_, 270 saved_main_file_path_,
271 page_url_, 271 page_url_,
272 browser_context->IsOffTheRecord(), 272 browser_context->IsOffTheRecord(),
273 download_manager_->GetNextId()); 273 download_manager_->GetNextId());
274 download_->AddObserver(this); 274 download_->AddObserver(this);
275 275
276 // Transfer ownership to the download manager. 276 // Transfer ownership to the download manager.
277 download_manager_->SavePageDownloadStarted(download_); 277 download_manager_->SavePageDownloadStarted(download_);
278 278
279 // Check save type and process the save page job. 279 // Check save type and process the save page job.
280 if (save_type_ == SAVE_AS_COMPLETE_HTML) { 280 if (save_type_ == SAVE_AS_COMPLETE_HTML) {
281 // Get directory 281 // Get directory
282 DCHECK(!saved_main_directory_path_.empty()); 282 DCHECK(!saved_main_directory_path_.empty());
283 GetAllSavableResourceLinksForCurrentPage(); 283 GetAllSavableResourceLinksForCurrentPage();
284 } else { 284 } else {
285 wait_state_ = NET_FILES; 285 wait_state_ = NET_FILES;
286 SaveFileCreateInfo::SaveFileSource save_source = page_url_.SchemeIsFile() ? 286 SaveFileCreateInfo::SaveFileSource save_source = page_url_.SchemeIsFile() ?
287 SaveFileCreateInfo::SAVE_FILE_FROM_FILE : 287 SaveFileCreateInfo::SAVE_FILE_FROM_FILE :
288 SaveFileCreateInfo::SAVE_FILE_FROM_NET; 288 SaveFileCreateInfo::SAVE_FILE_FROM_NET;
289 SaveItem* save_item = new SaveItem(page_url_, 289 SaveItem* save_item = new SaveItem(page_url_,
290 GURL(), 290 GURL(),
291 this, 291 this,
292 save_source); 292 save_source);
293 // Add this item to waiting list. 293 // Add this item to waiting list.
294 waiting_item_queue_.push(save_item); 294 waiting_item_queue_.push(save_item);
295 all_save_items_count_ = 1; 295 all_save_items_count_ = 1;
296 download_->set_total_bytes(1); 296 download_->SetTotalBytes(1);
297 297
298 DoSavingProcess(); 298 DoSavingProcess();
299 } 299 }
300 300
301 return true; 301 return true;
302 } 302 }
303 303
304 // On POSIX, the length of |pure_file_name| + |file_name_ext| is further 304 // On POSIX, the length of |pure_file_name| + |file_name_ext| is further
305 // restricted by NAME_MAX. The maximum allowed path looks like: 305 // restricted by NAME_MAX. The maximum allowed path looks like:
306 // '/path/to/save_dir' + '/' + NAME_MAX. 306 // '/path/to/save_dir' + '/' + NAME_MAX.
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 const std::vector<GURL>& frames_list) { 1007 const std::vector<GURL>& frames_list) {
1008 if (wait_state_ != RESOURCES_LIST) 1008 if (wait_state_ != RESOURCES_LIST)
1009 return; 1009 return;
1010 1010
1011 DCHECK(resources_list.size() == referrers_list.size()); 1011 DCHECK(resources_list.size() == referrers_list.size());
1012 all_save_items_count_ = static_cast<int>(resources_list.size()) + 1012 all_save_items_count_ = static_cast<int>(resources_list.size()) +
1013 static_cast<int>(frames_list.size()); 1013 static_cast<int>(frames_list.size());
1014 1014
1015 // We use total bytes as the total number of files we want to save. 1015 // We use total bytes as the total number of files we want to save.
1016 if (download_) 1016 if (download_)
1017 download_->set_total_bytes(all_save_items_count_); 1017 download_->SetTotalBytes(all_save_items_count_);
1018 1018
1019 if (all_save_items_count_) { 1019 if (all_save_items_count_) {
1020 // Put all sub-resources to wait list. 1020 // Put all sub-resources to wait list.
1021 for (int i = 0; i < static_cast<int>(resources_list.size()); ++i) { 1021 for (int i = 0; i < static_cast<int>(resources_list.size()); ++i) {
1022 const GURL& u = resources_list[i]; 1022 const GURL& u = resources_list[i];
1023 DCHECK(u.is_valid()); 1023 DCHECK(u.is_valid());
1024 SaveFileCreateInfo::SaveFileSource save_source = u.SchemeIsFile() ? 1024 SaveFileCreateInfo::SaveFileSource save_source = u.SchemeIsFile() ?
1025 SaveFileCreateInfo::SAVE_FILE_FROM_FILE : 1025 SaveFileCreateInfo::SAVE_FILE_FROM_FILE :
1026 SaveFileCreateInfo::SAVE_FILE_FROM_NET; 1026 SaveFileCreateInfo::SAVE_FILE_FROM_NET;
1027 SaveItem* save_item = new SaveItem(u, referrers_list[i], 1027 SaveItem* save_item = new SaveItem(u, referrers_list[i],
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
1270 download_ = NULL; 1270 download_ = NULL;
1271 download_manager_ = NULL; 1271 download_manager_ = NULL;
1272 } 1272 }
1273 1273
1274 void SavePackage::OnDownloadUpdated(DownloadItem* download) { 1274 void SavePackage::OnDownloadUpdated(DownloadItem* download) {
1275 DCHECK(download_); 1275 DCHECK(download_);
1276 DCHECK(download_ == download); 1276 DCHECK(download_ == download);
1277 DCHECK(download_manager_); 1277 DCHECK(download_manager_);
1278 1278
1279 // Check for removal. 1279 // Check for removal.
1280 if (download->state() == DownloadItem::REMOVING) 1280 if (download->GetState() == DownloadItem::REMOVING)
1281 StopObservation(); 1281 StopObservation();
1282 } 1282 }
1283 1283
1284 void SavePackage::FinalizeDownloadEntry() { 1284 void SavePackage::FinalizeDownloadEntry() {
1285 DCHECK(download_); 1285 DCHECK(download_);
1286 DCHECK(download_manager_); 1286 DCHECK(download_manager_);
1287 1287
1288 download_manager_->SavePageDownloadFinished(download_); 1288 download_manager_->SavePageDownloadFinished(download_);
1289 StopObservation(); 1289 StopObservation();
1290 } 1290 }
OLDNEW
« no previous file with comments | « content/browser/download/mock_download_manager_delegate.cc ('k') | content/content_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698