OLD | NEW |
---|---|
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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 WebDataRequestManager::~WebDataRequestManager() { | 110 WebDataRequestManager::~WebDataRequestManager() { |
111 base::AutoLock l(pending_lock_); | 111 base::AutoLock l(pending_lock_); |
112 for (auto i = pending_requests_.begin(); i != pending_requests_.end(); ++i) | 112 for (auto i = pending_requests_.begin(); i != pending_requests_.end(); ++i) |
113 i->second->MarkAsInactive(); | 113 i->second->MarkAsInactive(); |
114 pending_requests_.clear(); | 114 pending_requests_.clear(); |
115 } | 115 } |
116 | 116 |
117 void WebDataRequestManager::RequestCompletedOnThread( | 117 void WebDataRequestManager::RequestCompletedOnThread( |
118 std::unique_ptr<WebDataRequest> request, | 118 std::unique_ptr<WebDataRequest> request, |
119 std::unique_ptr<WDTypedResult> result) { | 119 std::unique_ptr<WDTypedResult> result) { |
120 // Manipulate the pending_requests_ collection while holding the lock. | 120 // Check whether the request is active. It might have been cancelled in |
121 // another thread before this completion handler was invoked. This means the | |
122 // request initiator is no longer interested in the result. | |
123 if (!request->IsActive()) | |
124 return; | |
125 | |
126 // Stop tracking the request. The request is already finished, so "stop | |
127 // tracking" is the same as post-facto cancellation. | |
121 { | 128 { |
122 base::AutoLock l(pending_lock_); | |
123 | |
124 // Check whether the request is active. It might have been cancelled in | |
125 // another thread before the lock was acquired. | |
126 if (!request->IsActive()) | |
127 return; | |
128 | |
129 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 | 129 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 |
130 // is fixed. | 130 // is fixed. |
131 tracked_objects::ScopedTracker tracking_profile( | 131 tracked_objects::ScopedTracker tracking_profile( |
Roger McFarlane (Chromium)
2017/05/08 17:41:32
as a side-effect of this change, this ScopedTracke
| |
132 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 132 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
133 "422460 " | 133 "422460 " |
134 "WebDataRequestManager::RequestCompletedOnThread::UpdateMap")); | 134 "WebDataRequestManager::RequestCompletedOnThread::UpdateMap")); |
135 | 135 |
136 // Remove the request object from the pending_requests_ map. Note that this | 136 CancelRequest(request->GetHandle()); |
137 // method has ownership of the object (it was passed by unique_ptr). | |
138 auto i = pending_requests_.find(request->GetHandle()); | |
139 DCHECK(i != pending_requests_.end()); | |
140 pending_requests_.erase(i); | |
141 | |
142 // The request is no longer active. | |
143 request->MarkAsInactive(); | |
144 } | 137 } |
145 | 138 |
146 // Notify the consumer if needed. | 139 // Notify the consumer if needed. |
147 // | |
148 // NOTE: The pending_lock_ is no longer held here. It's up to the consumer to | |
149 // be appropriately thread safe. | |
150 WebDataServiceConsumer* const consumer = request->GetConsumer(); | 140 WebDataServiceConsumer* const consumer = request->GetConsumer(); |
151 if (consumer) { | 141 if (consumer) { |
152 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 | 142 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 |
153 // is fixed. | 143 // is fixed. |
154 tracked_objects::ScopedTracker tracking_profile( | 144 tracked_objects::ScopedTracker tracking_profile( |
155 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 145 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
156 "422460 " | 146 "422460 " |
157 "WebDataRequestManager::RequestCompletedOnThread::NotifyConsumer")); | 147 "WebDataRequestManager::RequestCompletedOnThread::NotifyConsumer")); |
158 | 148 |
159 consumer->OnWebDataServiceRequestDone(request->GetHandle(), | 149 consumer->OnWebDataServiceRequestDone(request->GetHandle(), |
160 std::move(result)); | 150 std::move(result)); |
161 } | 151 } |
162 } | 152 } |
OLD | NEW |