Location provider using Windows 7 Location API
Implementation of a location provider that uses the Windows 7 Location API. Currently uses polling to get the users location, I will update this to use signals provided by the API in a future patch.

BUG=45535
TEST=Two test files included.

Review URL: http://codereview.chromium.org/3015053

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56332 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/geolocation/gps_location_provider_linux.cc b/chrome/browser/geolocation/gps_location_provider_linux.cc
index 9c918a91..4b23ff2 100644
--- a/chrome/browser/geolocation/gps_location_provider_linux.cc
+++ b/chrome/browser/geolocation/gps_location_provider_linux.cc
@@ -121,6 +121,6 @@
       interval);
 }
 
-LocationProviderBase* NewGpsLocationProvider() {
+LocationProviderBase* NewSystemLocationProvider() {
   return new GpsLocationProviderLinux(LibGps::New);
 }
diff --git a/chrome/browser/geolocation/location_arbitrator.cc b/chrome/browser/geolocation/location_arbitrator.cc
index 050407b..bf47ed7 100644
--- a/chrome/browser/geolocation/location_arbitrator.cc
+++ b/chrome/browser/geolocation/location_arbitrator.cc
@@ -105,10 +105,10 @@
     return ::NewNetworkLocationProvider(access_token_store, context,
                                         url, access_token);
   }
-  virtual LocationProviderBase* NewGpsLocationProvider() {
+  virtual LocationProviderBase* NewSystemLocationProvider() {
     if (g_provider_factory_function_for_test)
       return NULL;
-    return ::NewGpsLocationProvider();
+    return ::NewSystemLocationProvider();
   }
 };
 
@@ -222,7 +222,7 @@
             i->first, i->second),
         &providers_);
   }
-  RegisterProvider(provider_factory_->NewGpsLocationProvider(),
+  RegisterProvider(provider_factory_->NewSystemLocationProvider(),
                    &providers_);
   StartProviders();
 }
@@ -255,9 +255,9 @@
   // Updates location_info if it's better than what we currently have,
   // or if it's a newer update from the same provider.
   if (!old_position.IsValidFix()) {
-      // Older location wasn't locked.
-      return true;
-    }
+    // Older location wasn't locked.
+    return true;
+  }
   if (new_position.IsValidFix()) {
     // New location is locked, let's check if it's any better.
     if (old_position.accuracy >= new_position.accuracy) {
diff --git a/chrome/browser/geolocation/location_arbitrator.h b/chrome/browser/geolocation/location_arbitrator.h
index eeb2e9c..a4d166f 100644
--- a/chrome/browser/geolocation/location_arbitrator.h
+++ b/chrome/browser/geolocation/location_arbitrator.h
@@ -43,7 +43,7 @@
         URLRequestContextGetter* context,
         const GURL& url,
         const string16& access_token) = 0;
-    virtual LocationProviderBase* NewGpsLocationProvider() = 0;
+    virtual LocationProviderBase* NewSystemLocationProvider() = 0;
 
    protected:
     friend class base::RefCounted<ProviderFactory>;
diff --git a/chrome/browser/geolocation/location_arbitrator_unittest.cc b/chrome/browser/geolocation/location_arbitrator_unittest.cc
index 669ac454..76351ac 100644
--- a/chrome/browser/geolocation/location_arbitrator_unittest.cc
+++ b/chrome/browser/geolocation/location_arbitrator_unittest.cc
@@ -16,7 +16,7 @@
 class MockLocationObserver : public GeolocationArbitrator::Delegate {
  public:
   void InvalidateLastPosition() {
-    last_position_.accuracy = -1;
+    last_position_.latitude = 100;
     last_position_.error_code = Geoposition::ERROR_CODE_NONE;
     ASSERT_FALSE(last_position_.IsInitialized());
   }
@@ -40,7 +40,7 @@
       const string16& access_token) {
     return new MockLocationProvider(&cell_);
   }
-  virtual LocationProviderBase* NewGpsLocationProvider() {
+  virtual LocationProviderBase* NewSystemLocationProvider() {
     return new MockLocationProvider(&gps_);
   }
 
diff --git a/chrome/browser/geolocation/location_provider.cc b/chrome/browser/geolocation/location_provider.cc
index cdfd797..ecd066e1 100644
--- a/chrome/browser/geolocation/location_provider.cc
+++ b/chrome/browser/geolocation/location_provider.cc
@@ -56,9 +56,8 @@
   }
 }
 
