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/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 | 258 |
259 DWORD bytes_read = 0; | 259 DWORD bytes_read = 0; |
260 while (InternetReadFile(http_handle, buffer.get(), kMaxPingResponseLength, | 260 while (InternetReadFile(http_handle, buffer.get(), kMaxPingResponseLength, |
261 &bytes_read) && bytes_read > 0) { | 261 &bytes_read) && bytes_read > 0) { |
262 response->append(buffer.get(), bytes_read); | 262 response->append(buffer.get(), bytes_read); |
263 bytes_read = 0; | 263 bytes_read = 0; |
264 }; | 264 }; |
265 | 265 |
266 return true; | 266 return true; |
267 #else | 267 #else |
| 268 // Browser shutdown will cause the context to be reset to NULL. |
| 269 if (!g_context) |
| 270 return false; |
| 271 |
268 // Run a blocking event loop to match the win inet implementation. | 272 // Run a blocking event loop to match the win inet implementation. |
269 scoped_ptr<MessageLoop> message_loop; | 273 scoped_ptr<MessageLoop> message_loop; |
270 // Ensure that we have a MessageLoop. | 274 // Ensure that we have a MessageLoop. |
271 if (!MessageLoop::current()) | 275 if (!MessageLoop::current()) |
272 message_loop.reset(new MessageLoop); | 276 message_loop.reset(new MessageLoop); |
273 base::RunLoop loop; | 277 base::RunLoop loop; |
274 FinancialPingUrlFetcherDelegate delegate(loop.QuitClosure()); | 278 FinancialPingUrlFetcherDelegate delegate(loop.QuitClosure()); |
275 | 279 |
276 std::string url = base::StringPrintf("http://%s:%d%s", | 280 std::string url = base::StringPrintf("http://%s:%d%s", |
277 kFinancialServer, kFinancialPort, | 281 kFinancialServer, kFinancialPort, |
278 request); | 282 request); |
279 | 283 |
280 scoped_ptr<net::URLFetcher> fetcher(net::URLFetcher::Create( | 284 scoped_ptr<net::URLFetcher> fetcher(net::URLFetcher::Create( |
281 GURL(url), net::URLFetcher::GET, &delegate)); | 285 GURL(url), net::URLFetcher::GET, &delegate)); |
282 | 286 |
283 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE | | 287 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE | |
284 net::LOAD_DO_NOT_SEND_AUTH_DATA | | 288 net::LOAD_DO_NOT_SEND_AUTH_DATA | |
285 net::LOAD_DO_NOT_PROMPT_FOR_LOGIN | | 289 net::LOAD_DO_NOT_PROMPT_FOR_LOGIN | |
286 net::LOAD_DO_NOT_SEND_COOKIES | | 290 net::LOAD_DO_NOT_SEND_COOKIES | |
287 net::LOAD_DO_NOT_SAVE_COOKIES); | 291 net::LOAD_DO_NOT_SAVE_COOKIES); |
288 | 292 |
289 // Ensure rlz_lib::SetURLRequestContext() has been called before sending | 293 // Ensure rlz_lib::SetURLRequestContext() has been called before sending |
290 // pings. | 294 // pings. |
291 CHECK(g_context); | |
292 fetcher->SetRequestContext(g_context); | 295 fetcher->SetRequestContext(g_context); |
293 | 296 |
294 const base::TimeDelta kTimeout = base::TimeDelta::FromMinutes(5); | 297 const base::TimeDelta kTimeout = base::TimeDelta::FromMinutes(5); |
295 MessageLoop::ScopedNestableTaskAllower allow_nested(MessageLoop::current()); | 298 MessageLoop::ScopedNestableTaskAllower allow_nested(MessageLoop::current()); |
296 MessageLoop::current()->PostTask( | 299 MessageLoop::current()->PostTask( |
297 FROM_HERE, | 300 FROM_HERE, |
298 base::Bind(&net::URLFetcher::Start, base::Unretained(fetcher.get()))); | 301 base::Bind(&net::URLFetcher::Start, base::Unretained(fetcher.get()))); |
299 MessageLoop::current()->PostDelayedTask( | 302 MessageLoop::current()->PostDelayedTask( |
300 FROM_HERE, loop.QuitClosure(), kTimeout); | 303 FROM_HERE, loop.QuitClosure(), kTimeout); |
301 | 304 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 | 352 |
350 bool FinancialPing::ClearLastPingTime(Product product) { | 353 bool FinancialPing::ClearLastPingTime(Product product) { |
351 ScopedRlzValueStoreLock lock; | 354 ScopedRlzValueStoreLock lock; |
352 RlzValueStore* store = lock.GetStore(); | 355 RlzValueStore* store = lock.GetStore(); |
353 if (!store || !store->HasAccess(RlzValueStore::kWriteAccess)) | 356 if (!store || !store->HasAccess(RlzValueStore::kWriteAccess)) |
354 return false; | 357 return false; |
355 return store->ClearPingTime(product); | 358 return store->ClearPingTime(product); |
356 } | 359 } |
357 | 360 |
358 } // namespace | 361 } // namespace |
OLD | NEW |