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

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

Issue 2032283002: Remove refcounting from SavePackage. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 335
336 // Check save type and process the save page job. 336 // Check save type and process the save page job.
337 if (save_type_ == SAVE_PAGE_TYPE_AS_COMPLETE_HTML) { 337 if (save_type_ == SAVE_PAGE_TYPE_AS_COMPLETE_HTML) {
338 // Get directory 338 // Get directory
339 DCHECK(!saved_main_directory_path_.empty()); 339 DCHECK(!saved_main_directory_path_.empty());
340 GetSavableResourceLinks(); 340 GetSavableResourceLinks();
341 } else if (save_type_ == SAVE_PAGE_TYPE_AS_MHTML) { 341 } else if (save_type_ == SAVE_PAGE_TYPE_AS_MHTML) {
342 MHTMLGenerationParams mhtml_generation_params(saved_main_file_path_); 342 MHTMLGenerationParams mhtml_generation_params(saved_main_file_path_);
343 web_contents()->GenerateMHTML( 343 web_contents()->GenerateMHTML(
344 mhtml_generation_params, 344 mhtml_generation_params,
345 base::Bind(&SavePackage::OnMHTMLGenerated, this)); 345 base::Bind(&SavePackage::OnMHTMLGenerated, Unretained(this)));
346 } else { 346 } else {
347 DCHECK_EQ(SAVE_PAGE_TYPE_AS_ONLY_HTML, save_type_); 347 DCHECK_EQ(SAVE_PAGE_TYPE_AS_ONLY_HTML, save_type_);
348 wait_state_ = NET_FILES; 348 wait_state_ = NET_FILES;
349 SaveFileCreateInfo::SaveFileSource save_source = page_url_.SchemeIsFile() ? 349 SaveFileCreateInfo::SaveFileSource save_source = page_url_.SchemeIsFile() ?
350 SaveFileCreateInfo::SAVE_FILE_FROM_FILE : 350 SaveFileCreateInfo::SAVE_FILE_FROM_FILE :
351 SaveFileCreateInfo::SAVE_FILE_FROM_NET; 351 SaveFileCreateInfo::SAVE_FILE_FROM_NET;
352 // Add this item to waiting list. 352 // Add this item to waiting list.
353 waiting_item_queue_.push_back( 353 waiting_item_queue_.push_back(
354 new SaveItem(page_url_, Referrer(), this, save_source, 354 new SaveItem(page_url_, Referrer(), this, save_source,
355 FrameTreeNode::kFrameTreeNodeInvalidId)); 355 FrameTreeNode::kFrameTreeNodeInvalidId));
(...skipping 20 matching lines...) Expand all
376 // ShouldCompleteDownload() may depend on the gdata uploader to finish. 376 // ShouldCompleteDownload() may depend on the gdata uploader to finish.
377 download_->OnAllDataSaved(size, std::unique_ptr<crypto::SecureHash>()); 377 download_->OnAllDataSaved(size, std::unique_ptr<crypto::SecureHash>());
378 } 378 }
379 379
380 if (!download_manager_->GetDelegate()) { 380 if (!download_manager_->GetDelegate()) {
381 Finish(); 381 Finish();
382 return; 382 return;
383 } 383 }
384 384
385 if (download_manager_->GetDelegate()->ShouldCompleteDownload( 385 if (download_manager_->GetDelegate()->ShouldCompleteDownload(
386 download_, base::Bind(&SavePackage::Finish, this))) { 386 download_,
387 base::Bind(&SavePackage::Finish, base::Unretained(this)))) {
387 Finish(); 388 Finish();
388 } 389 }
389 } 390 }
390 391
391 // On POSIX, the length of |pure_file_name| + |file_name_ext| is further 392 // On POSIX, the length of |pure_file_name| + |file_name_ext| is further
392 // restricted by NAME_MAX. The maximum allowed path looks like: 393 // restricted by NAME_MAX. The maximum allowed path looks like:
393 // '/path/to/save_dir' + '/' + NAME_MAX. 394 // '/path/to/save_dir' + '/' + NAME_MAX.
394 uint32_t SavePackage::GetMaxPathLengthForDirectory( 395 uint32_t SavePackage::GetMaxPathLengthForDirectory(
395 const base::FilePath& base_dir) { 396 const base::FilePath& base_dir) {
396 #if defined(OS_POSIX) 397 #if defined(OS_POSIX)
(...skipping 978 matching lines...) Expand 10 before | Expand all | Expand 10 after
1375 bool skip_dir_check = false; 1376 bool skip_dir_check = false;
1376 auto* delegate = download_manager_->GetDelegate(); 1377 auto* delegate = download_manager_->GetDelegate();
1377 if (delegate) { 1378 if (delegate) {
1378 delegate->GetSaveDir( 1379 delegate->GetSaveDir(
1379 web_contents()->GetBrowserContext(), &website_save_dir, 1380 web_contents()->GetBrowserContext(), &website_save_dir,
1380 &download_save_dir, &skip_dir_check); 1381 &download_save_dir, &skip_dir_check);
1381 } 1382 }
1382 std::string mime_type = web_contents()->GetContentsMimeType(); 1383 std::string mime_type = web_contents()->GetContentsMimeType();
1383 BrowserThread::PostTask( 1384 BrowserThread::PostTask(
1384 BrowserThread::FILE, FROM_HERE, 1385 BrowserThread::FILE, FROM_HERE,
1385 base::Bind(&SavePackage::CreateDirectoryOnFileThread, this, 1386 base::Bind(&SavePackage::CreateDirectoryOnFileThread,
1386 website_save_dir, download_save_dir, skip_dir_check, mime_type)); 1387 base::Unretained(this), website_save_dir, download_save_dir,
1388 skip_dir_check, mime_type));
1387 } 1389 }
1388 1390
1389 void SavePackage::CreateDirectoryOnFileThread( 1391 void SavePackage::CreateDirectoryOnFileThread(
1390 const base::FilePath& website_save_dir, 1392 const base::FilePath& website_save_dir,
1391 const base::FilePath& download_save_dir, 1393 const base::FilePath& download_save_dir,
1392 bool skip_dir_check, 1394 bool skip_dir_check,
1393 const std::string& mime_type) { 1395 const std::string& mime_type) {
1394 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 1396 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
1395 1397
1396 base::FilePath save_dir; 1398 base::FilePath save_dir;
(...skipping 26 matching lines...) Expand all
1423 } else { 1425 } else {
1424 // Cannot create a shorter filename. This will cause the save as operation 1426 // Cannot create a shorter filename. This will cause the save as operation
1425 // to fail unless the user pick a shorter name. Continuing even though it 1427 // to fail unless the user pick a shorter name. Continuing even though it
1426 // will fail because returning means no save as popup for the user, which 1428 // will fail because returning means no save as popup for the user, which
1427 // is even more confusing. This case should be rare though. 1429 // is even more confusing. This case should be rare though.
1428 save_dir = save_dir.Append(suggested_filename); 1430 save_dir = save_dir.Append(suggested_filename);
1429 } 1431 }
1430 1432
1431 BrowserThread::PostTask( 1433 BrowserThread::PostTask(
1432 BrowserThread::UI, FROM_HERE, 1434 BrowserThread::UI, FROM_HERE,
1433 base::Bind(&SavePackage::ContinueGetSaveInfo, this, save_dir, 1435 base::Bind(&SavePackage::ContinueGetSaveInfo, base::Unretained(this),
1434 can_save_as_complete)); 1436 save_dir, can_save_as_complete));
1435 } 1437 }
1436 1438
1437 void SavePackage::ContinueGetSaveInfo(const base::FilePath& suggested_path, 1439 void SavePackage::ContinueGetSaveInfo(const base::FilePath& suggested_path,
1438 bool can_save_as_complete) { 1440 bool can_save_as_complete) {
1439 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1441 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1440 1442
1441 // The WebContents which owns this SavePackage may have disappeared during 1443 // The WebContents which owns this SavePackage may have disappeared during
1442 // the UI->FILE->UI thread hop of 1444 // the UI->FILE->UI thread hop of
1443 // GetSaveInfo->CreateDirectoryOnFileThread->ContinueGetSaveInfo. 1445 // GetSaveInfo->CreateDirectoryOnFileThread->ContinueGetSaveInfo.
1444 if (!web_contents() || !download_manager_->GetDelegate()) 1446 if (!web_contents() || !download_manager_->GetDelegate())
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1496 } 1498 }
1497 1499
1498 void SavePackage::FinalizeDownloadEntry() { 1500 void SavePackage::FinalizeDownloadEntry() {
1499 DCHECK(download_); 1501 DCHECK(download_);
1500 1502
1501 download_manager_->OnSavePackageSuccessfullyFinished(download_); 1503 download_manager_->OnSavePackageSuccessfullyFinished(download_);
1502 StopObservation(); 1504 StopObservation();
1503 } 1505 }
1504 1506
1505 } // namespace content 1507 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698