OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Library functions related to the Financial Server ping. | 5 // Library functions related to the Financial Server ping. |
6 | 6 |
7 #include "rlz/lib/financial_ping.h" | 7 #include "rlz/lib/financial_ping.h" |
8 | 8 |
9 #include "base/atomicops.h" | 9 #include "base/atomicops.h" |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 } | 181 } |
182 | 182 |
183 #if defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET) | 183 #if defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET) |
184 // The pointer to URLRequestContextGetter used by FinancialPing::PingServer(). | 184 // The pointer to URLRequestContextGetter used by FinancialPing::PingServer(). |
185 // It is atomic pointer because it can be accessed and modified by multiple | 185 // It is atomic pointer because it can be accessed and modified by multiple |
186 // threads. | 186 // threads. |
187 AtomicWord g_context; | 187 AtomicWord g_context; |
188 | 188 |
189 bool FinancialPing::SetURLRequestContext( | 189 bool FinancialPing::SetURLRequestContext( |
190 net::URLRequestContextGetter* context) { | 190 net::URLRequestContextGetter* context) { |
191 base::subtle::NoBarrier_Store( | 191 base::subtle::Release_Store( |
192 &g_context, reinterpret_cast<AtomicWord>(context)); | 192 &g_context, reinterpret_cast<AtomicWord>(context)); |
193 return true; | 193 return true; |
194 } | 194 } |
195 | 195 |
196 namespace { | 196 namespace { |
197 | 197 |
198 class FinancialPingUrlFetcherDelegate : public net::URLFetcherDelegate { | 198 class FinancialPingUrlFetcherDelegate : public net::URLFetcherDelegate { |
199 public: | 199 public: |
200 FinancialPingUrlFetcherDelegate(const base::Closure& callback) | 200 FinancialPingUrlFetcherDelegate(const base::Closure& callback) |
201 : callback_(callback) { | 201 : callback_(callback) { |
202 } | 202 } |
203 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 203 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
204 | 204 |
205 private: | 205 private: |
206 base::Closure callback_; | 206 base::Closure callback_; |
207 }; | 207 }; |
208 | 208 |
209 void FinancialPingUrlFetcherDelegate::OnURLFetchComplete( | 209 void FinancialPingUrlFetcherDelegate::OnURLFetchComplete( |
210 const net::URLFetcher* source) { | 210 const net::URLFetcher* source) { |
211 callback_.Run(); | 211 callback_.Run(); |
212 } | 212 } |
213 | 213 |
214 bool send_financial_ping_interrupted_for_test = false; | 214 bool send_financial_ping_interrupted_for_test = false; |
215 | 215 |
216 } // namespace | 216 } // namespace |
217 | 217 |
218 void ShutdownCheck(base::WeakPtr<base::RunLoop> weak) { | 218 void ShutdownCheck(base::WeakPtr<base::RunLoop> weak) { |
219 if (!weak.get()) | 219 if (!weak.get()) |
220 return; | 220 return; |
221 if (!base::subtle::NoBarrier_Load(&g_context)) { | 221 if (!base::subtle::Acquire_Load(&g_context)) { |
222 send_financial_ping_interrupted_for_test = true; | 222 send_financial_ping_interrupted_for_test = true; |
223 weak->QuitClosure().Run(); | 223 weak->QuitClosure().Run(); |
224 return; | 224 return; |
225 } | 225 } |
226 // How frequently the financial ping thread should check | 226 // How frequently the financial ping thread should check |
227 // the shutdown condition? | 227 // the shutdown condition? |
228 const base::TimeDelta kInterval = base::TimeDelta::FromMilliseconds(500); | 228 const base::TimeDelta kInterval = base::TimeDelta::FromMilliseconds(500); |
229 base::MessageLoop::current()->PostDelayedTask( | 229 base::MessageLoop::current()->PostDelayedTask( |
230 FROM_HERE, | 230 FROM_HERE, |
231 base::Bind(&ShutdownCheck, weak), | 231 base::Bind(&ShutdownCheck, weak), |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 bytes_read = 0; | 288 bytes_read = 0; |
289 }; | 289 }; |
290 | 290 |
291 return true; | 291 return true; |
292 #else | 292 #else |
293 // Copy the pointer to stack because g_context may be set to NULL | 293 // Copy the pointer to stack because g_context may be set to NULL |
294 // in different thread. The instance is guaranteed to exist while | 294 // in different thread. The instance is guaranteed to exist while |
295 // the method is running. | 295 // the method is running. |
296 net::URLRequestContextGetter* context = | 296 net::URLRequestContextGetter* context = |
297 reinterpret_cast<net::URLRequestContextGetter*>( | 297 reinterpret_cast<net::URLRequestContextGetter*>( |
298 base::subtle::NoBarrier_Load(&g_context)); | 298 base::subtle::Acquire_Load(&g_context)); |
299 | 299 |
300 // Browser shutdown will cause the context to be reset to NULL. | 300 // Browser shutdown will cause the context to be reset to NULL. |
301 if (!context) | 301 if (!context) |
302 return false; | 302 return false; |
303 | 303 |
304 // Run a blocking event loop to match the win inet implementation. | 304 // Run a blocking event loop to match the win inet implementation. |
305 scoped_ptr<base::MessageLoop> message_loop; | 305 scoped_ptr<base::MessageLoop> message_loop; |
306 // Ensure that we have a MessageLoop. | 306 // Ensure that we have a MessageLoop. |
307 if (!base::MessageLoop::current()) | 307 if (!base::MessageLoop::current()) |
308 message_loop.reset(new base::MessageLoop); | 308 message_loop.reset(new base::MessageLoop); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 } | 404 } |
405 | 405 |
406 bool WasSendFinancialPingInterrupted() { | 406 bool WasSendFinancialPingInterrupted() { |
407 return send_financial_ping_interrupted_for_test; | 407 return send_financial_ping_interrupted_for_test; |
408 } | 408 } |
409 | 409 |
410 } // namespace test | 410 } // namespace test |
411 #endif | 411 #endif |
412 | 412 |
413 } // namespace rlz_lib | 413 } // namespace rlz_lib |
OLD | NEW |