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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 } | 97 } |
98 | 98 |
99 int WebDataRequestManager::GetNextRequestHandle() { | 99 int WebDataRequestManager::GetNextRequestHandle() { |
100 base::AutoLock l(pending_lock_); | 100 base::AutoLock l(pending_lock_); |
101 return ++next_request_handle_; | 101 return ++next_request_handle_; |
102 } | 102 } |
103 | 103 |
104 void WebDataRequestManager::CancelRequest(WebDataServiceBase::Handle h) { | 104 void WebDataRequestManager::CancelRequest(WebDataServiceBase::Handle h) { |
105 base::AutoLock l(pending_lock_); | 105 base::AutoLock l(pending_lock_); |
106 RequestMap::iterator i = pending_requests_.find(h); | 106 RequestMap::iterator i = pending_requests_.find(h); |
107 if (i == pending_requests_.end()) { | 107 DCHECK(i != pending_requests_.end()); |
108 NOTREACHED() << "Canceling a nonexistent web data service request"; | |
109 return; | |
110 } | |
111 i->second->Cancel(); | 108 i->second->Cancel(); |
112 pending_requests_.erase(i); | 109 pending_requests_.erase(i); |
113 } | 110 } |
114 | 111 |
115 void WebDataRequestManager::RequestCompleted( | 112 void WebDataRequestManager::RequestCompleted( |
116 std::unique_ptr<WebDataRequest> request) { | 113 std::unique_ptr<WebDataRequest> request) { |
117 scoped_refptr<base::SingleThreadTaskRunner> task_runner = | 114 scoped_refptr<base::SingleThreadTaskRunner> task_runner = |
118 request->GetTaskRunner(); | 115 request->GetTaskRunner(); |
119 task_runner->PostTask( | 116 task_runner->PostTask( |
120 FROM_HERE, base::Bind(&WebDataRequestManager::RequestCompletedOnThread, | 117 FROM_HERE, base::Bind(&WebDataRequestManager::RequestCompletedOnThread, |
121 this, base::Passed(&request))); | 118 this, base::Passed(&request))); |
122 } | 119 } |
123 | 120 |
124 void WebDataRequestManager::RequestCompletedOnThread( | 121 void WebDataRequestManager::RequestCompletedOnThread( |
125 std::unique_ptr<WebDataRequest> request) { | 122 std::unique_ptr<WebDataRequest> request) { |
126 if (request->IsCancelled()) | 123 if (request->IsCancelled()) |
127 return; | 124 return; |
128 | 125 |
129 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is | 126 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is |
130 // fixed. | 127 // fixed. |
131 tracked_objects::ScopedTracker tracking_profile1( | 128 tracked_objects::ScopedTracker tracking_profile1( |
132 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 129 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
133 "422460 WebDataRequestManager::RequestCompletedOnThread::UpdateMap")); | 130 "422460 WebDataRequestManager::RequestCompletedOnThread::UpdateMap")); |
134 { | 131 { |
135 base::AutoLock l(pending_lock_); | 132 base::AutoLock l(pending_lock_); |
136 RequestMap::iterator i = pending_requests_.find(request->GetHandle()); | 133 RequestMap::iterator i = pending_requests_.find(request->GetHandle()); |
137 if (i == pending_requests_.end()) { | 134 DCHECK(i != pending_requests_.end()); |
138 NOTREACHED() << "Request completed called for an unknown request"; | |
139 return; | |
140 } | |
141 | 135 |
142 // Take ownership of the request object and remove it from the map. | 136 // Take ownership of the request object and remove it from the map. |
143 pending_requests_.erase(i); | 137 pending_requests_.erase(i); |
144 } | 138 } |
145 | 139 |
146 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is | 140 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is |
147 // fixed. | 141 // fixed. |
148 tracked_objects::ScopedTracker tracking_profile2( | 142 tracked_objects::ScopedTracker tracking_profile2( |
149 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 143 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
150 "422460 " | 144 "422460 " |
151 "WebDataRequestManager::RequestCompletedOnThread::NotifyConsumer")); | 145 "WebDataRequestManager::RequestCompletedOnThread::NotifyConsumer")); |
152 | 146 |
153 // Notify the consumer if needed. | 147 // Notify the consumer if needed. |
154 if (!request->IsCancelled()) { | 148 if (!request->IsCancelled()) { |
155 WebDataServiceConsumer* consumer = request->GetConsumer(); | 149 WebDataServiceConsumer* consumer = request->GetConsumer(); |
156 request->OnComplete(); | 150 request->OnComplete(); |
157 if (consumer) { | 151 if (consumer) { |
158 std::unique_ptr<WDTypedResult> r = request->GetResult(); | 152 std::unique_ptr<WDTypedResult> r = request->GetResult(); |
159 consumer->OnWebDataServiceRequestDone(request->GetHandle(), r.get()); | 153 consumer->OnWebDataServiceRequestDone(request->GetHandle(), r.get()); |
160 } | 154 } |
161 } | 155 } |
162 | 156 |
163 } | 157 } |
OLD | NEW |