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

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

Issue 2228403003: content: Use stl utilities from the base namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 4 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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 Cancel(true); 185 Cancel(true);
186 } 186 }
187 187
188 // We should no longer be observing the DownloadItem at this point. 188 // We should no longer be observing the DownloadItem at this point.
189 CHECK(!download_); 189 CHECK(!download_);
190 190
191 DCHECK_EQ(all_save_items_count_, waiting_item_queue_.size() + 191 DCHECK_EQ(all_save_items_count_, waiting_item_queue_.size() +
192 completed_count() + in_process_count()); 192 completed_count() + in_process_count());
193 193
194 // Free all SaveItems. 194 // Free all SaveItems.
195 STLDeleteElements(&waiting_item_queue_); 195 base::STLDeleteElements(&waiting_item_queue_);
196 STLDeleteValues(&in_progress_items_); 196 base::STLDeleteValues(&in_progress_items_);
197 STLDeleteValues(&saved_success_items_); 197 base::STLDeleteValues(&saved_success_items_);
198 STLDeleteValues(&saved_failed_items_); 198 base::STLDeleteValues(&saved_failed_items_);
199 // Clear containers that contain (now dangling/invalid) pointers to the 199 // Clear containers that contain (now dangling/invalid) pointers to the
200 // save items freed above. This is not strictly required (as the containers 200 // 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. 201 // will be destructed soon by ~SavePackage), but seems like good code hygiene.
202 frame_tree_node_id_to_contained_save_items_.clear(); 202 frame_tree_node_id_to_contained_save_items_.clear();
203 frame_tree_node_id_to_save_item_.clear(); 203 frame_tree_node_id_to_save_item_.clear();
204 url_to_save_item_.clear(); 204 url_to_save_item_.clear();
205 205
206 file_manager_ = nullptr; 206 file_manager_ = nullptr;
207 } 207 }
208 208
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 566
567 void SavePackage::PutInProgressItemToSavedMap(SaveItem* save_item) { 567 void SavePackage::PutInProgressItemToSavedMap(SaveItem* save_item) {
568 DCHECK_CURRENTLY_ON(BrowserThread::UI); 568 DCHECK_CURRENTLY_ON(BrowserThread::UI);
569 SaveItemIdMap::iterator it = in_progress_items_.find(save_item->id()); 569 SaveItemIdMap::iterator it = in_progress_items_.find(save_item->id());
570 DCHECK(it != in_progress_items_.end()); 570 DCHECK(it != in_progress_items_.end());
571 DCHECK_EQ(save_item, it->second); 571 DCHECK_EQ(save_item, it->second);
572 in_progress_items_.erase(it); 572 in_progress_items_.erase(it);
573 573
574 SaveItemIdMap& map = save_item->success() ? 574 SaveItemIdMap& map = save_item->success() ?
575 saved_success_items_ : saved_failed_items_; 575 saved_success_items_ : saved_failed_items_;
576 DCHECK(!ContainsKey(map, save_item->id())); 576 DCHECK(!base::ContainsKey(map, save_item->id()));
577 map[save_item->id()] = save_item; 577 map[save_item->id()] = save_item;
578 } 578 }
579 579
580 // Called for updating saving state. 580 // Called for updating saving state.
581 bool SavePackage::UpdateSaveProgress(SaveItemId save_item_id, 581 bool SavePackage::UpdateSaveProgress(SaveItemId save_item_id,
582 int64_t size, 582 int64_t size,
583 bool write_success) { 583 bool write_success) {
584 DCHECK_CURRENTLY_ON(BrowserThread::UI); 584 DCHECK_CURRENTLY_ON(BrowserThread::UI);
585 // Because we might have canceled this saving job before, 585 // Because we might have canceled this saving job before,
586 // so we might not find corresponding SaveItem. 586 // so we might not find corresponding SaveItem.
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 DCHECK_CURRENTLY_ON(BrowserThread::UI); 776 DCHECK_CURRENTLY_ON(BrowserThread::UI);
777 DCHECK(web_contents()); 777 DCHECK(web_contents());
778 DCHECK(!waiting_item_queue_.empty()); 778 DCHECK(!waiting_item_queue_.empty());
779 779
780 do { 780 do {
781 // Pop SaveItem from waiting list. 781 // Pop SaveItem from waiting list.
782 SaveItem* save_item = waiting_item_queue_.front(); 782 SaveItem* save_item = waiting_item_queue_.front();
783 waiting_item_queue_.pop_front(); 783 waiting_item_queue_.pop_front();
784 784
785 // Add the item to |in_progress_items_|. 785 // Add the item to |in_progress_items_|.
786 DCHECK(!ContainsKey(in_progress_items_, save_item->id())); 786 DCHECK(!base::ContainsKey(in_progress_items_, save_item->id()));
787 in_progress_items_[save_item->id()] = save_item; 787 in_progress_items_[save_item->id()] = save_item;
788 save_item->Start(); 788 save_item->Start();
789 789
790 // Find the frame responsible for making the network request below - it will 790 // Find the frame responsible for making the network request below - it will
791 // be used in security checks made later by ResourceDispatcherHostImpl. 791 // be used in security checks made later by ResourceDispatcherHostImpl.
792 int requester_frame_tree_node_id = 792 int requester_frame_tree_node_id =
793 save_item->save_source() == SaveFileCreateInfo::SAVE_FILE_FROM_NET 793 save_item->save_source() == SaveFileCreateInfo::SAVE_FILE_FROM_NET
794 ? save_item->container_frame_tree_node_id() 794 ? save_item->container_frame_tree_node_id()
795 : save_item->frame_tree_node_id(); 795 : save_item->frame_tree_node_id();
796 DCHECK_NE(FrameTreeNode::kFrameTreeNodeInvalidId, 796 DCHECK_NE(FrameTreeNode::kFrameTreeNodeInvalidId,
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 const SaveItem* save_item = it->second; 1021 const SaveItem* save_item = it->second;
1022 DCHECK_EQ(SaveFileCreateInfo::SAVE_FILE_FROM_DOM, save_item->save_source()); 1022 DCHECK_EQ(SaveFileCreateInfo::SAVE_FILE_FROM_DOM, save_item->save_source());
1023 if (save_item->state() != SaveItem::IN_PROGRESS) { 1023 if (save_item->state() != SaveItem::IN_PROGRESS) {
1024 for (const auto& saved_it : saved_success_items_) { 1024 for (const auto& saved_it : saved_success_items_) {
1025 if (saved_it.second->url() == save_item->url()) { 1025 if (saved_it.second->url() == save_item->url()) {
1026 wrote_to_completed_file_ = true; 1026 wrote_to_completed_file_ = true;
1027 break; 1027 break;
1028 } 1028 }
1029 } 1029 }
1030 1030
1031 if (ContainsKey(saved_failed_items_, save_item->id())) 1031 if (base::ContainsKey(saved_failed_items_, save_item->id()))
1032 wrote_to_failed_file_ = true; 1032 wrote_to_failed_file_ = true;
1033 1033
1034 return; 1034 return;
1035 } 1035 }
1036 1036
1037 if (!data.empty()) { 1037 if (!data.empty()) {
1038 // Prepare buffer for saving HTML data. 1038 // Prepare buffer for saving HTML data.
1039 scoped_refptr<net::IOBuffer> new_data(new net::IOBuffer(data.size())); 1039 scoped_refptr<net::IOBuffer> new_data(new net::IOBuffer(data.size()));
1040 memcpy(new_data->data(), data.data(), data.size()); 1040 memcpy(new_data->data(), data.data(), data.size());
1041 1041
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
1479 } 1479 }
1480 1480
1481 void SavePackage::FinalizeDownloadEntry() { 1481 void SavePackage::FinalizeDownloadEntry() {
1482 DCHECK(download_); 1482 DCHECK(download_);
1483 1483
1484 download_manager_->OnSavePackageSuccessfullyFinished(download_); 1484 download_manager_->OnSavePackageSuccessfullyFinished(download_);
1485 RemoveObservers(); 1485 RemoveObservers();
1486 } 1486 }
1487 1487
1488 } // namespace content 1488 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/save_file_manager.cc ('k') | content/browser/file_descriptor_info_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698