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

Side by Side Diff: extensions/browser/api/bluetooth/bluetooth_private_api.cc

Issue 2017113002: [Extensions] DCHECK that ExtensionFunctions respond (and only once) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/browser/api/bluetooth/bluetooth_private_api.h" 5 #include "extensions/browser/api/bluetooth/bluetooth_private_api.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 CreatePropertyErrorCallback(kPoweredProperty)); 171 CreatePropertyErrorCallback(kPoweredProperty));
172 } 172 }
173 173
174 if (discoverable && adapter->IsDiscoverable() != *discoverable) { 174 if (discoverable && adapter->IsDiscoverable() != *discoverable) {
175 pending_properties_.insert(kDiscoverableProperty); 175 pending_properties_.insert(kDiscoverableProperty);
176 adapter->SetDiscoverable( 176 adapter->SetDiscoverable(
177 *discoverable, CreatePropertySetCallback(kDiscoverableProperty), 177 *discoverable, CreatePropertySetCallback(kDiscoverableProperty),
178 CreatePropertyErrorCallback(kDiscoverableProperty)); 178 CreatePropertyErrorCallback(kDiscoverableProperty));
179 } 179 }
180 180
181 parsed_ = true;
182
181 if (pending_properties_.empty()) 183 if (pending_properties_.empty())
182 SendResponse(true); 184 SendResponse(true);
183 return true; 185 return true;
184 } 186 }
185 187
186 base::Closure 188 base::Closure
187 BluetoothPrivateSetAdapterStateFunction::CreatePropertySetCallback( 189 BluetoothPrivateSetAdapterStateFunction::CreatePropertySetCallback(
188 const std::string& property_name) { 190 const std::string& property_name) {
189 return base::Bind( 191 return base::Bind(
190 &BluetoothPrivateSetAdapterStateFunction::OnAdapterPropertySet, this, 192 &BluetoothPrivateSetAdapterStateFunction::OnAdapterPropertySet, this,
191 property_name); 193 property_name);
192 } 194 }
193 195
194 base::Closure 196 base::Closure
195 BluetoothPrivateSetAdapterStateFunction::CreatePropertyErrorCallback( 197 BluetoothPrivateSetAdapterStateFunction::CreatePropertyErrorCallback(
196 const std::string& property_name) { 198 const std::string& property_name) {
197 return base::Bind( 199 return base::Bind(
198 &BluetoothPrivateSetAdapterStateFunction::OnAdapterPropertyError, this, 200 &BluetoothPrivateSetAdapterStateFunction::OnAdapterPropertyError, this,
199 property_name); 201 property_name);
200 } 202 }
201 203
202 void BluetoothPrivateSetAdapterStateFunction::OnAdapterPropertySet( 204 void BluetoothPrivateSetAdapterStateFunction::OnAdapterPropertySet(
203 const std::string& property) { 205 const std::string& property) {
204 DCHECK(pending_properties_.find(property) != pending_properties_.end()); 206 DCHECK(pending_properties_.find(property) != pending_properties_.end());
205 DCHECK(failed_properties_.find(property) == failed_properties_.end()); 207 DCHECK(failed_properties_.find(property) == failed_properties_.end());
206 208
207 pending_properties_.erase(property); 209 pending_properties_.erase(property);
208 if (pending_properties_.empty()) { 210 if (pending_properties_.empty() && parsed_) {
209 if (failed_properties_.empty()) 211 if (failed_properties_.empty())
210 SendResponse(true); 212 SendResponse(true);
211 else 213 else
212 SendError(); 214 SendError();
213 } 215 }
214 } 216 }
215 217
216 void BluetoothPrivateSetAdapterStateFunction::OnAdapterPropertyError( 218 void BluetoothPrivateSetAdapterStateFunction::OnAdapterPropertyError(
217 const std::string& property) { 219 const std::string& property) {
218 DCHECK(pending_properties_.find(property) != pending_properties_.end()); 220 DCHECK(pending_properties_.find(property) != pending_properties_.end());
219 DCHECK(failed_properties_.find(property) == failed_properties_.end()); 221 DCHECK(failed_properties_.find(property) == failed_properties_.end());
220
221 pending_properties_.erase(property); 222 pending_properties_.erase(property);
222 failed_properties_.insert(property); 223 failed_properties_.insert(property);
223 if (pending_properties_.empty()) 224 if (pending_properties_.empty() && parsed_)
224 SendError(); 225 SendError();
225 } 226 }
226 227
227 void BluetoothPrivateSetAdapterStateFunction::SendError() { 228 void BluetoothPrivateSetAdapterStateFunction::SendError() {
228 DCHECK(pending_properties_.empty()); 229 DCHECK(pending_properties_.empty());
229 DCHECK(!failed_properties_.empty()); 230 DCHECK(!failed_properties_.empty());
230 231
231 std::vector<std::string> failed_vector; 232 std::vector<std::string> failed_vector;
232 std::copy(failed_properties_.begin(), failed_properties_.end(), 233 std::copy(failed_properties_.begin(), failed_properties_.end(),
233 std::back_inserter(failed_vector)); 234 std::back_inserter(failed_vector));
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 device::BluetoothDevice::ConnectErrorCode error) { 617 device::BluetoothDevice::ConnectErrorCode error) {
617 SetError(kPairingFailed); 618 SetError(kPairingFailed);
618 SendResponse(false); 619 SendResponse(false);
619 } 620 }
620 621
621 //////////////////////////////////////////////////////////////////////////////// 622 ////////////////////////////////////////////////////////////////////////////////
622 623
623 } // namespace api 624 } // namespace api
624 625
625 } // namespace extensions 626 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698