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

Side by Side Diff: components/webdata/common/web_data_request_manager.cc

Issue 2403773002: Remove stl_util's STLDeleteContainerPointers from autofill. (Closed)
Patch Set: rebase 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 "components/webdata/common/web_data_request_manager.h" 5 #include "components/webdata/common/web_data_request_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 12 matching lines...) Expand all
23 : manager_(manager), cancelled_(false), consumer_(consumer) { 23 : manager_(manager), cancelled_(false), consumer_(consumer) {
24 handle_ = manager_->GetNextRequestHandle(); 24 handle_ = manager_->GetNextRequestHandle();
25 task_runner_ = base::ThreadTaskRunnerHandle::Get(); 25 task_runner_ = base::ThreadTaskRunnerHandle::Get();
26 manager_->RegisterRequest(this); 26 manager_->RegisterRequest(this);
27 } 27 }
28 28
29 WebDataRequest::~WebDataRequest() { 29 WebDataRequest::~WebDataRequest() {
30 if (manager_) { 30 if (manager_) {
31 manager_->CancelRequest(handle_); 31 manager_->CancelRequest(handle_);
32 } 32 }
33 if (result_.get()) {
34 result_->Destroy();
35 }
36 } 33 }
37 34
38 WebDataServiceBase::Handle WebDataRequest::GetHandle() const { 35 WebDataServiceBase::Handle WebDataRequest::GetHandle() const {
39 return handle_; 36 return handle_;
40 } 37 }
41 38
42 WebDataServiceConsumer* WebDataRequest::GetConsumer() const { 39 WebDataServiceConsumer* WebDataRequest::GetConsumer() const {
43 return consumer_; 40 return consumer_;
44 } 41 }
45 42
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 // WebDataRequestManager implementation. 74 // WebDataRequestManager implementation.
78 // 75 //
79 //////////////////////////////////////////////////////////////////////////////// 76 ////////////////////////////////////////////////////////////////////////////////
80 77
81 WebDataRequestManager::WebDataRequestManager() 78 WebDataRequestManager::WebDataRequestManager()
82 : next_request_handle_(1) { 79 : next_request_handle_(1) {
83 } 80 }
84 81
85 WebDataRequestManager::~WebDataRequestManager() { 82 WebDataRequestManager::~WebDataRequestManager() {
86 base::AutoLock l(pending_lock_); 83 base::AutoLock l(pending_lock_);
87 for (RequestMap::iterator i = pending_requests_.begin(); 84 for (auto i = pending_requests_.begin(); i != pending_requests_.end(); ++i) {
88 i != pending_requests_.end(); ++i) {
89 i->second->Cancel(); 85 i->second->Cancel();
90 } 86 }
91 pending_requests_.clear(); 87 pending_requests_.clear();
92 } 88 }
93 89
94 void WebDataRequestManager::RegisterRequest(WebDataRequest* request) { 90 void WebDataRequestManager::RegisterRequest(WebDataRequest* request) {
95 base::AutoLock l(pending_lock_); 91 base::AutoLock l(pending_lock_);
96 pending_requests_[request->GetHandle()] = request; 92 pending_requests_[request->GetHandle()] = request;
97 } 93 }
98 94
99 int WebDataRequestManager::GetNextRequestHandle() { 95 int WebDataRequestManager::GetNextRequestHandle() {
100 base::AutoLock l(pending_lock_); 96 base::AutoLock l(pending_lock_);
101 return ++next_request_handle_; 97 return ++next_request_handle_;
102 } 98 }
103 99
104 void WebDataRequestManager::CancelRequest(WebDataServiceBase::Handle h) { 100 void WebDataRequestManager::CancelRequest(WebDataServiceBase::Handle h) {
105 base::AutoLock l(pending_lock_); 101 base::AutoLock l(pending_lock_);
106 RequestMap::iterator i = pending_requests_.find(h); 102 auto i = pending_requests_.find(h);
107 if (i == pending_requests_.end()) { 103 if (i == pending_requests_.end()) {
108 NOTREACHED() << "Canceling a nonexistent web data service request"; 104 NOTREACHED() << "Canceling a nonexistent web data service request";
109 return; 105 return;
110 } 106 }
111 i->second->Cancel(); 107 i->second->Cancel();
112 pending_requests_.erase(i); 108 pending_requests_.erase(i);
113 } 109 }
114 110
115 void WebDataRequestManager::RequestCompleted( 111 void WebDataRequestManager::RequestCompleted(
116 std::unique_ptr<WebDataRequest> request) { 112 std::unique_ptr<WebDataRequest> request) {
117 scoped_refptr<base::SingleThreadTaskRunner> task_runner = 113 scoped_refptr<base::SingleThreadTaskRunner> task_runner =
118 request->GetTaskRunner(); 114 request->GetTaskRunner();
119 task_runner->PostTask( 115 task_runner->PostTask(
120 FROM_HERE, base::Bind(&WebDataRequestManager::RequestCompletedOnThread, 116 FROM_HERE, base::Bind(&WebDataRequestManager::RequestCompletedOnThread,
121 this, base::Passed(&request))); 117 this, base::Passed(&request)));
122 } 118 }
123 119
124 void WebDataRequestManager::RequestCompletedOnThread( 120 void WebDataRequestManager::RequestCompletedOnThread(
125 std::unique_ptr<WebDataRequest> request) { 121 std::unique_ptr<WebDataRequest> request) {
126 if (request->IsCancelled()) 122 if (request->IsCancelled())
127 return; 123 return;
128 124
129 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is 125 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is
130 // fixed. 126 // fixed.
131 tracked_objects::ScopedTracker tracking_profile1( 127 tracked_objects::ScopedTracker tracking_profile1(
132 FROM_HERE_WITH_EXPLICIT_FUNCTION( 128 FROM_HERE_WITH_EXPLICIT_FUNCTION(
133 "422460 WebDataRequestManager::RequestCompletedOnThread::UpdateMap")); 129 "422460 WebDataRequestManager::RequestCompletedOnThread::UpdateMap"));
134 { 130 {
135 base::AutoLock l(pending_lock_); 131 base::AutoLock l(pending_lock_);
136 RequestMap::iterator i = pending_requests_.find(request->GetHandle()); 132 auto i = pending_requests_.find(request->GetHandle());
137 if (i == pending_requests_.end()) { 133 if (i == pending_requests_.end()) {
138 NOTREACHED() << "Request completed called for an unknown request"; 134 NOTREACHED() << "Request completed called for an unknown request";
139 return; 135 return;
140 } 136 }
141 137
142 // Take ownership of the request object and remove it from the map. 138 // Take ownership of the request object and remove it from the map.
143 pending_requests_.erase(i); 139 pending_requests_.erase(i);
144 } 140 }
145 141
146 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is 142 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is
147 // fixed. 143 // fixed.
148 tracked_objects::ScopedTracker tracking_profile2( 144 tracked_objects::ScopedTracker tracking_profile2(
149 FROM_HERE_WITH_EXPLICIT_FUNCTION( 145 FROM_HERE_WITH_EXPLICIT_FUNCTION(
150 "422460 " 146 "422460 "
151 "WebDataRequestManager::RequestCompletedOnThread::NotifyConsumer")); 147 "WebDataRequestManager::RequestCompletedOnThread::NotifyConsumer"));
152 148
153 // Notify the consumer if needed. 149 // Notify the consumer if needed.
154 if (!request->IsCancelled()) { 150 if (!request->IsCancelled()) {
155 WebDataServiceConsumer* consumer = request->GetConsumer(); 151 WebDataServiceConsumer* consumer = request->GetConsumer();
156 request->OnComplete(); 152 request->OnComplete();
157 if (consumer) { 153 if (consumer) {
158 std::unique_ptr<WDTypedResult> r = request->GetResult(); 154 std::unique_ptr<WDTypedResult> r = request->GetResult();
159 consumer->OnWebDataServiceRequestDone(request->GetHandle(), r.get()); 155 consumer->OnWebDataServiceRequestDone(request->GetHandle(), std::move(r));
160 } 156 }
161 } 157 }
162 158
163 } 159 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698