18e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul// Copyright 2014 The Chromium Authors. All rights reserved. 28e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul// Use of this source code is governed by a BSD-style license that can be 3a9bcf751030895494fc098f8d0ff56b2496bd993Brian Paul// found in the LICENSE file. 48e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 5ef8653a83800bc4b8e116e03ad52604097224378Brian Paul#ifndef CHROME_BROWSER_CHROMEOS_GEOLOCATION_SIMPLE_GEOLOCATION_PROVIDER_H_ 68e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul#define CHROME_BROWSER_CHROMEOS_GEOLOCATION_SIMPLE_GEOLOCATION_PROVIDER_H_ 78e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 88e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul#include "base/macros.h" 98e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul#include "base/memory/ref_counted.h" 108e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul#include "base/memory/scoped_vector.h" 118e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul#include "base/threading/thread_checker.h" 128e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul#include "base/time/time.h" 138e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul#include "chrome/browser/chromeos/geolocation/simple_geolocation_request.h" 148e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul#include "url/gurl.h" 158e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 168e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulnamespace net { 178e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulclass URLRequestContextGetter; 188e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul} 198e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 208e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulnamespace chromeos { 218e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 228e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul// This class implements Google Maps Geolocation API. 238e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul// 248e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul// SimpleGeolocationProvider must be created and used on the same thread. 258e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul// 268e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul// Note: this should probably be a singleton to monitor requests rate. 278e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul// But as it is used only diring ChromeOS Out-of-Box, it can be owned by 288e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul// WizardController for now. 298e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paulclass SimpleGeolocationProvider { 30248200737398a7d6403a23930a6c9d93db06b942Brian Paul public: 3189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul SimpleGeolocationProvider(net::URLRequestContextGetter* url_context_getter, 3289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul const GURL& url); 3389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul virtual ~SimpleGeolocationProvider(); 3489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul // Initiates new request (See SimpleGeolocationRequest for parameters 3689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul // description.) 3789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul void RequestGeolocation(base::TimeDelta timeout, 3889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul SimpleGeolocationRequest::ResponseCallback callback); 3989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 4089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul // Returns default geolocation service URL. 4189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul static GURL DefaultGeolocationProviderURL(); 4289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 4389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul private: 4489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul friend class TestGeolocationAPIURLFetcherCallback; 4589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 4689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul // Geolocation response callback. Deletes request from requests_. 4789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul void OnGeolocationResponse( 4889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul SimpleGeolocationRequest* request, 4989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul SimpleGeolocationRequest::ResponseCallback callback, 5089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul const Geoposition& geoposition, 5189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul bool server_error, 5289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul const base::TimeDelta elapsed); 5389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 543c63452e64df7e10aa073c6c3b9492b1d7dabbb8Brian Paul scoped_refptr<net::URLRequestContextGetter> url_context_getter_; 557a6b71ef2944bae1718e8167b2faaceb8422071cBrian Paul 56e75d2424e53d6023f4414e40694cd467e5392b96Brian Paul // URL of the Google Maps Geolocation API. 578e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul const GURL url_; 588e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 598e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul // Requests in progress. 608e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul // SimpleGeolocationProvider owns all requests, so this vector is deleted on 6124edd9015951dd41898902b6c3973fe605e5871aBrian Paul // destroy. 623c63452e64df7e10aa073c6c3b9492b1d7dabbb8Brian Paul ScopedVector<SimpleGeolocationRequest> requests_; 6389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 64371ef9c058b0d59bfb62689b64af1b29a2214d9eGareth Hughes // Creation and destruction should happen on the same thread. 658e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul base::ThreadChecker thread_checker_; 668e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul 672e5c686c2b6f356895f33b2815e41386946ab55aKeith Whitwell DISALLOW_COPY_AND_ASSIGN(SimpleGeolocationProvider); 688e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul}; 69248200737398a7d6403a23930a6c9d93db06b942Brian Paul 70fce0d13b4fff04de50fd91a8f4dfdc248b6262e0Keith Whitwell} // namespace chromeos 71fce0d13b4fff04de50fd91a8f4dfdc248b6262e0Keith Whitwell 72fce0d13b4fff04de50fd91a8f4dfdc248b6262e0Keith Whitwell#endif // CHROME_BROWSER_CHROMEOS_GEOLOCATION_SIMPLE_GEOLOCATION_PROVIDER_H_ 73fce0d13b4fff04de50fd91a8f4dfdc248b6262e0Keith Whitwell