OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROMEOS_GEOLOCATION_SIMPLE_GEOLOCATION_REQUEST_H_ | 5 #ifndef CHROMEOS_GEOLOCATION_SIMPLE_GEOLOCATION_REQUEST_H_ |
6 #define CHROMEOS_GEOLOCATION_SIMPLE_GEOLOCATION_REQUEST_H_ | 6 #define CHROMEOS_GEOLOCATION_SIMPLE_GEOLOCATION_REQUEST_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 typedef base::Callback<void(const Geoposition& /* position*/, | 41 typedef base::Callback<void(const Geoposition& /* position*/, |
42 bool /* server_error */, | 42 bool /* server_error */, |
43 const base::TimeDelta elapsed)> ResponseCallback; | 43 const base::TimeDelta elapsed)> ResponseCallback; |
44 | 44 |
45 // |url| is the server address to which the request wil be sent. | 45 // |url| is the server address to which the request wil be sent. |
46 // |timeout| retry request on error until timeout. | 46 // |timeout| retry request on error until timeout. |
47 SimpleGeolocationRequest(net::URLRequestContextGetter* url_context_getter, | 47 SimpleGeolocationRequest(net::URLRequestContextGetter* url_context_getter, |
48 const GURL& service_url, | 48 const GURL& service_url, |
49 base::TimeDelta timeout); | 49 base::TimeDelta timeout); |
50 | 50 |
51 virtual ~SimpleGeolocationRequest(); | 51 ~SimpleGeolocationRequest() override; |
52 | 52 |
53 // Initiates request. | 53 // Initiates request. |
54 // Note: if request object is destroyed before callback is called, | 54 // Note: if request object is destroyed before callback is called, |
55 // request will be silently cancelled. | 55 // request will be silently cancelled. |
56 void MakeRequest(const ResponseCallback& callback); | 56 void MakeRequest(const ResponseCallback& callback); |
57 | 57 |
58 void set_retry_sleep_on_server_error_for_testing( | 58 void set_retry_sleep_on_server_error_for_testing( |
59 const base::TimeDelta value) { | 59 const base::TimeDelta value) { |
60 retry_sleep_on_server_error_ = value; | 60 retry_sleep_on_server_error_ = value; |
61 } | 61 } |
62 | 62 |
63 void set_retry_sleep_on_bad_response_for_testing( | 63 void set_retry_sleep_on_bad_response_for_testing( |
64 const base::TimeDelta value) { | 64 const base::TimeDelta value) { |
65 retry_sleep_on_bad_response_ = value; | 65 retry_sleep_on_bad_response_ = value; |
66 } | 66 } |
67 | 67 |
68 private: | 68 private: |
69 // net::URLFetcherDelegate | 69 // net::URLFetcherDelegate |
70 virtual void OnURLFetchComplete(const net::URLFetcher* source) override; | 70 void OnURLFetchComplete(const net::URLFetcher* source) override; |
71 | 71 |
72 // Start new request. | 72 // Start new request. |
73 void StartRequest(); | 73 void StartRequest(); |
74 | 74 |
75 // Schedules retry. | 75 // Schedules retry. |
76 void Retry(bool server_error); | 76 void Retry(bool server_error); |
77 | 77 |
78 // Run callback and destroy "this". | 78 // Run callback and destroy "this". |
79 void ReplyAndDestroySelf(const base::TimeDelta elapsed, bool server_error); | 79 void ReplyAndDestroySelf(const base::TimeDelta elapsed, bool server_error); |
80 | 80 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 | 116 |
117 // Creation and destruction should happen on the same thread. | 117 // Creation and destruction should happen on the same thread. |
118 base::ThreadChecker thread_checker_; | 118 base::ThreadChecker thread_checker_; |
119 | 119 |
120 DISALLOW_COPY_AND_ASSIGN(SimpleGeolocationRequest); | 120 DISALLOW_COPY_AND_ASSIGN(SimpleGeolocationRequest); |
121 }; | 121 }; |
122 | 122 |
123 } // namespace chromeos | 123 } // namespace chromeos |
124 | 124 |
125 #endif // CHROMEOS_GEOLOCATION_SIMPLE_GEOLOCATION_REQUEST_H_ | 125 #endif // CHROMEOS_GEOLOCATION_SIMPLE_GEOLOCATION_REQUEST_H_ |
OLD | NEW |