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

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

Issue 1856623002: convert //rlz to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
« no previous file with comments | « rlz/chromeos/lib/rlz_value_store_chromeos.cc ('k') | 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 <stdint.h> 9 #include <stdint.h>
10 10
11 #include <memory>
12
11 #include "base/atomicops.h" 13 #include "base/atomicops.h"
12 #include "base/macros.h" 14 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
15 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
16 #include "base/strings/stringprintf.h" 17 #include "base/strings/stringprintf.h"
17 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
18 #include "build/build_config.h" 19 #include "build/build_config.h"
19 #include "rlz/lib/assert.h" 20 #include "rlz/lib/assert.h"
20 #include "rlz/lib/lib_values.h" 21 #include "rlz/lib/lib_values.h"
21 #include "rlz/lib/machine_id.h" 22 #include "rlz/lib/machine_id.h"
22 #include "rlz/lib/rlz_lib.h" 23 #include "rlz/lib/rlz_lib.h"
23 #include "rlz/lib/rlz_value_store.h" 24 #include "rlz/lib/rlz_value_store.h"
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 274
274 // Check the response status. 275 // Check the response status.
275 DWORD status; 276 DWORD status;
276 DWORD status_size = sizeof(status); 277 DWORD status_size = sizeof(status);
277 if (!HttpQueryInfo(http_handle, HTTP_QUERY_STATUS_CODE | 278 if (!HttpQueryInfo(http_handle, HTTP_QUERY_STATUS_CODE |
278 HTTP_QUERY_FLAG_NUMBER, &status, &status_size, NULL) || 279 HTTP_QUERY_FLAG_NUMBER, &status, &status_size, NULL) ||
279 200 != status) 280 200 != status)
280 return false; 281 return false;
281 282
282 // Get the response text. 283 // Get the response text.
283 scoped_ptr<char[]> buffer(new char[kMaxPingResponseLength]); 284 std::unique_ptr<char[]> buffer(new char[kMaxPingResponseLength]);
284 if (buffer.get() == NULL) 285 if (buffer.get() == NULL)
285 return false; 286 return false;
286 287
287 DWORD bytes_read = 0; 288 DWORD bytes_read = 0;
288 while (InternetReadFile(http_handle, buffer.get(), kMaxPingResponseLength, 289 while (InternetReadFile(http_handle, buffer.get(), kMaxPingResponseLength,
289 &bytes_read) && bytes_read > 0) { 290 &bytes_read) && bytes_read > 0) {
290 response->append(buffer.get(), bytes_read); 291 response->append(buffer.get(), bytes_read);
291 bytes_read = 0; 292 bytes_read = 0;
292 }; 293 };
293 294
294 return true; 295 return true;
295 #else 296 #else
296 // Copy the pointer to stack because g_context may be set to NULL 297 // Copy the pointer to stack because g_context may be set to NULL
297 // in different thread. The instance is guaranteed to exist while 298 // in different thread. The instance is guaranteed to exist while
298 // the method is running. 299 // the method is running.
299 net::URLRequestContextGetter* context = 300 net::URLRequestContextGetter* context =
300 reinterpret_cast<net::URLRequestContextGetter*>( 301 reinterpret_cast<net::URLRequestContextGetter*>(
301 base::subtle::Acquire_Load(&g_context)); 302 base::subtle::Acquire_Load(&g_context));
302 303
303 // Browser shutdown will cause the context to be reset to NULL. 304 // Browser shutdown will cause the context to be reset to NULL.
304 if (!context) 305 if (!context)
305 return false; 306 return false;
306 307
307 // Run a blocking event loop to match the win inet implementation. 308 // Run a blocking event loop to match the win inet implementation.
308 scoped_ptr<base::MessageLoop> message_loop; 309 std::unique_ptr<base::MessageLoop> message_loop;
309 // Ensure that we have a MessageLoop. 310 // Ensure that we have a MessageLoop.
310 if (!base::MessageLoop::current()) 311 if (!base::MessageLoop::current())
311 message_loop.reset(new base::MessageLoop); 312 message_loop.reset(new base::MessageLoop);
312 base::RunLoop loop; 313 base::RunLoop loop;
313 FinancialPingUrlFetcherDelegate delegate(loop.QuitClosure()); 314 FinancialPingUrlFetcherDelegate delegate(loop.QuitClosure());
314 315
315 std::string url = base::StringPrintf("http://%s:%d%s", 316 std::string url = base::StringPrintf("http://%s:%d%s",
316 kFinancialServer, kFinancialPort, 317 kFinancialServer, kFinancialPort,
317 request); 318 request);
318 319
319 scoped_ptr<net::URLFetcher> fetcher = 320 std::unique_ptr<net::URLFetcher> fetcher =
320 net::URLFetcher::Create(GURL(url), net::URLFetcher::GET, &delegate); 321 net::URLFetcher::Create(GURL(url), net::URLFetcher::GET, &delegate);
321 322
322 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE | 323 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE |
323 net::LOAD_DO_NOT_SEND_AUTH_DATA | 324 net::LOAD_DO_NOT_SEND_AUTH_DATA |
324 net::LOAD_DO_NOT_SEND_COOKIES | 325 net::LOAD_DO_NOT_SEND_COOKIES |
325 net::LOAD_DO_NOT_SAVE_COOKIES); 326 net::LOAD_DO_NOT_SAVE_COOKIES);
326 327
327 // Ensure rlz_lib::SetURLRequestContext() has been called before sending 328 // Ensure rlz_lib::SetURLRequestContext() has been called before sending
328 // pings. 329 // pings.
329 fetcher->SetRequestContext(context); 330 fetcher->SetRequestContext(context);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 } 407 }
407 408
408 bool WasSendFinancialPingInterrupted() { 409 bool WasSendFinancialPingInterrupted() {
409 return send_financial_ping_interrupted_for_test; 410 return send_financial_ping_interrupted_for_test;
410 } 411 }
411 412
412 } // namespace test 413 } // namespace test
413 #endif 414 #endif
414 415
415 } // namespace rlz_lib 416 } // namespace rlz_lib
OLDNEW
« no previous file with comments | « rlz/chromeos/lib/rlz_value_store_chromeos.cc ('k') | rlz/lib/rlz_lib_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698