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 CHROME_BROWSER_CHROMEOS_GEOLOCATION_SIMPLE_GEOLOCATION_REQUEST_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_GEOLOCATION_SIMPLE_GEOLOCATION_REQUEST_H_ |
6 #define CHROME_BROWSER_CHROMEOS_GEOLOCATION_SIMPLE_GEOLOCATION_REQUEST_H_ | 6 #define CHROME_BROWSER_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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 const GURL& service_url, | 48 const GURL& service_url, |
49 base::TimeDelta timeout); | 49 base::TimeDelta timeout); |
50 | 50 |
51 virtual ~SimpleGeolocationRequest(); | 51 virtual ~SimpleGeolocationRequest(); |
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( |
| 59 const base::TimeDelta value) { |
| 60 retry_sleep_on_server_error_ = value; |
| 61 } |
| 62 |
| 63 void set_retry_sleep_on_bad_response_for_testing( |
| 64 const base::TimeDelta value) { |
| 65 retry_sleep_on_bad_response_ = value; |
| 66 } |
| 67 |
58 private: | 68 private: |
59 // net::URLFetcherDelegate | 69 // net::URLFetcherDelegate |
60 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 70 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
61 | 71 |
62 // Start new request. | 72 // Start new request. |
63 void StartRequest(); | 73 void StartRequest(); |
64 | 74 |
65 // Schedules retry. | 75 // Schedules retry. |
66 void Retry(bool server_error); | 76 void Retry(bool server_error); |
67 | 77 |
(...skipping 11 matching lines...) Expand all Loading... |
79 ResponseCallback callback_; | 89 ResponseCallback callback_; |
80 | 90 |
81 // Actual URL with parameters. | 91 // Actual URL with parameters. |
82 GURL request_url_; | 92 GURL request_url_; |
83 | 93 |
84 scoped_ptr<net::URLFetcher> url_fetcher_; | 94 scoped_ptr<net::URLFetcher> url_fetcher_; |
85 | 95 |
86 // When request was actually started. | 96 // When request was actually started. |
87 base::Time request_started_at_; | 97 base::Time request_started_at_; |
88 | 98 |
| 99 base::TimeDelta retry_sleep_on_server_error_; |
| 100 |
| 101 base::TimeDelta retry_sleep_on_bad_response_; |
| 102 |
89 const base::TimeDelta timeout_; | 103 const base::TimeDelta timeout_; |
90 | 104 |
91 // Pending retry. | 105 // Pending retry. |
92 base::OneShotTimer<SimpleGeolocationRequest> request_scheduled_; | 106 base::OneShotTimer<SimpleGeolocationRequest> request_scheduled_; |
93 | 107 |
94 // Stop request on timeout. | 108 // Stop request on timeout. |
95 base::OneShotTimer<SimpleGeolocationRequest> timeout_timer_; | 109 base::OneShotTimer<SimpleGeolocationRequest> timeout_timer_; |
96 | 110 |
97 // Number of retry attempts. | 111 // Number of retry attempts. |
98 unsigned retries_; | 112 unsigned retries_; |
99 | 113 |
100 // This is updated on each retry. | 114 // This is updated on each retry. |
101 Geoposition position_; | 115 Geoposition position_; |
102 | 116 |
103 // Creation and destruction should happen on the same thread. | 117 // Creation and destruction should happen on the same thread. |
104 base::ThreadChecker thread_checker_; | 118 base::ThreadChecker thread_checker_; |
105 | 119 |
106 DISALLOW_COPY_AND_ASSIGN(SimpleGeolocationRequest); | 120 DISALLOW_COPY_AND_ASSIGN(SimpleGeolocationRequest); |
107 }; | 121 }; |
108 | 122 |
109 } // namespace chromeos | 123 } // namespace chromeos |
110 | 124 |
111 #endif // CHROME_BROWSER_CHROMEOS_GEOLOCATION_SIMPLE_GEOLOCATION_REQUEST_H_ | 125 #endif // CHROME_BROWSER_CHROMEOS_GEOLOCATION_SIMPLE_GEOLOCATION_REQUEST_H_ |
OLD | NEW |