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

Side by Side Diff: chrome/browser/geolocation/network_location_request.h

Issue 552250: Port the gears geolocation network provider to Chromium... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2008, Google Inc. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // 2 // Use of this source code is governed by a BSD-style license that can be
3 // Redistribution and use in source and binary forms, with or without 3 // found in the LICENSE file.
4 // modification, are permitted provided that the following conditions are met:
5 //
6 // 1. Redistributions of source code must retain the above copyright notice,
7 // this list of conditions and the following disclaimer.
8 // 2. Redistributions in binary form must reproduce the above copyright notice,
9 // this list of conditions and the following disclaimer in the documentation
10 // and/or other materials provided with the distribution.
11 // 3. Neither the name of Google Inc. nor the names of its contributors may be
12 // used to endorse or promote products derived from this software without
13 // specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
16 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
18 // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 4
26 #ifndef GEARS_GEOLOCATION_NETWORK_LOCATION_REQUEST_H__ 5 #ifndef CHROME_BROWSER_GEOLOCATION_NETWORK_LOCATION_REQUEST_H_
27 #define GEARS_GEOLOCATION_NETWORK_LOCATION_REQUEST_H__ 6 #define CHROME_BROWSER_GEOLOCATION_NETWORK_LOCATION_REQUEST_H_
28 7
29 // TODO(joth): port to chromium 8 #include <string>
30 #if 0 9 #include "base/basictypes.h"
10 #include "base/ref_counted.h"
11 #include "chrome/browser/geolocation/device_data_provider.h"
12 #include "chrome/browser/net/url_fetcher.h"
13 #include "googleurl/src/gurl.h"
31 14
32 #include <vector> 15 struct Position;
33 #include "gears/base/common/basictypes.h" // For int64 16 class URLRequestContextGetter;
34 #include "gears/base/common/common.h" 17 class URLFetcher;
35 #include "gears/base/common/event.h"
36 #include "gears/blob/blob.h"
37 #include "gears/geolocation/geolocation.h"
38 #include "gears/geolocation/device_data_provider.h"
39 #include "gears/localserver/common/async_task.h"
40 18
41 // An implementation of an AsyncTask that takes a set of device data and sends 19 // Takes a set of device data and sends it to a server to get a position fix.
42 // it to a server to get a position fix. It performs formatting of the request 20 // It performs formatting of the request and interpretation of the response.
43 // and interpretation of the response. 21 class NetworkLocationRequest : private URLFetcher::Delegate {
44 class NetworkLocationRequest : public AsyncTask {
45 public: 22 public:
46 friend class scoped_ptr<NetworkLocationRequest>; // For use in Create().
47
48 // Interface for receiving callbacks from a NetworkLocationRequest object. 23 // Interface for receiving callbacks from a NetworkLocationRequest object.
49 class ListenerInterface { 24 class ListenerInterface {
50 public: 25 public:
51 // Updates the listener with a new position. server_error indicates whether 26 // Updates the listener with a new position. server_error indicates whether
52 // was a server or network error - either no response or a 500 error code. 27 // was a server or network error - either no response or a 500 error code.
53 virtual void LocationResponseAvailable( 28 virtual void LocationResponseAvailable(
54 const Position &position, 29 const Position& position,
55 bool server_error, 30 bool server_error,
56 const std::string16 &access_token) = 0; 31 const string16& access_token) = 0;
32
33 protected:
34 virtual ~ListenerInterface() {}
57 }; 35 };
58 36
59 // Creates the object and starts its worker thread running. Returns NULL if 37 // |url| is the server address to which the request wil be sent, |host_name|
60 // creation or initialisation fails. 38 // is the host of the webpage that caused this request.
61 static NetworkLocationRequest* Create(BrowsingContext *browsing_context, 39 // TODO(joth): is host needed? What to do when we reuse cached locations?
62 const std::string16 &url, 40 NetworkLocationRequest(URLRequestContextGetter* context,
63 const std::string16 &host_name, 41 const GURL& url,
64 ListenerInterface *listener); 42 const string16& host_name,
65 bool MakeRequest(const std::string16 &access_token, 43 ListenerInterface* listener);
66 const RadioData &radio_data, 44 virtual ~NetworkLocationRequest();
67 const WifiData &wifi_data, 45
68 bool request_address, 46 // Makes a new request. Returns true if the new request was successfully
69 const std::string16 &address_language, 47 // started. In all cases, any currently pending request will be canceled.
70 double latitude, 48 bool MakeRequest(const string16& access_token,
71 double longitude, 49 const RadioData& radio_data,
50 const WifiData& wifi_data,
72 int64 timestamp); 51 int64 timestamp);
73 // This method aborts any pending request and instructs the worker thread to 52
74 // terminate. The object is destructed once the thread terminates. This 53 bool is_request_pending() const { return url_fetcher_ != NULL; }
75 // method blocks until the AsyncTask::Run() implementation is complete, after 54 const GURL& url() const { return url_; }
76 // which the thread will not attempt to access external resources such as the
77 // listener.
78 void StopThreadAndDelete();
79 55
80 private: 56 private:
81 // Private constructor and destructor. Callers should use Create() and 57 // URLFetcher::Delegate
82 // StopThreadAndDelete(). 58 virtual void OnURLFetchComplete(const URLFetcher* source,
83 NetworkLocationRequest(BrowsingContext *browsing_context, 59 const GURL& url,
84 const std::string16 &url, 60 const URLRequestStatus& status,
85 const std::string16 &host_name, 61 int response_code,
86 ListenerInterface *listener); 62 const ResponseCookies& cookies,
87 virtual ~NetworkLocationRequest() {} 63 const std::string& data);
88 64
89 void MakeRequestImpl(); 65 scoped_refptr<URLRequestContextGetter> url_context_;
90
91 // AsyncTask implementation.
92 virtual void Run();
93
94 static bool FormRequestBody(const std::string16 &host_name,
95 const std::string16 &access_token,
96 const RadioData &radio_data,
97 const WifiData &wifi_data,
98 bool request_address,
99 std::string16 address_language,
100 double latitude,
101 double longitude,
102 bool is_reverse_geocode,
103 scoped_refptr<BlobInterface> *blob);
104
105 static void GetLocationFromResponse(bool http_post_result,
106 int status_code,
107 const std::string &response_body,
108 int64 timestamp,
109 const std::string16 &server_url,
110 bool is_reverse_geocode,
111 Position *position,
112 std::string16 *access_token);
113
114 int64 timestamp_; // The timestamp of the data used to make the request. 66 int64 timestamp_; // The timestamp of the data used to make the request.
115 scoped_refptr<BlobInterface> post_body_; 67 ListenerInterface* listener_;
116 ListenerInterface *listener_; 68 const GURL url_;
117 std::string16 url_; 69 string16 host_name_;
118 std::string16 host_name_; 70 scoped_ptr<URLFetcher> url_fetcher_;
119
120 Mutex is_processing_response_mutex_;
121
122 bool is_reverse_geocode_;
123
124 Event thread_event_;
125 bool is_shutting_down_;
126
127 #ifdef USING_CCTESTS
128 // Uses FormRequestBody for testing.
129 friend void TestGeolocationFormRequestBody(JsCallContext *context);
130 // Uses GetLocationFromResponse for testing.
131 friend void TestGeolocationGetLocationFromResponse(
132 JsCallContext *context,
133 JsRunnerInterface *js_runner);
134 #endif
135 71
136 DISALLOW_EVIL_CONSTRUCTORS(NetworkLocationRequest); 72 DISALLOW_EVIL_CONSTRUCTORS(NetworkLocationRequest);
137 }; 73 };
138 74
139 #endif // if 0 75 #endif // CHROME_BROWSER_GEOLOCATION_NETWORK_LOCATION_REQUEST_H_
140
141 #endif // GEARS_GEOLOCATION_NETWORK_LOCATION_REQUEST_H__
OLDNEW
« no previous file with comments | « chrome/browser/geolocation/network_location_provider.cc ('k') | chrome/browser/geolocation/network_location_request.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698