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

Side by Side Diff: content/browser/geolocation/geolocation.cc

Issue 10344004: Add content API for requesting the current geolocation (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: *Argh*, missed another forward declaration of a struct as a class. Created 8 years, 7 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
« no previous file with comments | « no previous file | content/browser/geolocation/geolocation_observer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "content/public/browser/geolocation.h" 5 #include "content/public/browser/geolocation.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/logging.h"
10 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
11 #include "base/message_loop_proxy.h" 12 #include "base/message_loop_proxy.h"
12 #include "content/browser/geolocation/geolocation_provider.h" 13 #include "content/browser/geolocation/geolocation_provider.h"
13 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
14 #include "content/public/common/geoposition.h" 15 #include "content/public/common/geoposition.h"
15 16
16 namespace content { 17 namespace content {
17 18
18 namespace { 19 namespace {
19 20
20 void OverrideLocationForTestingOnIOThread( 21 void OverrideLocationForTestingOnIOThread(
21 const Geoposition& position, 22 const Geoposition& position,
22 const base::Closure& completion_callback, 23 const base::Closure& completion_callback,
23 scoped_refptr<base::MessageLoopProxy> callback_loop) { 24 scoped_refptr<base::MessageLoopProxy> callback_loop) {
25 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
24 GeolocationProvider::GetInstance()->OverrideLocationForTesting(position); 26 GeolocationProvider::GetInstance()->OverrideLocationForTesting(position);
25 callback_loop->PostTask(FROM_HERE, completion_callback); 27 callback_loop->PostTask(FROM_HERE, completion_callback);
26 } 28 }
27 29
30 void GeolocationUpdateCallbackOnIOThread(
31 const GeolocationUpdateCallback& client_callback,
32 scoped_refptr<base::MessageLoopProxy> client_loop,
33 const Geoposition& position) {
34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
35 if (base::MessageLoopProxy::current() != client_loop)
36 client_loop->PostTask(FROM_HERE, base::Bind(client_callback, position));
37 else
38 client_callback.Run(position);
39 }
40
41 void RequestLocationUpdateOnIOThread(
42 const GeolocationUpdateCallback& client_callback,
43 scoped_refptr<base::MessageLoopProxy> client_loop) {
44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
45 GeolocationUpdateCallback io_thread_callback = base::Bind(
46 &GeolocationUpdateCallbackOnIOThread,
47 client_callback,
48 client_loop);
49 GeolocationProvider::GetInstance()->RequestCallback(io_thread_callback);
50 }
51
28 } // namespace 52 } // namespace
29 53
30 void OverrideLocationForTesting( 54 void OverrideLocationForTesting(
31 const Geoposition& position, 55 const Geoposition& position,
32 const base::Closure& completion_callback) { 56 const base::Closure& completion_callback) {
33 base::Closure closure = base::Bind(&OverrideLocationForTestingOnIOThread, 57 base::Closure closure = base::Bind(&OverrideLocationForTestingOnIOThread,
34 position, 58 position,
35 completion_callback, 59 completion_callback,
36 base::MessageLoopProxy::current()); 60 base::MessageLoopProxy::current());
37 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { 61 if (!BrowserThread::CurrentlyOn(BrowserThread::IO))
38 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, closure); 62 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, closure);
39 } else { 63 else
40 closure.Run(); 64 closure.Run();
41 } 65 }
66
67 void RequestLocationUpdate(const GeolocationUpdateCallback& callback) {
68 base::Closure closure = base::Bind(&RequestLocationUpdateOnIOThread,
69 callback,
70 base::MessageLoopProxy::current());
71 if (!BrowserThread::CurrentlyOn(BrowserThread::IO))
72 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, closure);
73 else
74 closure.Run();
42 } 75 }
43 76
44 } // namespace content 77 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/geolocation/geolocation_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698