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

Side by Side Diff: Source/modules/geolocation/Geolocation.cpp

Issue 641963003: Make the geolocation code use C++11 for-ranges (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008, 2009, 2010, 2011 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008, 2009, 2010, 2011 Apple Inc. All Rights Reserved.
3 * Copyright (C) 2009 Torch Mobile, Inc. 3 * Copyright (C) 2009 Torch Mobile, Inc.
4 * Copyright 2010, The Android Open Source Project 4 * Copyright 2010, The Android Open Source Project
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 234
235 // Request permissions, which may be synchronous or asynchronous. 235 // Request permissions, which may be synchronous or asynchronous.
236 requestPermission(); 236 requestPermission();
237 } 237 }
238 238
239 void Geolocation::makeCachedPositionCallbacks() 239 void Geolocation::makeCachedPositionCallbacks()
240 { 240 {
241 // All modifications to m_requestsAwaitingCachedPosition are done 241 // All modifications to m_requestsAwaitingCachedPosition are done
242 // asynchronously, so we don't need to worry about it being modified from 242 // asynchronously, so we don't need to worry about it being modified from
243 // the callbacks. 243 // the callbacks.
244 GeoNotifierSet::const_iterator end = m_requestsAwaitingCachedPosition.end(); 244 for (GeoNotifier* notifier : m_requestsAwaitingCachedPosition) {
Mike West 2014/10/16 19:38:15 As you're replacing a const_iteratore, please s/Ge
kenneth.christiansen 2014/10/16 22:33:05 That would be a bigger change :-) I am fine to do
245 for (GeoNotifierSet::const_iterator iter = m_requestsAwaitingCachedPosition. begin(); iter != end; ++iter) {
246 GeoNotifier* notifier = iter->get();
247 notifier->runSuccessCallback(lastPosition()); 245 notifier->runSuccessCallback(lastPosition());
248 246
249 // If this is a one-shot request, stop it. Otherwise, if the watch still 247 // If this is a one-shot request, stop it. Otherwise, if the watch still
250 // exists, start the service to get updates. 248 // exists, start the service to get updates.
251 if (m_oneShots.contains(notifier)) 249 if (m_oneShots.contains(notifier))
252 m_oneShots.remove(notifier); 250 m_oneShots.remove(notifier);
253 else if (m_watchers.contains(notifier)) { 251 else if (m_watchers.contains(notifier)) {
254 if (!notifier->options()->timeout() || startUpdating(notifier)) 252 if (!notifier->options()->timeout() || startUpdating(notifier))
255 notifier->startTimer(); 253 notifier->startTimer();
256 else 254 else
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 // If any of the requests are waiting for permission for a cached position, 319 // If any of the requests are waiting for permission for a cached position,
322 // the position from the service will be at least as fresh. 320 // the position from the service will be at least as fresh.
323 if (lastPosition()) 321 if (lastPosition())
324 makeSuccessCallbacks(); 322 makeSuccessCallbacks();
325 else 323 else
326 makeCachedPositionCallbacks(); 324 makeCachedPositionCallbacks();
327 } 325 }
328 326
329 void Geolocation::sendError(GeoNotifierVector& notifiers, PositionError* error) 327 void Geolocation::sendError(GeoNotifierVector& notifiers, PositionError* error)
330 { 328 {
331 GeoNotifierVector::const_iterator end = notifiers.end(); 329 for (GeoNotifier* notifier : notifiers)
332 for (GeoNotifierVector::const_iterator it = notifiers.begin(); it != end; ++ it) 330 notifier->runErrorCallback(error);
333 (*it)->runErrorCallback(error);
334 } 331 }
335 332
336 void Geolocation::sendPosition(GeoNotifierVector& notifiers, Geoposition* positi on) 333 void Geolocation::sendPosition(GeoNotifierVector& notifiers, Geoposition* positi on)
337 { 334 {
338 GeoNotifierVector::const_iterator end = notifiers.end(); 335 for (GeoNotifier* notifier : notifiers)
339 for (GeoNotifierVector::const_iterator it = notifiers.begin(); it != end; ++ it) 336 notifier->runSuccessCallback(position);
340 (*it)->runSuccessCallback(position);
341 } 337 }
342 338
343 void Geolocation::stopTimer(GeoNotifierVector& notifiers) 339 void Geolocation::stopTimer(GeoNotifierVector& notifiers)
344 { 340 {
345 GeoNotifierVector::const_iterator end = notifiers.end(); 341 for (GeoNotifier* notifier : notifiers)
346 for (GeoNotifierVector::const_iterator it = notifiers.begin(); it != end; ++ it) 342 notifier->stopTimer();
347 (*it)->stopTimer();
348 } 343 }
349 344
350 void Geolocation::stopTimersForOneShots() 345 void Geolocation::stopTimersForOneShots()
351 { 346 {
352 GeoNotifierVector copy; 347 GeoNotifierVector copy;
353 copyToVector(m_oneShots, copy); 348 copyToVector(m_oneShots, copy);
354 349
355 stopTimer(copy); 350 stopTimer(copy);
356 } 351 }
357 352
358 void Geolocation::stopTimersForWatchers() 353 void Geolocation::stopTimersForWatchers()
359 { 354 {
360 GeoNotifierVector copy; 355 GeoNotifierVector copy;
361 m_watchers.getNotifiersVector(copy); 356 m_watchers.getNotifiersVector(copy);
362 357
363 stopTimer(copy); 358 stopTimer(copy);
364 } 359 }
365 360
366 void Geolocation::stopTimers() 361 void Geolocation::stopTimers()
367 { 362 {
368 stopTimersForOneShots(); 363 stopTimersForOneShots();
369 stopTimersForWatchers(); 364 stopTimersForWatchers();
370 } 365 }
371 366
372 void Geolocation::cancelRequests(GeoNotifierVector& notifiers) 367 void Geolocation::cancelRequests(GeoNotifierVector& notifiers)
373 { 368 {
374 GeoNotifierVector::const_iterator end = notifiers.end(); 369 for (GeoNotifier* notifier : notifiers)
375 for (GeoNotifierVector::const_iterator it = notifiers.begin(); it != end; ++ it) 370 notifier->setFatalError(PositionError::create(PositionError::POSITION_UN AVAILABLE, framelessDocumentErrorMessage));
376 (*it)->setFatalError(PositionError::create(PositionError::POSITION_UNAVA ILABLE, framelessDocumentErrorMessage));
377 } 371 }
378 372
379 void Geolocation::cancelAllRequests() 373 void Geolocation::cancelAllRequests()
380 { 374 {
381 GeoNotifierVector copy; 375 GeoNotifierVector copy;
382 copyToVector(m_oneShots, copy); 376 copyToVector(m_oneShots, copy);
383 cancelRequests(copy); 377 cancelRequests(copy);
384 m_watchers.getNotifiersVector(copy); 378 m_watchers.getNotifiersVector(copy);
385 cancelRequests(copy); 379 cancelRequests(copy);
386 } 380 }
387 381
388 void Geolocation::extractNotifiersWithCachedPosition(GeoNotifierVector& notifier s, GeoNotifierVector* cached) 382 void Geolocation::extractNotifiersWithCachedPosition(GeoNotifierVector& notifier s, GeoNotifierVector* cached)
389 { 383 {
390 GeoNotifierVector nonCached; 384 GeoNotifierVector nonCached;
391 GeoNotifierVector::iterator end = notifiers.end(); 385 for (GeoNotifier* notifier : notifiers) {
392 for (GeoNotifierVector::const_iterator it = notifiers.begin(); it != end; ++ it) {
393 GeoNotifier* notifier = it->get();
394 if (notifier->useCachedPosition()) { 386 if (notifier->useCachedPosition()) {
395 if (cached) 387 if (cached)
396 cached->append(notifier); 388 cached->append(notifier);
397 } else 389 } else
398 nonCached.append(notifier); 390 nonCached.append(notifier);
399 } 391 }
400 notifiers.swap(nonCached); 392 notifiers.swap(nonCached);
401 } 393 }
402 394
403 void Geolocation::copyToSet(const GeoNotifierVector& src, GeoNotifierSet& dest) 395 void Geolocation::copyToSet(const GeoNotifierVector& src, GeoNotifierSet& dest)
404 { 396 {
405 GeoNotifierVector::const_iterator end = src.end(); 397 for (GeoNotifier* notifier : src)
406 for (GeoNotifierVector::const_iterator it = src.begin(); it != end; ++it) {
407 GeoNotifier* notifier = it->get();
408 dest.add(notifier); 398 dest.add(notifier);
409 }
410 } 399 }
411 400
412 void Geolocation::handleError(PositionError* error) 401 void Geolocation::handleError(PositionError* error)
413 { 402 {
414 ASSERT(error); 403 ASSERT(error);
415 404
416 GeoNotifierVector oneShotsCopy; 405 GeoNotifierVector oneShotsCopy;
417 copyToVector(m_oneShots, oneShotsCopy); 406 copyToVector(m_oneShots, oneShotsCopy);
418 407
419 GeoNotifierVector watchersCopy; 408 GeoNotifierVector watchersCopy;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 LocalFrame* frame = this->frame(); 507 LocalFrame* frame = this->frame();
519 if (!frame) 508 if (!frame)
520 return; 509 return;
521 510
522 GeolocationController::from(frame)->removeObserver(this); 511 GeolocationController::from(frame)->removeObserver(this);
523 } 512 }
524 513
525 void Geolocation::handlePendingPermissionNotifiers() 514 void Geolocation::handlePendingPermissionNotifiers()
526 { 515 {
527 // While we iterate through the list, we need not worry about list being mod ified as the permission 516 // While we iterate through the list, we need not worry about list being mod ified as the permission
528 // is already set to Yes/No and no new listeners will be added to the pendin g list 517 // is already set to Yes/No and no new listeners will be added to the pendin g list.
529 GeoNotifierSet::const_iterator end = m_pendingForPermissionNotifiers.end(); 518 for (GeoNotifier* notifier : m_pendingForPermissionNotifiers) {
530 for (GeoNotifierSet::const_iterator iter = m_pendingForPermissionNotifiers.b egin(); iter != end; ++iter) {
531 GeoNotifier* notifier = iter->get();
532
533 if (isAllowed()) { 519 if (isAllowed()) {
534 // start all pending notification requests as permission granted. 520 // start all pending notification requests as permission granted.
535 // The notifier is always ref'ed by m_oneShots or m_watchers. 521 // The notifier is always ref'ed by m_oneShots or m_watchers.
536 if (startUpdating(notifier)) 522 if (startUpdating(notifier))
537 notifier->startTimer(); 523 notifier->startTimer();
538 else 524 else
539 notifier->setFatalError(PositionError::create(PositionError::POS ITION_UNAVAILABLE, failedToStartServiceErrorMessage)); 525 notifier->setFatalError(PositionError::create(PositionError::POS ITION_UNAVAILABLE, failedToStartServiceErrorMessage));
540 } else { 526 } else {
541 notifier->setFatalError(PositionError::create(PositionError::PERMISS ION_DENIED, permissionDeniedErrorMessage)); 527 notifier->setFatalError(PositionError::create(PositionError::PERMISS ION_DENIED, permissionDeniedErrorMessage));
542 } 528 }
543 } 529 }
544 } 530 }
545 531
546 } // namespace blink 532 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698