What's new? | Help | Directory | Sign in
Google
gears
Improving Your Web Browser
  
  
  
    
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Copyright 2008, Google Inc.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// 3. Neither the name of Google Inc. nor the names of its contributors may be
// used to endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#ifndef GEARS_GEOLOCATION_NETWORK_LOCATION_REQUEST_H__
#define GEARS_GEOLOCATION_NETWORK_LOCATION_REQUEST_H__

#include "gears/base/common/basictypes.h" // For int64
#include "gears/base/common/common.h"
#include "gears/base/common/event.h"
#include "gears/blob/blob.h"
#include "gears/geolocation/geolocation.h"
#include "gears/geolocation/device_data_provider.h"
#include "gears/localserver/common/async_task.h"
#include <vector>

// An implementation of an AsyncTask that takes a set of device data and sends
// it to a server to get a position fix. It performs formatting of the request
// and interpretation of the response.
class NetworkLocationRequest : public AsyncTask {
public:
// Interface for receiving callbacks from a NetworkLocationRequest object.
class ListenerInterface {
public:
// Updates the listener with a new position. server_error indicates whether
// was a server or network error - either no response or a 500 error code.
virtual void LocationResponseAvailable(const Position &position,
bool server_error) = 0;
};

static NetworkLocationRequest* Create(const std::string16 &url,
const std::string16 &host_name,
ListenerInterface *listener);
bool MakeRequest(const RadioData &radio_data,
const WifiData &wifi_data,
bool request_address,
std::string16 address_language,
double latitude,
double longitude,
int64 timestamp);
// This method aborts any pending request and instructs the worker thread to
// terminate. The object is destructed once the thread terminates. This
// method blocks until the AsyncTask::Run() implementation is complete, after
// which the thread will not attempt to access external resources such as the
// listener.
void StopThreadAndDelete();

private:
// Private constructor and destructor. Callers should use Create() and
// StopThreadAndDelete().
NetworkLocationRequest(const std::string16 &url,
const std::string16 &host_name,
ListenerInterface *listener);
virtual ~NetworkLocationRequest() {}
// AsyncTask implementation.
virtual void Run();

static bool FormRequestBody(const std::string16 &host_name,
const RadioData &radio_data,
const WifiData &wifi_data,
bool request_address,
std::string16 address_language,
double latitude,
double longitude,
scoped_refptr<BlobInterface> *blob);

static void GetLocationFromResponse(bool http_post_result,
int status_code,
const std::string &response_body,
int64 timestamp,
std::string16 server_url,
Position *position);

int64 timestamp_; // The timestamp of the data used to make the request.
scoped_refptr<BlobInterface> post_body_;
ListenerInterface *listener_;
std::string16 url_;
std::string16 host_name_;

Mutex is_processing_response_mutex_;

#ifdef USING_CCTESTS
// Uses FormRequestBody for testing.
friend void TestGeolocationFormRequestBody(JsCallContext *context);
// Uses GetLocationFromResponse for testing.
friend void TestGeolocationGetLocationFromResponse(
JsCallContext *context,
JsRunnerInterface *js_runner);
#endif

DISALLOW_EVIL_CONSTRUCTORS(NetworkLocationRequest);
};

#endif // GEARS_GEOLOCATION_NETWORK_LOCATION_REQUEST_H__
Show details Hide details

Change log

r2417 by gears.daemon on Jul 18 (5 days ago)   Diff
[Author: steveblock]

Adds exponential back-off for Geolocation
network requests.

R=andreip
CC=gears-eng@googlegroups.com
DELTA=125  (97 added, 17 deleted, 11
changed)
OCL=7684706
SCL=7746590
Go to: 
Project members, sign in to write a code review

Older revisions

r2201 by gears.daemon on Jul 01, 2008   Diff
[Author: steveblock]

Adds some tests for extracting a
position from a location server
response.
...
r1973 by gears.daemon on Jun 16, 2008   Diff
[Author: steveblock]

Bug fix in Geolocation
NetworkLocationRequest.

...
r1721 by gears.daemon on May 20, 2008   Diff
[Author: steveblock]

Updates Geolocation options fields and
network protocol.

...
All revisions of this file

File info

Size: 5310 bytes, 115 lines