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)// A library to manage RLZ information for access-points shared
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// across different client applications.
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// All functions return true on success and false on error.
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This implemenation is thread safe.
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef RLZ_LIB_RLZ_LIB_H_
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define RLZ_LIB_RLZ_LIB_H_
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <stdio.h>
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "build/build_config.h"
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "rlz/lib/rlz_enums.h"
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_WIN)
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define RLZ_LIB_API __cdecl
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#else
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define RLZ_LIB_API
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Define one of
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// + RLZ_NETWORK_IMPLEMENTATION_WIN_INET: Uses win inet to send financial pings.
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// + RLZ_NETWORK_IMPLEMENTATION_CHROME_NET: Uses chrome's network stack to send
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   financial pings. rlz_lib::SetURLRequestContext() must be called before
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   any calls to SendFinancialPing().
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(RLZ_NETWORK_IMPLEMENTATION_WIN_INET) && \
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET)
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#error Exactly one of RLZ_NETWORK_IMPLEMENTATION_WIN_INET and \
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    RLZ_NETWORK_IMPLEMENTATION_CHROME_NET should be defined.
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if !defined(RLZ_NETWORK_IMPLEMENTATION_WIN_INET) && \
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    !defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET)
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_WIN)
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define RLZ_NETWORK_IMPLEMENTATION_WIN_INET
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#else
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define RLZ_NETWORK_IMPLEMENTATION_CHROME_NET
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET)
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace net {
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class URLRequestContextGetter;
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace net
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace rlz_lib {
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// All functions return true on success and false on error.
56f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// This implemenation is thread safe.
57f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)//
58f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Each prototype mentions the registry access requirements:
59f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)//
60f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// HKLM read:  Will work from any process and at any privilege level on Vista.
61f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// HKCU read:  Calls made from the SYSTEM account must pass the current user's
62f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)//             SID as the optional 'sid' param. Can be called from low integrity
63f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)//             process on Vista.
64f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// HKCU write: Calls made from the SYSTEM account must pass the current user's
65f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)//             SID as the optional 'sid' param. Calls require at least medium
66f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)//             integrity on Vista (e.g. Toolbar will need to use their broker)
67f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// HKLM write: Calls must be made from an account with admin rights. No SID
68f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)//             need be passed when running as SYSTEM.
69f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Functions which do not access registry will be marked with "no restrictions".
70f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ScopedRlzValueStoreLock;
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The maximum length of an access points RLZ in bytes.
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const size_t kMaxRlzLength = 64;
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The maximum length of an access points RLZ in bytes.
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const size_t kMaxDccLength = 128;
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The maximum length of a CGI string in bytes.
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const size_t kMaxCgiLength = 2048;
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The maximum length of a ping response we will parse in bytes. If the response
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// is bigger, please break it up into separate calls.
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const size_t kMaxPingResponseLength = 0x4000;  // 16K
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET)
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Set the URLRequestContextGetter used by SendFinancialPing(). The IO message
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// loop returned by this context will be used for the IO done by
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// SendFinancialPing().
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool RLZ_LIB_API SetURLRequestContext(net::URLRequestContextGetter* context);
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// RLZ storage functions.
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Get all the events reported by this product as a CGI string to append to
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the daily ping.
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Access: HKCU read.
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool RLZ_LIB_API GetProductEventsAsCgi(Product product, char* unescaped_cgi,
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                       size_t unescaped_cgi_size);
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Records an RLZ event.
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Some events can be product-independent (e.g: First search from home page),
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// and some can be access point independent (e.g. Pack installed). However,
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// product independent events must still include the product which cares about
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// that information being reported.
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Access: HKCU write.
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool RLZ_LIB_API RecordProductEvent(Product product, AccessPoint point,
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                    Event event_id);
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Clear an event reported by this product. This should be called after a
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// successful ping to the RLZ server.
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Access: HKCU write.
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool RLZ_LIB_API ClearProductEvent(Product product, AccessPoint point,
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   Event event_id);
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Clear all reported events and recorded stateful events of this product.
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This should be called on complete uninstallation of the product.
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Access: HKCU write.
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool RLZ_LIB_API ClearAllProductEvents(Product product);
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Clears all product-specifc state from the RLZ registry.
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Should be called during product uninstallation.
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This removes outstanding product events, product financial ping times,
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the product RLS argument (if any), and any RLZ's for access points being
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// uninstalled with the product.
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// access_points is an array terminated with NO_ACCESS_POINT.
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// IMPORTANT: These are the access_points the product is removing as part
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// of the uninstallation, not necessarily all the access points passed to
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// SendFinancialPing() and GetPingParams().
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// access_points can be NULL if no points are being uninstalled.
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// No return value - this is best effort. Will assert in debug mode on
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// failed attempts.
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Access: HKCU write.
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void RLZ_LIB_API ClearProductState(Product product,
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   const AccessPoint* access_points);
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Get the RLZ value of the access point. If the access point is not Google, the
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// RLZ will be the empty string and the function will return false.
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Access: HKCU read.
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool RLZ_LIB_API GetAccessPointRlz(AccessPoint point, char* rlz,
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   size_t rlz_size);
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Set the RLZ for the access-point. Fails and asserts if called when the access
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// point is not set to Google.
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// new_rlz should come from a server-response. Client applications should not
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// create their own RLZ values.
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Access: HKCU write.
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool RLZ_LIB_API SetAccessPointRlz(AccessPoint point, const char* new_rlz);
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Financial Server pinging functions.
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// These functions deal with pinging the RLZ financial server and parsing and
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// acting upon the response. Clients should SendFinancialPing() to avoid needing
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// these functions. However, these functions allow clients to split the various
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// parts of the pinging process up as needed (to avoid firewalls, etc).
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Forms the HTTP request to send to the RLZ financial server.
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// product            : The product to ping for.
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// access_points      : The access points this product affects. Array must be
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//                      terminated with NO_ACCESS_POINT.
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// product_signature  : The signature sent with daily pings (e.g. swg, ietb)
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// product_brand      : The brand of the pinging product, if any.
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// product_id         : The product-specific installation ID (can be NULL).
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// product_lang       : The language for the product (used to determine cohort).
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// exclude_machine_id : Whether the Machine ID should be explicitly excluded
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//                      based on the products privacy policy.
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// request            : The buffer where the function returns the HTTP request.
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// request_buffer_size: The size of the request buffer in bytes. The buffer
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//                      size (kMaxCgiLength+1) is guaranteed to be enough.
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Access: HKCU read.
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool RLZ_LIB_API FormFinancialPingRequest(Product product,
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                          const AccessPoint* access_points,
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                          const char* product_signature,
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                          const char* product_brand,
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                          const char* product_id,
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                          const char* product_lang,
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                          bool exclude_machine_id,
1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                          char* request,
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                          size_t request_buffer_size);
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Pings the financial server and returns the HTTP response. This will fail
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// if it is too early to ping the server since the last ping.
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// If RLZ_NETWORK_IMPLEMENTATION_CHROME_NET is set, SetURLRequestContext() needs
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// to be called before calling this function.
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// product              : The product to ping for.
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// request              : The HTTP request (for example, returned by
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//                        FormFinancialPingRequest).
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// response             : The buffer in which the HTTP response is returned.
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// response_buffer_size : The size of the response buffer in bytes. The buffer
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//                        size (kMaxPingResponseLength+1) is enough for all
1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//                        legitimate server responses (any response that is
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//                        bigger should be considered the same way as a general
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//                        network problem).
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Access: HKCU read.
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool RLZ_LIB_API PingFinancialServer(Product product,
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                     const char* request,
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                     char* response,
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                     size_t response_buffer_size);
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Checks if a ping response is valid - ie. it has a checksum line which
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// is the CRC-32 checksum of the message uptil the checksum. If
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// checksum_idx is not NULL, it will get the index of the checksum, i.e. -
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the effective end of the message.
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Access: No restrictions.
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool RLZ_LIB_API IsPingResponseValid(const char* response,
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                     int* checksum_idx);
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Complex helpers built on top of other functions.
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Parses the responses from the financial server and updates product state
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// and access point RLZ's in registry. Like ParsePingResponse(), but also
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// updates the last ping time.
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Access: HKCU write.
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool RLZ_LIB_API ParseFinancialPingResponse(Product product,
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                            const char* response);
2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Send the ping with RLZs and events to the PSO server.
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This ping method should be called daily. (More frequent calls will fail).
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Also, if there are no events, the call will succeed only once a week.
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// If RLZ_NETWORK_IMPLEMENTATION_CHROME_NET is set, SetURLRequestContext() needs
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// to be called before calling this function.
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// product            : The product to ping for.
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// access_points      : The access points this product affects. Array must be
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//                      terminated with NO_ACCESS_POINT.
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// product_signature  : The signature sent with daily pings (e.g. swg, ietb)
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// product_brand      : The brand of the pinging product, if any.
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// product_id         : The product-specific installation ID (can be NULL).
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// product_lang       : The language for the product (used to determine cohort).
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// exclude_machine_id : Whether the Machine ID should be explicitly excluded
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//                      based on the products privacy policy.
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns true on successful ping and response, false otherwise.
2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Access: HKCU write.
2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool RLZ_LIB_API SendFinancialPing(Product product,
2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   const AccessPoint* access_points,
2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   const char* product_signature,
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   const char* product_brand,
2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   const char* product_id,
2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   const char* product_lang,
2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   bool exclude_machine_id);
2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// An alternate implementations of SendFinancialPing with the same behavior,
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// except the caller can optionally choose to skip the timing check.
2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool RLZ_LIB_API SendFinancialPing(Product product,
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   const AccessPoint* access_points,
2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   const char* product_signature,
2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   const char* product_brand,
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   const char* product_id,
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   const char* product_lang,
2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   bool exclude_machine_id,
2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   const bool skip_time_check);
2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Parses RLZ related ping response information from the server.
2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Updates stored RLZ values and clears stored events accordingly.
2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Access: HKCU write.
2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool RLZ_LIB_API ParsePingResponse(Product product, const char* response);
2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copies the events associated with the product and the RLZ's for each access
2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// point in access_points into cgi. This string can be directly appended
2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// to a ping (will need an & if not first paramter).
2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// access_points must be an array of AccessPoints terminated with
2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NO_ACCESS_POINT.
2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Access: HKCU read.
2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool RLZ_LIB_API GetPingParams(Product product,
2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                               const AccessPoint* access_points,
2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                               char* unescaped_cgi, size_t unescaped_cgi_size);
2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_WIN)
2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// OEM Deal confirmation storage functions. OEM Deals are windows-only.
2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Makes the OEM Deal Confirmation code writable by all users on the machine.
2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This should be called before calling SetMachineDealCode from a non-admin
2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// account.
2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Access: HKLM write.
2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool RLZ_LIB_API CreateMachineState(void);
2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Set the OEM Deal Confirmation Code (DCC). This information is used for RLZ
2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// initalization.
2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Access: HKLM write, or
2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// HKCU read if rlz_lib::CreateMachineState() has been sucessfully called.
2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool RLZ_LIB_API SetMachineDealCode(const char* dcc);
2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Get the DCC cgi argument string to append to a daily ping.
2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Should be used only by OEM deal trackers. Applications should use the
2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// GetMachineDealCode method which has an AccessPoint paramter.
2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Access: HKLM read.
2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool RLZ_LIB_API GetMachineDealCodeAsCgi(char* cgi, size_t cgi_size);
2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Get the DCC value stored in registry.
2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Should be used only by OEM deal trackers. Applications should use the
2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// GetMachineDealCode method which has an AccessPoint paramter.
2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Access: HKLM read.
2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool RLZ_LIB_API GetMachineDealCode(char* dcc, size_t dcc_size);
2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Parses a ping response, checks if it is valid and sets the machine DCC
3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// from the response. The ping must also contain the current DCC value in
3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// order to be considered valid.
3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Access: HKLM write;
3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//         HKCU write if CreateMachineState() has been successfully called.
3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool RLZ_LIB_API SetMachineDealCodeFromPingResponse(const char* response);
3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Segment RLZ persistence based on branding information.
3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// All information for a given product is persisted under keys with the either
3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// product's name or its access point's name.  This assumes that only
3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// one instance of the product is installed on the machine, and that only one
3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// product brand is associated with it.
3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// In some cases, a given product may be using supplementary brands.  The RLZ
3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// information must be kept separately for each of these brands.  To achieve
3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// this segmentation, scope all RLZ library calls that deal with supplementary
3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// brands within the lifetime of an rlz_lib::ProductBranding instance.
3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// For example, to record events for a supplementary brand, do the following:
3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//  {
3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//    rlz_lib::SupplementaryBranding branding("AAAA");
3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//    // This call to RecordProductEvent is scoped to the AAAA brand.
3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//    rlz_lib::RecordProductEvent(rlz_lib::DESKTOP, rlz_lib::GD_DESKBAND,
3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//                                rlz_lib::INSTALL);
3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//  }
3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//  // This call to RecordProductEvent is not scoped to any supplementary brand.
3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//  rlz_lib::RecordProductEvent(rlz_lib::DESKTOP, rlz_lib::GD_DESKBAND,
3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//                              rlz_lib::INSTALL);
3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// In particular, this affects the recording of stateful events and the sending
3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// of financial pings.  In the former case, a stateful event recorded while
3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// scoped to a supplementary brand will be recorded again when scoped to a
3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// different supplementary brand (or not scoped at all).  In the latter case,
3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the time skip check is specific to each supplementary brand.
3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class SupplementaryBranding {
3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SupplementaryBranding(const char* brand);
3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ~SupplementaryBranding();
3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static const std::string& GetBrand();
3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ScopedRlzValueStoreLock* lock_;
3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace rlz_lib
3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // RLZ_LIB_RLZ_LIB_H_
352