OLD | NEW |
---|---|
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)) { |
John Knottenbelt
2012/05/04 10:16:58
Please remove the curly braces here (or add them i
bartfab (slow)
2012/05/04 10:35:58
I had removed the braces. jam@ requested that I ad
| |
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 } |
42 } | 66 } |
43 | 67 |
68 void RequestLocationUpdate(const GeolocationUpdateCallback& callback) { | |
69 base::Closure closure = base::Bind(&RequestLocationUpdateOnIOThread, | |
70 callback, | |
71 base::MessageLoopProxy::current()); | |
72 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) | |
73 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, closure); | |
74 else | |
75 closure.Run(); | |
76 } | |
77 | |
44 } // namespace content | 78 } // namespace content |
OLD | NEW |