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)#ifndef CHROME_INSTALLER_UTIL_GOOGLE_UPDATE_SETTINGS_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHROME_INSTALLER_UTIL_GOOGLE_UPDATE_SETTINGS_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h" 11868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/string16.h" 12eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/time/time.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/version.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/util/util_constants.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class BrowserDistribution; 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace installer { 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ChannelInfo; 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class InstallationState; 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This class provides accessors to the Google Update 'ClientState' information 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// that recorded when the user downloads the chrome installer. It is 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// google_update.exe responsibility to write the initial values. 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class GoogleUpdateSettings { 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Update policy constants defined by Google Update; do not change these. 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) enum UpdatePolicy { 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) UPDATES_DISABLED = 0, 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AUTOMATIC_UPDATES = 1, 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MANUAL_UPDATES_ONLY = 2, 33eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AUTO_UPDATES_ONLY = 3, 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Defines product data that is tracked/used by Google Update. 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) struct ProductData { 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The currently installed version. 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string version; 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The time that Google Update last updated this product. (This means 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // either running an updater successfully, or doing an update check that 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // results in no update available.) 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Time last_success; 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The result reported by the most recent run of an installer/updater. 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int last_result; 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The error code, if any, reported by the most recent run of an 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // installer or updater. This is typically platform independent. 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int last_error_code; 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The extra error code, if any, reported by the most recent run of 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // an installer or updater. This is typically an error code specific 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // to the platform -- i.e. on Windows, it will be a Win32 HRESULT. 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int last_extra_code; 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if this install is system-wide, false if it is per-user. 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool IsSystemInstall(); 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns whether the user has given consent to collect UMA data and send 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // crash dumps to Google. This information is collected by the web server 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // used to download the chrome installer. 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool GetCollectStatsConsent(); 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the user consent to send UMA and crash dumps to Google. Returns 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // false if the setting could not be recorded. 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool SetCollectStatsConsent(bool consented); 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_WIN) 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns whether the user has given consent to collect UMA data and send 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // crash dumps to Google. This information is collected by the web server 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // used to download the chrome installer. 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool GetCollectStatsConsentAtLevel(bool system_install); 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the user consent to send UMA and crash dumps to Google. Returns 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // false if the setting could not be recorded. 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool SetCollectStatsConsentAtLevel(bool system_install, 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool consented); 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the metrics id set in the registry (that can be used in crash 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // reports). If none found, returns empty string. 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool GetMetricsId(std::wstring* metrics_id); 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the metrics id to be used in crash reports. 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool SetMetricsId(const std::wstring& metrics_id); 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the machine-wide EULA consented flag required on OEM installs. 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns false if the setting could not be recorded. 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool SetEULAConsent(const installer::InstallationState& machine_state, 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BrowserDistribution* dist, 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool consented); 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the last time chrome was run in days. It uses a recorded value 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // set by SetLastRunTime(). Returns -1 if the value was not found or if 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the value is corrupted. 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static int GetLastRunTime(); 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Stores the time that this function was last called using an encoded 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // form of the system local time. Retrieve the time using GetLastRunTime(). 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns false if the value could not be stored. 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool SetLastRunTime(); 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Removes the storage used by SetLastRunTime() and SetLastRunTime(). Returns 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // false if the operation failed. Returns true if the storage was freed or 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // if it never existed in the first place. 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool RemoveLastRunTime(); 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns in |browser| the browser used to download chrome as recorded 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Google Update. Returns false if the information is not available. 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool GetBrowser(std::wstring* browser); 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns in |language| the language selected by the user when downloading 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // chrome. This information is collected by the web server used to download 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the chrome installer. Returns false if the information is not available. 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool GetLanguage(std::wstring* language); 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns in |brand| the RLZ brand code or distribution tag that has been 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // assigned to a partner. Returns false if the information is not available. 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // NOTE: This function is Windows only. If the code you are writing is not 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // specifically for Windows, prefer calling google_util::GetBrand(). 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool GetBrand(std::wstring* brand); 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns in |brand| the RLZ reactivation brand code or distribution tag 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // that has been assigned to a partner for reactivating a dormant chrome 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // install. Returns false if the information is not available. 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // NOTE: This function is Windows only. If the code you are writing is not 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // specifically for Windows, prefer calling 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // google_util::GetReactivationBrand(). 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool GetReactivationBrand(std::wstring* brand); 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns in |client| the google_update client field, which is currently 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // used to track experiments. Returns false if the entry does not exist. 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool GetClient(std::wstring* client); 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the google_update client field. Unlike GetClient() this is set only 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // for the current user. Returns false if the operation failed. 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool SetClient(const std::wstring& client); 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns in 'client' the RLZ referral available for some distribution 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // partners. This value does not exist for most chrome or chromium installs. 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool GetReferral(std::wstring* referral); 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Overwrites the current value of the referral with an empty string. Returns 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // true if this operation succeeded. 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool ClearReferral(); 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Set did_run "dr" in the client state value. This is used to measure 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // active users. Returns false if writting to the registry failed. 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool UpdateDidRunState(bool did_run, bool system_level); 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Set did_run "dr" in the client state value for |dist|. This is used to 1532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // measure active users. Returns false if writting to the registry failed. 1542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static bool UpdateDidRunStateForDistribution(BrowserDistribution* dist, 1552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool did_run, 1562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool system_level); 1572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns only the channel name: "" (stable), "dev", "beta", "canary", or 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // "unknown" if unknown. This value will not be modified by "-m" for a 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // multi-install. See kChromeChannel* in util_constants.h 1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static std::wstring GetChromeChannel(bool system_install); 1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Return a human readable modifier for the version string, e.g. 1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the channel (dev, beta, stable). Returns true if this operation succeeded, 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // on success, channel contains one of "", "unknown", "dev" or "beta" (unless 1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // it is a multi-install product, in which case it will return "m", 1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // "unknown-m", "dev-m", or "beta-m"). 1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool GetChromeChannelAndModifiers(bool system_install, 1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) string16* channel); 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This method changes the Google Update "ap" value to move the installation 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // on to or off of one of the recovery channels. 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // - If incremental installer fails we append a magic string ("-full"), if 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // it is not present already, so that Google Update server next time will send 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // full installer to update Chrome on the local machine 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // - If we are currently running full installer, we remove this magic 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // string (if it is present) regardless of whether installer failed or not. 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // There is no fall-back for full installer :) 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // - Unconditionally remove "-multifail" since we haven't crashed. 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |state_key| should be obtained via InstallerState::state_key(). 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static void UpdateInstallStatus(bool system_install, 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer::ArchiveType archive_type, 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int install_return_code, 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::wstring& product_guid); 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This method updates the value for Google Update "ap" key for Chrome 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // based on whether we are doing incremental install (or not) and whether 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the install succeeded. 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // - If install worked, remove the magic string (if present). 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // - If incremental installer failed, append a magic string (if 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // not present already). 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // - If full installer failed, still remove this magic 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // string (if it is present already). 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // archive_type: tells whether this is incremental install or not. 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // install_return_code: if 0, means installation was successful. 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // value: current value of Google Update "ap" key. 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if |value| is modified. 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool UpdateGoogleUpdateApKey(installer::ArchiveType archive_type, 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int install_return_code, 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) installer::ChannelInfo* value); 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // For system-level installs, we need to be able to communicate the results 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // of the Toast Experiments back to Google Update. The problem is just that 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the experiment is run in the context of the user, which doesn't have 2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // write access to the HKLM key that Google Update expects the results in. 2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // However, when we are about to switch contexts from system to user, we can 2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // duplicate the handle to the registry key and pass it (through handle 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // inheritance) to the newly created child process that is launched as the 2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // user, allowing the child process to write to the key, with the 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // WriteGoogleUpdateSystemClientKey function below. 2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static int DuplicateGoogleUpdateSystemClientKey(); 2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Takes a |handle| to a registry key and writes |value| string into the 2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // specified |key|. See DuplicateGoogleUpdateSystemClientKey for details. 2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool WriteGoogleUpdateSystemClientKey(int handle, 2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::wstring& key, 2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::wstring& value); 2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the effective update policy for |app_guid| as dictated by 2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Group Policy settings. |is_overridden|, if non-NULL, is populated with 2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // true if an app-specific policy override is in force, or false otherwise. 2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static UpdatePolicy GetAppUpdatePolicy(const std::wstring& app_guid, 2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool* is_overridden); 2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns Google Update's uninstall command line, or an empty string if none 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // is found. 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static string16 GetUninstallCommandLine(bool system_install); 2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the version of Google Update that is installed. 2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static Version GetGoogleUpdateVersion(bool system_install); 2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the time at which Google Update last started an automatic update 2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // check, or the null time if this information isn't available. 2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static base::Time GetGoogleUpdateLastStartedAU(bool system_install); 2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the time at which Google Update last successfully contacted Google 2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // servers and got a valid check response, or the null time if this 2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // information isn't available. 2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static base::Time GetGoogleUpdateLastChecked(bool system_install); 2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns detailed update data for a product being managed by Google Update. 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if the |version| and |last_updated| fields in |data| 2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // are modified. The other items are considered optional. 2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool GetUpdateDetailForApp(bool system_install, 2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const wchar_t* app_guid, 2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ProductData* data); 2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns product data for Google Update. (Equivalent to calling 2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // GetUpdateDetailForAppGuid with the app guid for Google Update itself.) 2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool GetUpdateDetailForGoogleUpdate(bool system_install, 2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ProductData* data); 2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns product data for the current product. (Equivalent to calling 2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // GetUpdateDetailForApp with the app guid stored in BrowserDistribution.) 2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool GetUpdateDetail(bool system_install, ProductData* data); 2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Sets |experiment_labels| as the Google Update experiment_labels value in 2592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // the ClientState key for this Chrome product, if appropriate. If 2602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // |experiment_labels| is empty, this will delete the value instead. This will 2612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // return true if the label was successfully set (or deleted), false otherwise 2622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // (even if the label does not need to be set for this particular distribution 2632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // type). 2642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static bool SetExperimentLabels(bool system_install, 2652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const string16& experiment_labels); 2662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Reads the Google Update experiment_labels value in the ClientState key for 2682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // this Chrome product and writes it into |experiment_labels|. If the key or 2692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // value does not exist, |experiment_labels| will be set to the empty string. 2702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // If this distribution of Chrome does not set the experiment_labels value, 2712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // this will do nothing to |experiment_labels|. This will return true if the 2722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // label did not exist, or was successfully read. 2732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static bool ReadExperimentLabels(bool system_install, 2742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) string16* experiment_labels); 2752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_IMPLICIT_CONSTRUCTORS(GoogleUpdateSettings); 2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // CHROME_INSTALLER_UTIL_GOOGLE_UPDATE_SETTINGS_H_ 281