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 3 // found in the LICENSE file. 4 // 5 // Library functions related to the Financial Server ping. 6 7 #ifndef RLZ_LIB_FINANCIAL_PING_H_ 8 #define RLZ_LIB_FINANCIAL_PING_H_ 9 10 #include <string> 11 #include "rlz/lib/rlz_enums.h" 12 13 #if defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET) 14 namespace network { 15 namespace mojom { 16 class URLLoaderFactory; 17 } 18 } // namespace network 19 #endif 20 21 namespace rlz_lib { 22 23 class FinancialPing { 24 public: 25 // Return values of the PingServer() method. 26 enum PingResponse { 27 PING_SUCCESSFUL, // Ping sent and response processed successfully. 28 PING_FAILURE, // Ping not sent. 29 PING_SHUTDOWN // Ping not sent because chrome is shutting down. 30 }; 31 32 // Form the HTTP request to send to the PSO server. 33 // Will look something like: 34 // /pso/ping?as=swg&brand=GGLD&id=124&hl=en& 35 // events=I7S&rep=1&rlz=I7:val,W1:&dcc=dval 36 static bool FormRequest(Product product, const AccessPoint* access_points, 37 const char* product_signature, 38 const char* product_brand, const char* product_id, 39 const char* product_lang, bool exclude_machine_id, 40 std::string* request); 41 42 // Returns whether the time is right to send a ping. 43 // If no_delay is true, this should always ping if there are events, 44 // or one week has passed since last_ping when there are no new events. 45 // If no_delay is false, this should ping if current time < last_ping time 46 // (case of time reset) or if one day has passed since last_ping and there 47 // are events, or one week has passed since last_ping when there are 48 // no new events. 49 static bool IsPingTime(Product product, bool no_delay); 50 51 // Set the last ping time to be now. Writes to RlzValueStore. 52 static bool UpdateLastPingTime(Product product); 53 54 // Clear the last ping time - should be called on uninstall. 55 // Writes to RlzValueStore. 56 static bool ClearLastPingTime(Product product); 57 58 // Ping the financial server with request. Writes to RlzValueStore. 59 static PingResponse PingServer(const char* request, std::string* response); 60 61 #if defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET) 62 static bool SetURLLoaderFactory(network::mojom::URLLoaderFactory* factory); 63 #endif 64 65 private: FinancialPing()66 FinancialPing() {} ~FinancialPing()67 ~FinancialPing() {} 68 }; 69 70 #if defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET) 71 namespace test { 72 void ResetSendFinancialPingInterrupted(); 73 bool WasSendFinancialPingInterrupted(); 74 } // namespace test 75 #endif 76 77 } // namespace rlz_lib 78 79 80 #endif // RLZ_LIB_FINANCIAL_PING_H_ 81