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 <stdint.h> |
| 10 |
9 #include "base/atomicops.h" | 11 #include "base/atomicops.h" |
10 #include "base/basictypes.h" | 12 #include "base/macros.h" |
11 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
13 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
14 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
15 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "build/build_config.h" |
16 #include "rlz/lib/assert.h" | 19 #include "rlz/lib/assert.h" |
17 #include "rlz/lib/lib_values.h" | 20 #include "rlz/lib/lib_values.h" |
18 #include "rlz/lib/machine_id.h" | 21 #include "rlz/lib/machine_id.h" |
19 #include "rlz/lib/rlz_lib.h" | 22 #include "rlz/lib/rlz_lib.h" |
20 #include "rlz/lib/rlz_value_store.h" | 23 #include "rlz/lib/rlz_value_store.h" |
21 #include "rlz/lib/string_utils.h" | 24 #include "rlz/lib/string_utils.h" |
22 | 25 |
23 #if !defined(OS_WIN) | 26 #if !defined(OS_WIN) |
24 #include "base/time/time.h" | 27 #include "base/time/time.h" |
25 #endif | 28 #endif |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 #include "net/url_request/url_request_context_getter.h" | 60 #include "net/url_request/url_request_context_getter.h" |
58 #include "url/gurl.h" | 61 #include "url/gurl.h" |
59 | 62 |
60 #endif | 63 #endif |
61 | 64 |
62 namespace { | 65 namespace { |
63 | 66 |
64 // Returns the time relative to a fixed point in the past in multiples of | 67 // Returns the time relative to a fixed point in the past in multiples of |
65 // 100 ns stepts. The point in the past is arbitrary but can't change, as the | 68 // 100 ns stepts. The point in the past is arbitrary but can't change, as the |
66 // result of this value is stored on disk. | 69 // result of this value is stored on disk. |
67 int64 GetSystemTimeAsInt64() { | 70 int64_t GetSystemTimeAsInt64() { |
68 #if defined(OS_WIN) | 71 #if defined(OS_WIN) |
69 FILETIME now_as_file_time; | 72 FILETIME now_as_file_time; |
70 // Relative to Jan 1, 1601 (UTC). | 73 // Relative to Jan 1, 1601 (UTC). |
71 GetSystemTimeAsFileTime(&now_as_file_time); | 74 GetSystemTimeAsFileTime(&now_as_file_time); |
72 | 75 |
73 LARGE_INTEGER integer; | 76 LARGE_INTEGER integer; |
74 integer.HighPart = now_as_file_time.dwHighDateTime; | 77 integer.HighPart = now_as_file_time.dwHighDateTime; |
75 integer.LowPart = now_as_file_time.dwLowDateTime; | 78 integer.LowPart = now_as_file_time.dwLowDateTime; |
76 return integer.QuadPart; | 79 return integer.QuadPart; |
77 #else | 80 #else |
78 // Seconds since epoch (Jan 1, 1970). | 81 // Seconds since epoch (Jan 1, 1970). |
79 double now_seconds = base::Time::Now().ToDoubleT(); | 82 double now_seconds = base::Time::Now().ToDoubleT(); |
80 return static_cast<int64>(now_seconds * 1000 * 1000 * 10); | 83 return static_cast<int64_t>(now_seconds * 1000 * 1000 * 10); |
81 #endif | 84 #endif |
82 } | 85 } |
83 | 86 |
84 } // namespace | 87 } // namespace |
85 | 88 |
86 | 89 |
87 namespace rlz_lib { | 90 namespace rlz_lib { |
88 | 91 |
89 using base::subtle::AtomicWord; | 92 using base::subtle::AtomicWord; |
90 | 93 |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 return fetcher->GetResponseAsString(response); | 350 return fetcher->GetResponseAsString(response); |
348 #endif | 351 #endif |
349 } | 352 } |
350 | 353 |
351 bool FinancialPing::IsPingTime(Product product, bool no_delay) { | 354 bool FinancialPing::IsPingTime(Product product, bool no_delay) { |
352 ScopedRlzValueStoreLock lock; | 355 ScopedRlzValueStoreLock lock; |
353 RlzValueStore* store = lock.GetStore(); | 356 RlzValueStore* store = lock.GetStore(); |
354 if (!store || !store->HasAccess(RlzValueStore::kReadAccess)) | 357 if (!store || !store->HasAccess(RlzValueStore::kReadAccess)) |
355 return false; | 358 return false; |
356 | 359 |
357 int64 last_ping = 0; | 360 int64_t last_ping = 0; |
358 if (!store->ReadPingTime(product, &last_ping)) | 361 if (!store->ReadPingTime(product, &last_ping)) |
359 return true; | 362 return true; |
360 | 363 |
361 uint64 now = GetSystemTimeAsInt64(); | 364 uint64_t now = GetSystemTimeAsInt64(); |
362 int64 interval = now - last_ping; | 365 int64_t interval = now - last_ping; |
363 | 366 |
364 // If interval is negative, clock was probably reset. So ping. | 367 // If interval is negative, clock was probably reset. So ping. |
365 if (interval < 0) | 368 if (interval < 0) |
366 return true; | 369 return true; |
367 | 370 |
368 // Check if this product has any unreported events. | 371 // Check if this product has any unreported events. |
369 char cgi[kMaxCgiLength + 1]; | 372 char cgi[kMaxCgiLength + 1]; |
370 cgi[0] = 0; | 373 cgi[0] = 0; |
371 bool has_events = GetProductEventsAsCgi(product, cgi, arraysize(cgi)); | 374 bool has_events = GetProductEventsAsCgi(product, cgi, arraysize(cgi)); |
372 if (no_delay && has_events) | 375 if (no_delay && has_events) |
373 return true; | 376 return true; |
374 | 377 |
375 return interval >= (has_events ? kEventsPingInterval : kNoEventsPingInterval); | 378 return interval >= (has_events ? kEventsPingInterval : kNoEventsPingInterval); |
376 } | 379 } |
377 | 380 |
378 | 381 |
379 bool FinancialPing::UpdateLastPingTime(Product product) { | 382 bool FinancialPing::UpdateLastPingTime(Product product) { |
380 ScopedRlzValueStoreLock lock; | 383 ScopedRlzValueStoreLock lock; |
381 RlzValueStore* store = lock.GetStore(); | 384 RlzValueStore* store = lock.GetStore(); |
382 if (!store || !store->HasAccess(RlzValueStore::kWriteAccess)) | 385 if (!store || !store->HasAccess(RlzValueStore::kWriteAccess)) |
383 return false; | 386 return false; |
384 | 387 |
385 uint64 now = GetSystemTimeAsInt64(); | 388 uint64_t now = GetSystemTimeAsInt64(); |
386 return store->WritePingTime(product, now); | 389 return store->WritePingTime(product, now); |
387 } | 390 } |
388 | 391 |
389 | 392 |
390 bool FinancialPing::ClearLastPingTime(Product product) { | 393 bool FinancialPing::ClearLastPingTime(Product product) { |
391 ScopedRlzValueStoreLock lock; | 394 ScopedRlzValueStoreLock lock; |
392 RlzValueStore* store = lock.GetStore(); | 395 RlzValueStore* store = lock.GetStore(); |
393 if (!store || !store->HasAccess(RlzValueStore::kWriteAccess)) | 396 if (!store || !store->HasAccess(RlzValueStore::kWriteAccess)) |
394 return false; | 397 return false; |
395 return store->ClearPingTime(product); | 398 return store->ClearPingTime(product); |
396 } | 399 } |
397 | 400 |
398 #if defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET) | 401 #if defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET) |
399 namespace test { | 402 namespace test { |
400 | 403 |
401 void ResetSendFinancialPingInterrupted() { | 404 void ResetSendFinancialPingInterrupted() { |
402 send_financial_ping_interrupted_for_test = false; | 405 send_financial_ping_interrupted_for_test = false; |
403 } | 406 } |
404 | 407 |
405 bool WasSendFinancialPingInterrupted() { | 408 bool WasSendFinancialPingInterrupted() { |
406 return send_financial_ping_interrupted_for_test; | 409 return send_financial_ping_interrupted_for_test; |
407 } | 410 } |
408 | 411 |
409 } // namespace test | 412 } // namespace test |
410 #endif | 413 #endif |
411 | 414 |
412 } // namespace rlz_lib | 415 } // namespace rlz_lib |
OLD | NEW |