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

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: Put functions back into random order for easier reviewing. 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 void RequestLocationUpdateOnIOThread(
jam 2012/05/03 18:22:19 nit: blank line before
bartfab (slow) 2012/05/04 08:30:22 Done.
41 const GeolocationUpdateCallback& client_callback,
42 scoped_refptr<base::MessageLoopProxy> client_loop) {
43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
44 GeolocationUpdateCallback io_thread_callback = base::Bind(
45 &GeolocationUpdateCallbackOnIOThread,
46 client_callback,
47 client_loop);
48 GeolocationProvider::GetInstance()->RequestCallback(io_thread_callback);
49 }
50
28 } // namespace 51 } // namespace
29 52
30 void OverrideLocationForTesting( 53 void OverrideLocationForTesting(const Geoposition& position,
jam 2012/05/03 18:22:19 nit: no need to change the style in this function.
bartfab (slow) 2012/05/04 08:30:22 The intention was not to enforce one style over an
31 const Geoposition& position, 54 const base::Closure& completion_callback) {
32 const base::Closure& completion_callback) {
33 base::Closure closure = base::Bind(&OverrideLocationForTestingOnIOThread, 55 base::Closure closure = base::Bind(&OverrideLocationForTestingOnIOThread,
34 position, 56 position,
35 completion_callback, 57 completion_callback,
36 base::MessageLoopProxy::current()); 58 base::MessageLoopProxy::current());
37 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { 59 if (!BrowserThread::CurrentlyOn(BrowserThread::IO))
38 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, closure); 60 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, closure);
39 } else { 61 else
40 closure.Run(); 62 closure.Run();
41 } 63 }
64
65 void RequestLocationUpdate(const GeolocationUpdateCallback& callback) {
66 base::Closure closure = base::Bind(&RequestLocationUpdateOnIOThread,
67 callback,
68 base::MessageLoopProxy::current());
69 if (!BrowserThread::CurrentlyOn(BrowserThread::IO))
70 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, closure);
71 else
72 closure.Run();
42 } 73 }
43 74
44 } // namespace content 75 } // 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