Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(846)

Side by Side Diff: rlz/lib/financial_ping.cc

Issue 14520024: rlz: Use base::MessageLoop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | rlz/lib/rlz_lib_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // Run a blocking event loop to match the win inet implementation. 268 // Run a blocking event loop to match the win inet implementation.
269 scoped_ptr<MessageLoop> message_loop; 269 scoped_ptr<base::MessageLoop> message_loop;
270 // Ensure that we have a MessageLoop. 270 // Ensure that we have a MessageLoop.
271 if (!MessageLoop::current()) 271 if (!base::MessageLoop::current())
272 message_loop.reset(new MessageLoop); 272 message_loop.reset(new base::MessageLoop);
273 base::RunLoop loop; 273 base::RunLoop loop;
274 FinancialPingUrlFetcherDelegate delegate(loop.QuitClosure()); 274 FinancialPingUrlFetcherDelegate delegate(loop.QuitClosure());
275 275
276 std::string url = base::StringPrintf("http://%s:%d%s", 276 std::string url = base::StringPrintf("http://%s:%d%s",
277 kFinancialServer, kFinancialPort, 277 kFinancialServer, kFinancialPort,
278 request); 278 request);
279 279
280 scoped_ptr<net::URLFetcher> fetcher(net::URLFetcher::Create( 280 scoped_ptr<net::URLFetcher> fetcher(net::URLFetcher::Create(
281 GURL(url), net::URLFetcher::GET, &delegate)); 281 GURL(url), net::URLFetcher::GET, &delegate));
282 282
283 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE | 283 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE |
284 net::LOAD_DO_NOT_SEND_AUTH_DATA | 284 net::LOAD_DO_NOT_SEND_AUTH_DATA |
285 net::LOAD_DO_NOT_PROMPT_FOR_LOGIN | 285 net::LOAD_DO_NOT_PROMPT_FOR_LOGIN |
286 net::LOAD_DO_NOT_SEND_COOKIES | 286 net::LOAD_DO_NOT_SEND_COOKIES |
287 net::LOAD_DO_NOT_SAVE_COOKIES); 287 net::LOAD_DO_NOT_SAVE_COOKIES);
288 288
289 // Ensure rlz_lib::SetURLRequestContext() has been called before sending 289 // Ensure rlz_lib::SetURLRequestContext() has been called before sending
290 // pings. 290 // pings.
291 CHECK(g_context); 291 CHECK(g_context);
292 fetcher->SetRequestContext(g_context); 292 fetcher->SetRequestContext(g_context);
293 293
294 const base::TimeDelta kTimeout = base::TimeDelta::FromMinutes(5); 294 const base::TimeDelta kTimeout = base::TimeDelta::FromMinutes(5);
295 MessageLoop::ScopedNestableTaskAllower allow_nested(MessageLoop::current()); 295 base::MessageLoop::ScopedNestableTaskAllower allow_nested(
296 MessageLoop::current()->PostTask( 296 base::MessageLoop::current());
297 base::MessageLoop::current()->PostTask(
297 FROM_HERE, 298 FROM_HERE,
298 base::Bind(&net::URLFetcher::Start, base::Unretained(fetcher.get()))); 299 base::Bind(&net::URLFetcher::Start, base::Unretained(fetcher.get())));
299 MessageLoop::current()->PostDelayedTask( 300 base::MessageLoop::current()->PostDelayedTask(
300 FROM_HERE, loop.QuitClosure(), kTimeout); 301 FROM_HERE, loop.QuitClosure(), kTimeout);
301 302
302 loop.Run(); 303 loop.Run();
303 304
304 if (fetcher->GetResponseCode() != 200) 305 if (fetcher->GetResponseCode() != 200)
305 return false; 306 return false;
306 307
307 return fetcher->GetResponseAsString(response); 308 return fetcher->GetResponseAsString(response);
308 #endif 309 #endif
309 } 310 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 350
350 bool FinancialPing::ClearLastPingTime(Product product) { 351 bool FinancialPing::ClearLastPingTime(Product product) {
351 ScopedRlzValueStoreLock lock; 352 ScopedRlzValueStoreLock lock;
352 RlzValueStore* store = lock.GetStore(); 353 RlzValueStore* store = lock.GetStore();
353 if (!store || !store->HasAccess(RlzValueStore::kWriteAccess)) 354 if (!store || !store->HasAccess(RlzValueStore::kWriteAccess))
354 return false; 355 return false;
355 return store->ClearPingTime(product); 356 return store->ClearPingTime(product);
356 } 357 }
357 358
358 } // namespace 359 } // namespace
OLDNEW
« no previous file with comments | « no previous file | rlz/lib/rlz_lib_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698