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

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: Rebased. 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
Index: content/browser/geolocation/geolocation.cc
diff --git a/content/browser/geolocation/geolocation.cc b/content/browser/geolocation/geolocation.cc
index 920ab3130d978aee16f381eea4e4c28fc37ff391..74ba782d39d0d1285a29146bee4517618b3051f8 100644
--- a/content/browser/geolocation/geolocation.cc
+++ b/content/browser/geolocation/geolocation.cc
@@ -7,7 +7,9 @@
#include "base/bind.h"
#include "base/callback.h"
#include "base/location.h"
+#include "base/logging.h"
#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
#include "base/message_loop_proxy.h"
#include "content/browser/geolocation/geolocation_provider.h"
#include "content/public/browser/browser_thread.h"
@@ -17,28 +19,69 @@ namespace content {
namespace {
+scoped_ptr<Geoposition> callback_override_position;
+
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(
- const Geoposition& position,
- const base::Closure& completion_callback) {
+void OverrideLocationForTesting(const Geoposition& position,
+ const base::Closure& completion_callback) {
base::Closure closure = base::Bind(&OverrideLocationForTestingOnIOThread,
position,
completion_callback,
base::MessageLoopProxy::current());
- if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
+ if (!BrowserThread::CurrentlyOn(BrowserThread::IO))
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, closure);
- } else {
+ else
closure.Run();
+}
+void OverrideCallbackLocationForTesting(Geoposition* position) {
+ callback_override_position.reset(position);
+}
+
+void RequestLocationUpdate(const GeolocationUpdateCallback& callback) {
+ // Only used for testing.
+ if (callback_override_position.get()) {
+ callback.Run(*callback_override_position.get());
+ return;
}
+
+ base::Closure closure = base::Bind(&RequestLocationUpdateOnIOThread,
+ callback,
+ base::MessageLoopProxy::current());
+ if (!BrowserThread::CurrentlyOn(BrowserThread::IO))
+ BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, closure);
+ else
+ closure.Run();
}
} // namespace content
« no previous file with comments | « no previous file | content/browser/geolocation/geolocation_observer.h » ('j') | content/public/browser/geolocation.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698