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

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

Issue 2435863004: Remove stl_util's deletion function use from content/. (Closed)
Patch Set: minus service worker Created 4 years, 2 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"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/i18n/file_util_icu.h" 13 #include "base/i18n/file_util_icu.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/ptr_util.h"
16 #include "base/message_loop/message_loop.h" 17 #include "base/message_loop/message_loop.h"
17 #include "base/stl_util.h" 18 #include "base/stl_util.h"
18 #include "base/strings/string_piece.h" 19 #include "base/strings/string_piece.h"
19 #include "base/strings/string_split.h" 20 #include "base/strings/string_split.h"
20 #include "base/strings/sys_string_conversions.h" 21 #include "base/strings/sys_string_conversions.h"
21 #include "base/strings/utf_string_conversions.h" 22 #include "base/strings/utf_string_conversions.h"
22 #include "base/threading/thread.h" 23 #include "base/threading/thread.h"
23 #include "build/build_config.h" 24 #include "build/build_config.h"
24 #include "components/url_formatter/url_formatter.h" 25 #include "components/url_formatter/url_formatter.h"
25 #include "content/browser/bad_message.h" 26 #include "content/browser/bad_message.h"
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 Cancel(true); 186 Cancel(true);
186 } 187 }
187 188
188 // We should no longer be observing the DownloadItem at this point. 189 // We should no longer be observing the DownloadItem at this point.
189 CHECK(!download_); 190 CHECK(!download_);
190 191
191 DCHECK_EQ(all_save_items_count_, waiting_item_queue_.size() + 192 DCHECK_EQ(all_save_items_count_, waiting_item_queue_.size() +
192 completed_count() + in_process_count()); 193 completed_count() + in_process_count());
193 194
194 // Free all SaveItems. 195 // Free all SaveItems.
195 base::STLDeleteElements(&waiting_item_queue_); 196 waiting_item_queue_.clear();
196 base::STLDeleteValues(&in_progress_items_); 197 in_progress_items_.clear();
197 base::STLDeleteValues(&saved_success_items_); 198 saved_success_items_.clear();
198 base::STLDeleteValues(&saved_failed_items_); 199 saved_failed_items_.clear();
199 // Clear containers that contain (now dangling/invalid) pointers to the 200 // Clear containers that contain (now dangling/invalid) pointers to the
200 // save items freed above. This is not strictly required (as the containers 201 // save items freed above. This is not strictly required (as the containers
201 // will be destructed soon by ~SavePackage), but seems like good code hygiene. 202 // will be destructed soon by ~SavePackage), but seems like good code hygiene.
202 frame_tree_node_id_to_contained_save_items_.clear(); 203 frame_tree_node_id_to_contained_save_items_.clear();
203 frame_tree_node_id_to_save_item_.clear(); 204 frame_tree_node_id_to_save_item_.clear();
204 url_to_save_item_.clear(); 205 url_to_save_item_.clear();
205 206
206 file_manager_ = nullptr; 207 file_manager_ = nullptr;
207 } 208 }
208 209
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 GetSavableResourceLinks(); 295 GetSavableResourceLinks();
295 } else if (save_type_ == SAVE_PAGE_TYPE_AS_MHTML) { 296 } else if (save_type_ == SAVE_PAGE_TYPE_AS_MHTML) {
296 MHTMLGenerationParams mhtml_generation_params(saved_main_file_path_); 297 MHTMLGenerationParams mhtml_generation_params(saved_main_file_path_);
297 web_contents()->GenerateMHTML( 298 web_contents()->GenerateMHTML(
298 mhtml_generation_params, 299 mhtml_generation_params,
299 base::Bind(&SavePackage::OnMHTMLGenerated, this)); 300 base::Bind(&SavePackage::OnMHTMLGenerated, this));
300 } else { 301 } else {
301 DCHECK_EQ(SAVE_PAGE_TYPE_AS_ONLY_HTML, save_type_); 302 DCHECK_EQ(SAVE_PAGE_TYPE_AS_ONLY_HTML, save_type_);
302 wait_state_ = NET_FILES; 303 wait_state_ = NET_FILES;
303 // Add this item to waiting list. 304 // Add this item to waiting list.
304 waiting_item_queue_.push_back(new SaveItem( 305 waiting_item_queue_.push_back(base::WrapUnique(new SaveItem(
305 page_url_, Referrer(), this, SaveFileCreateInfo::SAVE_FILE_FROM_NET, 306 page_url_, Referrer(), this, SaveFileCreateInfo::SAVE_FILE_FROM_NET,
306 FrameTreeNode::kFrameTreeNodeInvalidId, 307 FrameTreeNode::kFrameTreeNodeInvalidId,
307 web_contents()->GetMainFrame()->GetFrameTreeNodeId())); 308 web_contents()->GetMainFrame()->GetFrameTreeNodeId())));
308 all_save_items_count_ = 1; 309 all_save_items_count_ = 1;
309 download_->SetTotalBytes(1); 310 download_->SetTotalBytes(1);
310 311
311 DoSavingProcess(); 312 DoSavingProcess();
312 } 313 }
313 } 314 }
314 315
315 void SavePackage::OnMHTMLGenerated(int64_t size) { 316 void SavePackage::OnMHTMLGenerated(int64_t size) {
316 DCHECK_CURRENTLY_ON(BrowserThread::UI); 317 DCHECK_CURRENTLY_ON(BrowserThread::UI);
317 if (size <= 0) { 318 if (size <= 0) {
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 482
482 return true; 483 return true;
483 } 484 }
484 485
485 // We have received a message from SaveFileManager about a new saving job. We 486 // We have received a message from SaveFileManager about a new saving job. We
486 // find a SaveItem and store it in our in_progress list. 487 // find a SaveItem and store it in our in_progress list.
487 void SavePackage::StartSave(const SaveFileCreateInfo* info) { 488 void SavePackage::StartSave(const SaveFileCreateInfo* info) {
488 DCHECK_CURRENTLY_ON(BrowserThread::UI); 489 DCHECK_CURRENTLY_ON(BrowserThread::UI);
489 DCHECK(info); 490 DCHECK(info);
490 491
491 SaveItemIdMap::iterator it = in_progress_items_.find(info->save_item_id); 492 auto it = in_progress_items_.find(info->save_item_id);
492 if (it == in_progress_items_.end()) { 493 if (it == in_progress_items_.end()) {
493 // If not found, we must have cancel action. 494 // If not found, we must have cancel action.
494 DCHECK(canceled()); 495 DCHECK(canceled());
495 return; 496 return;
496 } 497 }
497 SaveItem* save_item = it->second; 498 SaveItem* save_item = it->second.get();
498 499
499 DCHECK(!saved_main_file_path_.empty()); 500 DCHECK(!saved_main_file_path_.empty());
500 501
501 save_item->SetTotalBytes(info->total_bytes); 502 save_item->SetTotalBytes(info->total_bytes);
502 503
503 // Determine the proper path for a saving job, by choosing either the default 504 // Determine the proper path for a saving job, by choosing either the default
504 // save directory, or prompting the user. 505 // save directory, or prompting the user.
505 DCHECK(!save_item->has_final_name()); 506 DCHECK(!save_item->has_final_name());
506 if (info->url != page_url_) { 507 if (info->url != page_url_) {
507 base::FilePath::StringType generated_name; 508 base::FilePath::StringType generated_name;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 // Inform backend to serialize the all frames' DOM and send serialized 550 // Inform backend to serialize the all frames' DOM and send serialized
550 // HTML data back. 551 // HTML data back.
551 GetSerializedHtmlWithLocalLinks(); 552 GetSerializedHtmlWithLocalLinks();
552 } 553 }
553 } 554 }
554 555
555 SaveItem* SavePackage::LookupInProgressSaveItem(SaveItemId save_item_id) { 556 SaveItem* SavePackage::LookupInProgressSaveItem(SaveItemId save_item_id) {
556 DCHECK_CURRENTLY_ON(BrowserThread::UI); 557 DCHECK_CURRENTLY_ON(BrowserThread::UI);
557 auto it = in_progress_items_.find(save_item_id); 558 auto it = in_progress_items_.find(save_item_id);
558 if (it != in_progress_items_.end()) { 559 if (it != in_progress_items_.end()) {
559 SaveItem* save_item = it->second; 560 SaveItem* save_item = it->second.get();
560 DCHECK_EQ(SaveItem::IN_PROGRESS, save_item->state()); 561 DCHECK_EQ(SaveItem::IN_PROGRESS, save_item->state());
561 return save_item; 562 return save_item;
562 } 563 }
563 return nullptr; 564 return nullptr;
564 } 565 }
565 566
566 void SavePackage::PutInProgressItemToSavedMap(SaveItem* save_item) { 567 void SavePackage::PutInProgressItemToSavedMap(SaveItem* save_item) {
567 DCHECK_CURRENTLY_ON(BrowserThread::UI); 568 DCHECK_CURRENTLY_ON(BrowserThread::UI);
568 SaveItemIdMap::iterator it = in_progress_items_.find(save_item->id()); 569 auto it = in_progress_items_.find(save_item->id());
569 DCHECK(it != in_progress_items_.end()); 570 DCHECK(it != in_progress_items_.end());
570 DCHECK_EQ(save_item, it->second); 571 DCHECK_EQ(save_item, it->second.get());
572 std::unique_ptr<SaveItem> owned_item = std::move(it->second);
571 in_progress_items_.erase(it); 573 in_progress_items_.erase(it);
572 574
573 SaveItemIdMap& map = save_item->success() ? 575 SaveItemIdMap& map = save_item->success() ?
574 saved_success_items_ : saved_failed_items_; 576 saved_success_items_ : saved_failed_items_;
575 DCHECK(!base::ContainsKey(map, save_item->id())); 577 DCHECK(!base::ContainsKey(map, save_item->id()));
576 map[save_item->id()] = save_item; 578 map[save_item->id()] = std::move(owned_item);
577 } 579 }
578 580
579 // Called for updating saving state. 581 // Called for updating saving state.
580 bool SavePackage::UpdateSaveProgress(SaveItemId save_item_id, 582 bool SavePackage::UpdateSaveProgress(SaveItemId save_item_id,
581 int64_t size, 583 int64_t size,
582 bool write_success) { 584 bool write_success) {
583 DCHECK_CURRENTLY_ON(BrowserThread::UI); 585 DCHECK_CURRENTLY_ON(BrowserThread::UI);
584 // Because we might have canceled this saving job before, 586 // Because we might have canceled this saving job before,
585 // so we might not find corresponding SaveItem. 587 // so we might not find corresponding SaveItem.
586 SaveItem* save_item = LookupInProgressSaveItem(save_item_id); 588 SaveItem* save_item = LookupInProgressSaveItem(save_item_id);
(...skipping 16 matching lines...) Expand all
603 DCHECK_CURRENTLY_ON(BrowserThread::UI); 605 DCHECK_CURRENTLY_ON(BrowserThread::UI);
604 // If we haven't moved out of the initial state, there's nothing to cancel and 606 // If we haven't moved out of the initial state, there's nothing to cancel and
605 // there won't be valid pointers for |file_manager_| or |download_|. 607 // there won't be valid pointers for |file_manager_| or |download_|.
606 if (wait_state_ == INITIALIZE) 608 if (wait_state_ == INITIALIZE)
607 return; 609 return;
608 610
609 // When stopping, if it still has some items in in_progress, cancel them. 611 // When stopping, if it still has some items in in_progress, cancel them.
610 DCHECK(canceled()); 612 DCHECK(canceled());
611 if (in_process_count()) { 613 if (in_process_count()) {
612 for (const auto& it : in_progress_items_) { 614 for (const auto& it : in_progress_items_) {
613 SaveItem* save_item = it.second; 615 SaveItem* save_item = it.second.get();
614 DCHECK_EQ(SaveItem::IN_PROGRESS, save_item->state()); 616 DCHECK_EQ(SaveItem::IN_PROGRESS, save_item->state());
615 save_item->Cancel(); 617 save_item->Cancel();
616 } 618 }
617 // Remove all in progress item to saved map. For failed items, they will 619 // Remove all in progress item to saved map. For failed items, they will
618 // be put into saved_failed_items_, for successful item, they will be put 620 // be put into saved_failed_items_, for successful item, they will be put
619 // into saved_success_items_. 621 // into saved_success_items_.
620 while (in_process_count()) 622 while (in_process_count())
621 PutInProgressItemToSavedMap(in_progress_items_.begin()->second); 623 PutInProgressItemToSavedMap(in_progress_items_.begin()->second.get());
622 } 624 }
623 625
624 // This vector contains the save ids of the save files which SaveFileManager 626 // This vector contains the save ids of the save files which SaveFileManager
625 // needs to remove from its save_file_map_. 627 // needs to remove from its save_file_map_.
626 std::vector<SaveItemId> save_item_ids; 628 std::vector<SaveItemId> save_item_ids;
627 for (const auto& it : saved_success_items_) 629 for (const auto& it : saved_success_items_)
628 save_item_ids.push_back(it.first); 630 save_item_ids.push_back(it.first);
629 for (const auto& it : saved_failed_items_) 631 for (const auto& it : saved_failed_items_)
630 save_item_ids.push_back(it.first); 632 save_item_ids.push_back(it.first);
631 633
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 if (wrote_to_completed_file_) 687 if (wrote_to_completed_file_)
686 RecordSavePackageEvent(SAVE_PACKAGE_WRITE_TO_COMPLETED); 688 RecordSavePackageEvent(SAVE_PACKAGE_WRITE_TO_COMPLETED);
687 689
688 if (wrote_to_failed_file_) 690 if (wrote_to_failed_file_)
689 RecordSavePackageEvent(SAVE_PACKAGE_WRITE_TO_FAILED); 691 RecordSavePackageEvent(SAVE_PACKAGE_WRITE_TO_FAILED);
690 692
691 // This vector contains the save ids of the save files which SaveFileManager 693 // This vector contains the save ids of the save files which SaveFileManager
692 // needs to remove from its |save_file_map_|. 694 // needs to remove from its |save_file_map_|.
693 std::vector<SaveItemId> list_of_failed_save_item_ids; 695 std::vector<SaveItemId> list_of_failed_save_item_ids;
694 for (const auto& it : saved_failed_items_) { 696 for (const auto& it : saved_failed_items_) {
695 const SaveItem* save_item = it.second; 697 const SaveItem* save_item = it.second.get();
696 DCHECK_EQ(it.first, save_item->id()); 698 DCHECK_EQ(it.first, save_item->id());
697 list_of_failed_save_item_ids.push_back(save_item->id()); 699 list_of_failed_save_item_ids.push_back(save_item->id());
698 } 700 }
699 701
700 BrowserThread::PostTask( 702 BrowserThread::PostTask(
701 BrowserThread::FILE, FROM_HERE, 703 BrowserThread::FILE, FROM_HERE,
702 base::Bind(&SaveFileManager::RemoveSavedFileFromFileMap, file_manager_, 704 base::Bind(&SaveFileManager::RemoveSavedFileFromFileMap, file_manager_,
703 list_of_failed_save_item_ids)); 705 list_of_failed_save_item_ids));
704 706
705 if (download_) { 707 if (download_) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 base::Bind(&SaveFileManager::CancelSave, file_manager_, save_item->id())); 773 base::Bind(&SaveFileManager::CancelSave, file_manager_, save_item->id()));
772 } 774 }
773 775
774 void SavePackage::SaveNextFile(bool process_all_remaining_items) { 776 void SavePackage::SaveNextFile(bool process_all_remaining_items) {
775 DCHECK_CURRENTLY_ON(BrowserThread::UI); 777 DCHECK_CURRENTLY_ON(BrowserThread::UI);
776 DCHECK(web_contents()); 778 DCHECK(web_contents());
777 DCHECK(!waiting_item_queue_.empty()); 779 DCHECK(!waiting_item_queue_.empty());
778 780
779 do { 781 do {
780 // Pop SaveItem from waiting list. 782 // Pop SaveItem from waiting list.
781 SaveItem* save_item = waiting_item_queue_.front(); 783 std::unique_ptr<SaveItem> save_item =
784 std::move(waiting_item_queue_.front());
785 SaveItem* save_item_ptr = save_item.get();
782 waiting_item_queue_.pop_front(); 786 waiting_item_queue_.pop_front();
783 787
784 // Add the item to |in_progress_items_|. 788 // Add the item to |in_progress_items_|.
785 DCHECK(!base::ContainsKey(in_progress_items_, save_item->id())); 789 DCHECK(!base::ContainsKey(in_progress_items_, save_item->id()));
786 in_progress_items_[save_item->id()] = save_item; 790 in_progress_items_[save_item_ptr->id()] = std::move(save_item);
787 save_item->Start(); 791 save_item_ptr->Start();
788 792
789 // Find the frame responsible for making the network request below - it will 793 // Find the frame responsible for making the network request below - it will
790 // be used in security checks made later by ResourceDispatcherHostImpl. 794 // be used in security checks made later by ResourceDispatcherHostImpl.
791 int requester_frame_tree_node_id = 795 int requester_frame_tree_node_id =
792 save_item->save_source() == SaveFileCreateInfo::SAVE_FILE_FROM_NET 796 save_item_ptr->save_source() == SaveFileCreateInfo::SAVE_FILE_FROM_NET
793 ? save_item->container_frame_tree_node_id() 797 ? save_item_ptr->container_frame_tree_node_id()
794 : save_item->frame_tree_node_id(); 798 : save_item_ptr->frame_tree_node_id();
795 DCHECK_NE(FrameTreeNode::kFrameTreeNodeInvalidId, 799 DCHECK_NE(FrameTreeNode::kFrameTreeNodeInvalidId,
796 requester_frame_tree_node_id); 800 requester_frame_tree_node_id);
797 FrameTreeNode* requester_frame_tree_node = 801 FrameTreeNode* requester_frame_tree_node =
798 FrameTreeNode::GloballyFindByID(requester_frame_tree_node_id); 802 FrameTreeNode::GloballyFindByID(requester_frame_tree_node_id);
799 if (!requester_frame_tree_node) { 803 if (!requester_frame_tree_node) {
800 save_item->Finish(0, /* is_success = */ false); 804 save_item_ptr->Finish(0, /* is_success = */ false);
801 continue; 805 continue;
802 } 806 }
803 RenderFrameHostImpl* requester_frame = 807 RenderFrameHostImpl* requester_frame =
804 requester_frame_tree_node->current_frame_host(); 808 requester_frame_tree_node->current_frame_host();
805 809
806 file_manager_->SaveURL( 810 file_manager_->SaveURL(
807 save_item->id(), save_item->url(), save_item->referrer(), 811 save_item_ptr->id(), save_item_ptr->url(), save_item_ptr->referrer(),
808 requester_frame->GetProcess()->GetID(), 812 requester_frame->GetProcess()->GetID(),
809 requester_frame->render_view_host()->GetRoutingID(), 813 requester_frame->render_view_host()->GetRoutingID(),
810 requester_frame->routing_id(), save_item->save_source(), 814 requester_frame->routing_id(), save_item_ptr->save_source(),
811 save_item->full_path(), 815 save_item_ptr->full_path(),
812 web_contents()->GetBrowserContext()->GetResourceContext(), this); 816 web_contents()->GetBrowserContext()->GetResourceContext(), this);
813 } while (process_all_remaining_items && !waiting_item_queue_.empty()); 817 } while (process_all_remaining_items && !waiting_item_queue_.empty());
814 } 818 }
815 819
816 int SavePackage::PercentComplete() { 820 int SavePackage::PercentComplete() {
817 DCHECK_CURRENTLY_ON(BrowserThread::UI); 821 DCHECK_CURRENTLY_ON(BrowserThread::UI);
818 if (!all_save_items_count_) 822 if (!all_save_items_count_)
819 return 0; 823 return 0;
820 if (!in_process_count()) 824 if (!in_process_count())
821 return 100; 825 return 100;
(...skipping 12 matching lines...) Expand all
834 if (save_type_ == SAVE_PAGE_TYPE_AS_COMPLETE_HTML) { 838 if (save_type_ == SAVE_PAGE_TYPE_AS_COMPLETE_HTML) {
835 // We guarantee that images and JavaScripts must be downloaded first. 839 // We guarantee that images and JavaScripts must be downloaded first.
836 // So when finishing all those sub-resources, we will know which 840 // So when finishing all those sub-resources, we will know which
837 // sub-resource's link can be replaced with local file path, which 841 // sub-resource's link can be replaced with local file path, which
838 // sub-resource's link need to be replaced with absolute URL which 842 // sub-resource's link need to be replaced with absolute URL which
839 // point to its internet address because it got error when saving its data. 843 // point to its internet address because it got error when saving its data.
840 844
841 // Start a new SaveItem job if we still have job in waiting queue. 845 // Start a new SaveItem job if we still have job in waiting queue.
842 if (waiting_item_queue_.size()) { 846 if (waiting_item_queue_.size()) {
843 DCHECK_EQ(NET_FILES, wait_state_); 847 DCHECK_EQ(NET_FILES, wait_state_);
844 const SaveItem* save_item = waiting_item_queue_.front(); 848 const SaveItem* save_item = waiting_item_queue_.front().get();
845 if (save_item->save_source() != SaveFileCreateInfo::SAVE_FILE_FROM_DOM) { 849 if (save_item->save_source() != SaveFileCreateInfo::SAVE_FILE_FROM_DOM) {
846 SaveNextFile(false); 850 SaveNextFile(false);
847 } else if (!in_process_count()) { 851 } else if (!in_process_count()) {
848 // If there is no in-process SaveItem, it means all sub-resources 852 // If there is no in-process SaveItem, it means all sub-resources
849 // have been processed. Now we need to start serializing HTML DOM 853 // have been processed. Now we need to start serializing HTML DOM
850 // for the current page to get the generated HTML data. 854 // for the current page to get the generated HTML data.
851 wait_state_ = HTML_DATA; 855 wait_state_ = HTML_DATA;
852 // All non-HTML resources have been finished, start all remaining 856 // All non-HTML resources have been finished, start all remaining
853 // HTML files. 857 // HTML files.
854 SaveNextFile(true); 858 SaveNextFile(true);
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
1127 int container_frame_tree_node_id, 1131 int container_frame_tree_node_id,
1128 int save_item_frame_tree_node_id, 1132 int save_item_frame_tree_node_id,
1129 const GURL& url, 1133 const GURL& url,
1130 const Referrer& referrer, 1134 const Referrer& referrer,
1131 SaveFileCreateInfo::SaveFileSource save_source) { 1135 SaveFileCreateInfo::SaveFileSource save_source) {
1132 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1136 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1133 Referrer sanitized_referrer = Referrer::SanitizeForRequest(url, referrer); 1137 Referrer sanitized_referrer = Referrer::SanitizeForRequest(url, referrer);
1134 SaveItem* save_item = 1138 SaveItem* save_item =
1135 new SaveItem(url, sanitized_referrer, this, save_source, 1139 new SaveItem(url, sanitized_referrer, this, save_source,
1136 save_item_frame_tree_node_id, container_frame_tree_node_id); 1140 save_item_frame_tree_node_id, container_frame_tree_node_id);
1137 waiting_item_queue_.push_back(save_item); 1141 waiting_item_queue_.push_back(base::WrapUnique(save_item));
1138 1142
1139 frame_tree_node_id_to_contained_save_items_[container_frame_tree_node_id] 1143 frame_tree_node_id_to_contained_save_items_[container_frame_tree_node_id]
1140 .push_back(save_item); 1144 .push_back(save_item);
1141 return save_item; 1145 return save_item;
1142 } 1146 }
1143 1147
1144 SaveItem* SavePackage::CreatePendingSaveItemDeduplicatingByUrl( 1148 SaveItem* SavePackage::CreatePendingSaveItemDeduplicatingByUrl(
1145 int container_frame_tree_node_id, 1149 int container_frame_tree_node_id,
1146 int save_item_frame_tree_node_id, 1150 int save_item_frame_tree_node_id,
1147 const GURL& url, 1151 const GURL& url,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1205 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1202 --number_of_frames_pending_response_; 1206 --number_of_frames_pending_response_;
1203 DCHECK_LE(0, number_of_frames_pending_response_); 1207 DCHECK_LE(0, number_of_frames_pending_response_);
1204 if (number_of_frames_pending_response_ != 0) 1208 if (number_of_frames_pending_response_ != 0)
1205 return; // Need to wait for more responses from RenderFrames. 1209 return; // Need to wait for more responses from RenderFrames.
1206 1210
1207 // Sort |waiting_item_queue_| so that frames go last (frames are identified by 1211 // Sort |waiting_item_queue_| so that frames go last (frames are identified by
1208 // SAVE_FILE_FROM_DOM in the comparison function below). 1212 // SAVE_FILE_FROM_DOM in the comparison function below).
1209 std::stable_sort( 1213 std::stable_sort(
1210 waiting_item_queue_.begin(), waiting_item_queue_.end(), 1214 waiting_item_queue_.begin(), waiting_item_queue_.end(),
1211 [](SaveItem* x, SaveItem* y) { 1215 [](const std::unique_ptr<SaveItem>& x,
1216 const std::unique_ptr<SaveItem>& y) {
1212 DCHECK(x); 1217 DCHECK(x);
1213 DCHECK(y); 1218 DCHECK(y);
1214 return (x->save_source() != SaveFileCreateInfo::SAVE_FILE_FROM_DOM) && 1219 return (x->save_source() != SaveFileCreateInfo::SAVE_FILE_FROM_DOM) &&
1215 (y->save_source() == SaveFileCreateInfo::SAVE_FILE_FROM_DOM); 1220 (y->save_source() == SaveFileCreateInfo::SAVE_FILE_FROM_DOM);
1216 }); 1221 });
1217 1222
1218 all_save_items_count_ = static_cast<int>(waiting_item_queue_.size()); 1223 all_save_items_count_ = static_cast<int>(waiting_item_queue_.size());
1219 1224
1220 // We use total bytes as the total number of files we want to save. 1225 // We use total bytes as the total number of files we want to save.
1221 // Hack to avoid touching download_ after user cancel. 1226 // Hack to avoid touching download_ after user cancel.
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
1478 } 1483 }
1479 1484
1480 void SavePackage::FinalizeDownloadEntry() { 1485 void SavePackage::FinalizeDownloadEntry() {
1481 DCHECK(download_); 1486 DCHECK(download_);
1482 1487
1483 download_manager_->OnSavePackageSuccessfullyFinished(download_); 1488 download_manager_->OnSavePackageSuccessfullyFinished(download_);
1484 RemoveObservers(); 1489 RemoveObservers();
1485 } 1490 }
1486 1491
1487 } // namespace content 1492 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/save_package.h ('k') | content/browser/manifest/manifest_manager_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698