15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Library functions related to the Financial Server ping. 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef RLZ_LIB_FINANCIAL_PING_H_ 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define RLZ_LIB_FINANCIAL_PING_H_ 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string> 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "rlz/lib/rlz_enums.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET) 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace net { 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class URLRequestContextGetter; 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace net 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace rlz_lib { 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class FinancialPing { 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Form the HTTP request to send to the PSO server. 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Will look something like: 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // /pso/ping?as=swg&brand=GGLD&id=124&hl=en& 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // events=I7S&rep=1&rlz=I7:val,W1:&dcc=dval 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool FormRequest(Product product, const AccessPoint* access_points, 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char* product_signature, 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char* product_brand, const char* product_id, 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char* product_lang, bool exclude_machine_id, 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string* request); 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns whether the time is right to send a ping. 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If no_delay is true, this should always ping if there are events, 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // or one week has passed since last_ping when there are no new events. 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If no_delay is false, this should ping if current time < last_ping time 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // (case of time reset) or if one day has passed since last_ping and there 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // are events, or one week has passed since last_ping when there are 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // no new events. 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool IsPingTime(Product product, bool no_delay); 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Set the last ping time to be now. Writes to RlzValueStore. 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool UpdateLastPingTime(Product product); 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Clear the last ping time - should be called on uninstall. 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Writes to RlzValueStore. 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool ClearLastPingTime(Product product); 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Ping the financial server with request. Writes to RlzValueStore. 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool PingServer(const char* request, std::string* response); 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET) 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool SetURLRequestContext(net::URLRequestContextGetter* context); 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FinancialPing() {} 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ~FinancialPing() {} 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 618bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#if defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET) 628bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)namespace test { 638bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)void ResetSendFinancialPingInterrupted(); 648bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)bool WasSendFinancialPingInterrupted(); 658bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} // namespace test 668bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#endif 678bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace rlz_lib 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // RLZ_LIB_FINANCIAL_PING_H_ 72