Updates the mic icon status based on the device's audio state (2nd)
[chromium-blink-merge.git] / chrome / browser / chromeos / geolocation / simple_geolocation_provider.cc
blob3d4dba3fe69211e26cfb68f706776481013ec423
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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/geolocation/simple_geolocation_provider.h"
7 #include <algorithm>
8 #include <iterator>
10 #include "base/bind.h"
11 #include "base/time/time.h"
12 #include "chrome/browser/chromeos/geolocation/geoposition.h"
13 #include "net/url_request/url_request_context_getter.h"
14 #include "url/gurl.h"
16 namespace chromeos {
18 namespace {
19 const char kDefaultGeolocationProviderUrl[] =
20 "https://www.googleapis.com/geolocation/v1/geolocate?";
21 } // namespace
23 SimpleGeolocationProvider::SimpleGeolocationProvider(
24 net::URLRequestContextGetter* url_context_getter,
25 const GURL& url)
26 : url_context_getter_(url_context_getter), url_(url) {
29 SimpleGeolocationProvider::~SimpleGeolocationProvider() {
30 DCHECK(thread_checker_.CalledOnValidThread());
33 void SimpleGeolocationProvider::RequestGeolocation(
34 base::TimeDelta timeout,
35 SimpleGeolocationRequest::ResponseCallback callback) {
36 DCHECK(thread_checker_.CalledOnValidThread());
37 SimpleGeolocationRequest* request(
38 new SimpleGeolocationRequest(url_context_getter_.get(), url_, timeout));
39 requests_.push_back(request);
41 // SimpleGeolocationProvider owns all requests. It is safe to pass unretained
42 // "this" because destruction of SimpleGeolocationProvider cancels all
43 // requests.
44 SimpleGeolocationRequest::ResponseCallback callback_tmp(
45 base::Bind(&SimpleGeolocationProvider::OnGeolocationResponse,
46 base::Unretained(this),
47 request,
48 callback));
49 request->MakeRequest(callback_tmp);
52 // static
53 GURL SimpleGeolocationProvider::DefaultGeolocationProviderURL() {
54 return GURL(kDefaultGeolocationProviderUrl);
57 void SimpleGeolocationProvider::OnGeolocationResponse(
58 SimpleGeolocationRequest* request,
59 SimpleGeolocationRequest::ResponseCallback callback,
60 const Geoposition& geoposition,
61 bool server_error,
62 const base::TimeDelta elapsed) {
63 DCHECK(thread_checker_.CalledOnValidThread());
65 callback.Run(geoposition, server_error, elapsed);
67 ScopedVector<SimpleGeolocationRequest>::iterator new_end =
68 std::remove(requests_.begin(), requests_.end(), request);
69 DCHECK_EQ(std::distance(new_end, requests_.end()), 1);
70 requests_.erase(new_end, requests_.end());
73 } // namespace chromeos