-// Currently only Linux has a GPS provider.
-#if !defined(OS_LINUX)
-LocationProviderBase* NewGpsLocationProvider() {
+#if !defined(OS_LINUX) && !defined(OS_WIN)
+LocationProviderBase* NewSystemLocationProvider() {
   return NULL;
 }
 #endif
diff --git a/chrome/browser/geolocation/location_provider.h b/chrome/browser/geolocation/location_provider.h
index 08e191ef..6c4d8da 100644
--- a/chrome/browser/geolocation/location_provider.h
+++ b/chrome/browser/geolocation/location_provider.h
@@ -7,8 +7,8 @@
 // providers to obtain a position fix.
 //
 // This file declares a base class to be used by all location providers.
-// Primarily, this class declares interface methods to be implemented by derived
-// classes.
+// Primarily, this class declares interface methods to be implemented by
+// derived classes.
 
 #ifndef CHROME_BROWSER_GEOLOCATION_LOCATION_PROVIDER_H_
 #define CHROME_BROWSER_GEOLOCATION_LOCATION_PROVIDER_H_
@@ -85,13 +85,13 @@
   ListenerMap listeners_;
 };
 
-// Factory functions for the various types of location provider to abstract over
-// the platform-dependent implementations.
-LocationProviderBase* NewGpsLocationProvider();
+// Factory functions for the various types of location provider to abstract
+// over the platform-dependent implementations.
 LocationProviderBase* NewNetworkLocationProvider(
     AccessTokenStore* access_token_store,
     URLRequestContextGetter* context,
     const GURL& url,
     const string16& access_token);
+LocationProviderBase* NewSystemLocationProvider();
 
 #endif  // CHROME_BROWSER_GEOLOCATION_LOCATION_PROVIDER_H_
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 8c05212..45ed49f 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -1496,6 +1496,10 @@
         'browser/geolocation/wifi_data_provider_mac.h',
         'browser/geolocation/wifi_data_provider_win.cc',
         'browser/geolocation/wifi_data_provider_win.h',
+        'browser/geolocation/win7_location_api_win.cc',
+        'browser/geolocation/win7_location_api_win.h',
+        'browser/geolocation/win7_location_provider_win.cc',
+        'browser/geolocation/win7_location_provider_win.h',
         'browser/google_service_auth_error.h',
         'browser/google_update.cc',
         'browser/google_update.h',
@@ -3252,6 +3256,14 @@
           'export_dependent_settings': [
             '../views/views.gyp:views',
           ],
+          'direct_dependent_settings': {
+            'link_settings': {
+              'libraries': [
+                '-llocationapi.lib',
+                '-lsensorsapi.lib',
+              ],
+            }
+          },
           'sources': [
             'browser/net/ssl_config_service_manager_system.cc',
             # Using built-in rule in vstudio for midl.
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index ba62cf2..d7f5e26 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -962,6 +962,8 @@
         'browser/geolocation/wifi_data_provider_common_unittest.cc',
         'browser/geolocation/wifi_data_provider_unittest_chromeos.cc',
         'browser/geolocation/wifi_data_provider_unittest_win.cc',
+        'browser/geolocation/win7_location_api_unittest_win.cc',
+        'browser/geolocation/win7_location_provider_unittest_win.cc',
         'browser/global_keyboard_shortcuts_mac_unittest.mm',
         'browser/google_update_settings_unittest.cc',
         'browser/google_url_tracker_unittest.cc',
diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc
index 5a6b770..2242966 100644
--- a/chrome/common/chrome_switches.cc
+++ b/chrome/common/chrome_switches.cc
@@ -470,6 +470,9 @@
 // Order of the listed sub-arguments does not matter.
 const char kEnableWatchdog[]                = "enable-watchdog";
 
+// Enables Windows 7 Location Platform provider for geolocation API.
+const char kEnableWin7Location[]            = "enable-win7-location";
+
 // Disable WebKit's XSSAuditor.  The XSSAuditor mitigates reflective XSS.
 const char kEnableXSSAuditor[]              = "enable-xss-auditor";
 
diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h
index 8fa9a2dd..9ffd4443 100644
--- a/chrome/common/chrome_switches.h
+++ b/chrome/common/chrome_switches.h
@@ -149,6 +149,7 @@
 extern const char kEnableVideoLayering[];
 extern const char kEnableVideoLogging[];
 extern const char kEnableWatchdog[];
+extern const char kEnableWin7Location[];
 extern const char kEnableXSSAuditor[];
 // Experimental features.
 extern const char kExperimentalEnableNegotiateAuth[];