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

Unified 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, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | content/browser/geolocation/geolocation_observer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/geolocation/geolocation.cc
diff --git a/content/browser/geolocation/geolocation.cc b/content/browser/geolocation/geolocation.cc
index 920ab3130d978aee16f381eea4e4c28fc37ff391..fbc0828121eb2e100b9a7464add56e96ec7d1647 100644
--- a/content/browser/geolocation/geolocation.cc
+++ b/content/browser/geolocation/geolocation.cc
@@ -7,6 +7,7 @@
#include "base/bind.h"
#include "base/callback.h"
#include "base/location.h"
+#include "base/logging.h"
#include "base/memory/ref_counted.h"
#include "base/message_loop_proxy.h"
#include "content/browser/geolocation/geolocation_provider.h"
@@ -21,10 +22,33 @@ void OverrideLocationForTestingOnIOThread(
const Geoposition& position,
const base::Closure& completion_callback,
scoped_refptr<base::MessageLoopProxy> callback_loop) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
GeolocationProvider::GetInstance()->OverrideLocationForTesting(position);
callback_loop->PostTask(FROM_HERE, completion_callback);
}
+void GeolocationUpdateCallbackOnIOThread(
+ const GeolocationUpdateCallback& client_callback,
+ scoped_refptr<base::MessageLoopProxy> client_loop,
+ const Geoposition& position) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ if (base::MessageLoopProxy::current() != client_loop)
+ client_loop->PostTask(FROM_HERE, base::Bind(client_callback, position));
+ else
+ client_callback.Run(position);
+}
+
+void RequestLocationUpdateOnIOThread(
+ const GeolocationUpdateCallback& client_callback,
+ scoped_refptr<base::MessageLoopProxy> client_loop) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ GeolocationUpdateCallback io_thread_callback = base::Bind(
+ &GeolocationUpdateCallbackOnIOThread,
+ client_callback,
+ client_loop);
+ GeolocationProvider::GetInstance()->RequestCallback(io_thread_callback);
+}
+
} // namespace
void OverrideLocationForTesting(
@@ -34,11 +58,20 @@ void OverrideLocationForTesting(
position,
completion_callback,
base::MessageLoopProxy::current());
- if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
+ if (!BrowserThread::CurrentlyOn(BrowserThread::IO))
+ BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, closure);
+ else
+ closure.Run();
+}
+
+void RequestLocationUpdate(const GeolocationUpdateCallback& callback) {
+ base::Closure closure = base::Bind(&RequestLocationUpdateOnIOThread,
+ callback,
+ base::MessageLoopProxy::current());
+ if (!BrowserThread::CurrentlyOn(BrowserThread::IO))
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, closure);
- } else {
+ else
closure.Run();
- }
}
} // namespace content
« 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