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

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 }
91 pending_requests_.clear(); 86 pending_requests_.clear();
92 } 87 }
93 88
94 void WebDataRequestManager::RegisterRequest(WebDataRequest* request) { 89 void WebDataRequestManager::RegisterRequest(WebDataRequest* request) {
95 base::AutoLock l(pending_lock_); 90 base::AutoLock l(pending_lock_);
96 pending_requests_[request->GetHandle()] = request; 91 pending_requests_[request->GetHandle()] = request;
97 } 92 }
98 93
99 int WebDataRequestManager::GetNextRequestHandle() { 94 int WebDataRequestManager::GetNextRequestHandle() {
100 base::AutoLock l(pending_lock_); 95 base::AutoLock l(pending_lock_);
101 return ++next_request_handle_; 96 return ++next_request_handle_;
102 } 97 }
103 98
104 void WebDataRequestManager::CancelRequest(WebDataServiceBase::Handle h) { 99 void WebDataRequestManager::CancelRequest(WebDataServiceBase::Handle h) {
105 base::AutoLock l(pending_lock_); 100 base::AutoLock l(pending_lock_);
106 RequestMap::iterator i = pending_requests_.find(h); 101 auto i = pending_requests_.find(h);
107 DCHECK(i != pending_requests_.end()); 102 DCHECK(i != pending_requests_.end());
108 i->second->Cancel(); 103 i->second->Cancel();
109 pending_requests_.erase(i); 104 pending_requests_.erase(i);
110 } 105 }
111 106
112 void WebDataRequestManager::RequestCompleted( 107 void WebDataRequestManager::RequestCompleted(
113 std::unique_ptr<WebDataRequest> request) { 108 std::unique_ptr<WebDataRequest> request) {
114 scoped_refptr<base::SingleThreadTaskRunner> task_runner = 109 scoped_refptr<base::SingleThreadTaskRunner> task_runner =
115 request->GetTaskRunner(); 110 request->GetTaskRunner();
116 task_runner->PostTask( 111 task_runner->PostTask(
117 FROM_HERE, base::Bind(&WebDataRequestManager::RequestCompletedOnThread, 112 FROM_HERE, base::Bind(&WebDataRequestManager::RequestCompletedOnThread,
118 this, base::Passed(&request))); 113 this, base::Passed(&request)));
119 } 114 }
120 115
121 void WebDataRequestManager::RequestCompletedOnThread( 116 void WebDataRequestManager::RequestCompletedOnThread(
122 std::unique_ptr<WebDataRequest> request) { 117 std::unique_ptr<WebDataRequest> request) {
123 if (request->IsCancelled()) 118 if (request->IsCancelled())
124 return; 119 return;
125 120
126 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is 121 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is
127 // fixed. 122 // fixed.
128 tracked_objects::ScopedTracker tracking_profile1( 123 tracked_objects::ScopedTracker tracking_profile1(
129 FROM_HERE_WITH_EXPLICIT_FUNCTION( 124 FROM_HERE_WITH_EXPLICIT_FUNCTION(
130 "422460 WebDataRequestManager::RequestCompletedOnThread::UpdateMap")); 125 "422460 WebDataRequestManager::RequestCompletedOnThread::UpdateMap"));
131 { 126 {
132 base::AutoLock l(pending_lock_); 127 base::AutoLock l(pending_lock_);
133 RequestMap::iterator i = pending_requests_.find(request->GetHandle()); 128 auto i = pending_requests_.find(request->GetHandle());
134 DCHECK(i != pending_requests_.end()); 129 DCHECK(i != pending_requests_.end());
135 130
136 // Take ownership of the request object and remove it from the map. 131 // Take ownership of the request object and remove it from the map.
137 pending_requests_.erase(i); 132 pending_requests_.erase(i);
138 } 133 }
139 134
140 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is 135 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is
141 // fixed. 136 // fixed.
142 tracked_objects::ScopedTracker tracking_profile2( 137 tracked_objects::ScopedTracker tracking_profile2(
143 FROM_HERE_WITH_EXPLICIT_FUNCTION( 138 FROM_HERE_WITH_EXPLICIT_FUNCTION(
144 "422460 " 139 "422460 "
145 "WebDataRequestManager::RequestCompletedOnThread::NotifyConsumer")); 140 "WebDataRequestManager::RequestCompletedOnThread::NotifyConsumer"));
146 141
147 // Notify the consumer if needed. 142 // Notify the consumer if needed.
148 if (!request->IsCancelled()) { 143 if (!request->IsCancelled()) {
149 WebDataServiceConsumer* consumer = request->GetConsumer(); 144 WebDataServiceConsumer* consumer = request->GetConsumer();
150 request->OnComplete(); 145 request->OnComplete();
151 if (consumer) { 146 if (consumer) {
152 std::unique_ptr<WDTypedResult> r = request->GetResult(); 147 consumer->OnWebDataServiceRequestDone(request->GetHandle(),
153 consumer->OnWebDataServiceRequestDone(request->GetHandle(), r.get()); 148 request->GetResult());
154 } 149 }
155 } 150 }
156 151
157 } 152 }
OLDNEW
« no previous file with comments | « components/webdata/common/web_data_request_manager.h ('k') | components/webdata/common/web_data_results.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698