google_update_settings.h revision 116680a4aac90f2aa7413d9095a592090648e557
19f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// Copyright (c) 2012 The Chromium Authors. All rights reserved.
29f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// Use of this source code is governed by a BSD-style license that can be
39f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// found in the LICENSE file.
49f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
59f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson#ifndef CHROME_INSTALLER_UTIL_GOOGLE_UPDATE_SETTINGS_H_
69f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson#define CHROME_INSTALLER_UTIL_GOOGLE_UPDATE_SETTINGS_H_
79f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
89f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson#include <string>
99f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson#include "base/basictypes.h"
119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson#include "base/strings/string16.h"
129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson#include "base/time/time.h"
139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson#include "base/version.h"
149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson#include "chrome/installer/util/util_constants.h"
159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonclass AppRegistrationData;
179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonclass BrowserDistribution;
189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonnamespace installer {
209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonclass ChannelInfo;
219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonclass InstallationState;
229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson}
239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// This class provides accessors to the Google Update 'ClientState' information
259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// that recorded when the user downloads the chrome installer. It is
269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// google_update.exe responsibility to write the initial values.
279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonclass GoogleUpdateSettings {
289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public:
299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Update policy constants defined by Google Update; do not change these.
309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  enum UpdatePolicy {
319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    UPDATES_DISABLED    = 0,
329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    AUTOMATIC_UPDATES   = 1,
339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    MANUAL_UPDATES_ONLY = 2,
349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    AUTO_UPDATES_ONLY   = 3,
359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    UPDATE_POLICIES_COUNT
369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  };
379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static const wchar_t kPoliciesKey[];
399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static const wchar_t kUpdatePolicyValue[];
409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static const wchar_t kUpdateOverrideValuePrefix[];
419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static const wchar_t kCheckPeriodOverrideMinutes[];
429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static const int kCheckPeriodOverrideMinutesDefault;
439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static const int kCheckPeriodOverrideMinutesMax;
449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static const GoogleUpdateSettings::UpdatePolicy kDefaultUpdatePolicy;
459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Defines product data that is tracked/used by Google Update.
479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  struct ProductData {
489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    // The currently installed version.
499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    std::string version;
509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    // The time that Google Update last updated this product.  (This means
519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    // either running an updater successfully, or doing an update check that
529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    // results in no update available.)
539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    base::Time last_success;
549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    // The result reported by the most recent run of an installer/updater.
559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    int last_result;
569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    // The error code, if any, reported by the most recent run of an
579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    // installer or updater.  This is typically platform independent.
589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    int last_error_code;
599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    // The extra error code, if any, reported by the most recent run of
609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    // an installer or updater.  This is typically an error code specific
619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    // to the platform -- i.e. on Windows, it will be a Win32 HRESULT.
629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    int last_extra_code;
639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  };
649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Returns true if this install is system-wide, false if it is per-user.
669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static bool IsSystemInstall();
679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Returns whether the user has given consent to collect UMA data and send
699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // crash dumps to Google. This information is collected by the web server
709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // used to download the chrome installer.
719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static bool GetCollectStatsConsent();
729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Sets the user consent to send UMA and crash dumps to Google. Returns
749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // false if the setting could not be recorded.
759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static bool SetCollectStatsConsent(bool consented);
769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson#if defined(OS_WIN)
789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Returns whether the user has given consent to collect UMA data and send
799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // crash dumps to Google. This information is collected by the web server
809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // used to download the chrome installer.
819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static bool GetCollectStatsConsentAtLevel(bool system_install);
829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Sets the user consent to send UMA and crash dumps to Google. Returns
849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // false if the setting could not be recorded.
859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static bool SetCollectStatsConsentAtLevel(bool system_install,
869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                                            bool consented);
879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson#endif
889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Returns the metrics client id backed up in the registry. If none found,
909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // returns empty string.
919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static bool LoadMetricsClientId(std::string* metrics_id);
929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Stores a backup of the metrics client id in the registry.
949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static bool StoreMetricsClientId(const std::string& metrics_id);
959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Sets the machine-wide EULA consented flag required on OEM installs.
979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Returns false if the setting could not be recorded.
989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static bool SetEULAConsent(const installer::InstallationState& machine_state,
999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                             BrowserDistribution* dist,
1009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                             bool consented);
1019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Returns the last time chrome was run in days. It uses a recorded value
1039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // set by SetLastRunTime(). Returns -1 if the value was not found or if
1049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // the value is corrupted.
1059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static int GetLastRunTime();
1069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Stores the time that this function was last called using an encoded
1089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // form of the system local time. Retrieve the time using GetLastRunTime().
1099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Returns false if the value could not be stored.
1109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static bool SetLastRunTime();
1119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Removes the storage used by SetLastRunTime() and SetLastRunTime(). Returns
1139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // false if the operation failed. Returns true if the storage was freed or
1149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // if it never existed in the first place.
1159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static bool RemoveLastRunTime();
1169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Returns in |browser| the browser used to download chrome as recorded
1189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Google Update. Returns false if the information is not available.
1199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static bool GetBrowser(base::string16* browser);
1209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Returns in |language| the language selected by the user when downloading
1229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // chrome. This information is collected by the web server used to download
1239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // the chrome installer. Returns false if the information is not available.
1249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static bool GetLanguage(base::string16* language);
1259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Returns in |brand| the RLZ brand code or distribution tag that has been
1279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // assigned to a partner. Returns false if the information is not available.
1289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  //
1299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // NOTE: This function is Windows only.  If the code you are writing is not
1309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // specifically for Windows, prefer calling google_brand::GetBrand().
1319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static bool GetBrand(base::string16* brand);
1329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Returns in |brand| the RLZ reactivation brand code or distribution tag
1349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // that has been assigned to a partner for reactivating a dormant chrome
1359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // install. Returns false if the information is not available.
1369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  //
1379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // NOTE: This function is Windows only.  If the code you are writing is not
1389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // specifically for Windows, prefer calling
1399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // google_brand::GetReactivationBrand().
1409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static bool GetReactivationBrand(base::string16* brand);
1419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Returns in |client| the google_update client field, which is currently
1439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // used to track experiments. Returns false if the entry does not exist.
1449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static bool GetClient(base::string16* client);
1459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Sets the google_update client field. Unlike GetClient() this is set only
1479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // for the current user. Returns false if the operation failed.
1489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static bool SetClient(const base::string16& client);
1499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Returns in 'client' the RLZ referral available for some distribution
1519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // partners. This value does not exist for most chrome or chromium installs.
1529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static bool GetReferral(base::string16* referral);
1539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Overwrites the current value of the referral with an empty string. Returns
1559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // true if this operation succeeded.
1569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static bool ClearReferral();
1579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Set did_run "dr" in the client state value for app specified by
1599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // |app_reg_data|. This is used to measure active users. Returns false if
1609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // registry write fails.
1619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static bool UpdateDidRunStateForApp(const AppRegistrationData& app_reg_data,
1629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                                      bool did_run);
1639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Convenience routine: UpdateDidRunStateForApp() specialized for the current
1659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // BrowserDistribution, and also updates Chrome Binary's did_run if the
1669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // current distribution is multi-install.
1679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static bool UpdateDidRunState(bool did_run, bool system_level);
1689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Returns only the channel name: "" (stable), "dev", "beta", "canary", or
1709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // "unknown" if unknown. This value will not be modified by "-m" for a
1719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // multi-install. See kChromeChannel* in util_constants.h
1729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static base::string16 GetChromeChannel(bool system_install);
1739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Return a human readable modifier for the version string, e.g.
1759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // the channel (dev, beta, stable). Returns true if this operation succeeded,
1769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // on success, channel contains one of "", "unknown", "dev" or "beta" (unless
1779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // it is a multi-install product, in which case it will return "m",
1789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // "unknown-m", "dev-m", or "beta-m").
1799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static bool GetChromeChannelAndModifiers(bool system_install,
1809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                                           base::string16* channel);
1819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // This method changes the Google Update "ap" value to move the installation
1839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // on to or off of one of the recovery channels.
1849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // - If incremental installer fails we append a magic string ("-full"), if
1859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // it is not present already, so that Google Update server next time will send
1869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // full installer to update Chrome on the local machine
1879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // - If we are currently running full installer, we remove this magic
1889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // string (if it is present) regardless of whether installer failed or not.
1899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // There is no fall-back for full installer :)
1909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // - Unconditionally remove "-multifail" since we haven't crashed.
1919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // |state_key| should be obtained via InstallerState::state_key().
1929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static void UpdateInstallStatus(bool system_install,
1939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                                  installer::ArchiveType archive_type,
1949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                                  int install_return_code,
1959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                                  const base::string16& product_guid);
1969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // This method updates the value for Google Update "ap" key for Chrome
1989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // based on whether we are doing incremental install (or not) and whether
1999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // the install succeeded.
2009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // - If install worked, remove the magic string (if present).
2019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // - If incremental installer failed, append a magic string (if
2029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  //   not present already).
2039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // - If full installer failed, still remove this magic
2049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  //   string (if it is present already).
2059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  //
2069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // archive_type: tells whether this is incremental install or not.
2079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // install_return_code: if 0, means installation was successful.
2089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // value: current value of Google Update "ap" key.
2099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Returns true if |value| is modified.
2109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static bool UpdateGoogleUpdateApKey(installer::ArchiveType archive_type,
2119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                                      int install_return_code,
2129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                                      installer::ChannelInfo* value);
2139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // This method updates the values that report how many profiles are in use
2159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // and how many of those are signed-in.
2169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static void UpdateProfileCounts(int profiles_active, int profiles_signedin);
2179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // For system-level installs, we need to be able to communicate the results
2199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // of the Toast Experiments back to Google Update. The problem is just that
2209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // the experiment is run in the context of the user, which doesn't have
2219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // write access to the HKLM key that Google Update expects the results in.
2229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // However, when we are about to switch contexts from system to user, we can
2239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // duplicate the handle to the registry key and pass it (through handle
2249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // inheritance) to the newly created child process that is launched as the
2259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // user, allowing the child process to write to the key, with the
2269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // WriteGoogleUpdateSystemClientKey function below.
2279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static int DuplicateGoogleUpdateSystemClientKey();
2289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Takes a |handle| to a registry key and writes |value| string into the
2309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // specified |key|. See DuplicateGoogleUpdateSystemClientKey for details.
2319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static bool WriteGoogleUpdateSystemClientKey(int handle,
2329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                                               const base::string16& key,
2339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                                               const base::string16& value);
2349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Returns the effective update policy for |app_guid| as dictated by
2369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Group Policy settings.  |is_overridden|, if non-NULL, is populated with
2379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // true if an app-specific policy override is in force, or false otherwise.
2389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static UpdatePolicy GetAppUpdatePolicy(const base::string16& app_guid,
2399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                                         bool* is_overridden);
2409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Returns true if the app indicated by |app_guid| should be updated
2429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // automatically by Google Update based on current autoupdate settings. This
2439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // is distinct from GetApUpdatePolicy which checks only a subset of things
2449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // that can cause an app not to update.
2459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static bool AreAutoupdatesEnabled(const base::string16& app_guid);
2469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Attempts to reenable auto-updates for |app_guid| by removing
2489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // any group policy settings that would block updates from occurring. This is
2499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // a superset of the things checked by GetAppUpdatePolicy() as
2509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // GetAppUpdatePolicy() does not check Omaha's AutoUpdateCheckPeriodMinutes
2519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // setting which will be reset by this method. Will need to be called from an
2529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // elevated process since those settings live in HKLM. Returns true if there
2539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // is a reasonable belief that updates are not disabled by policy when this
2549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // method returns, false otherwise. Note that for Chromium builds, this
2559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // returns true since Chromium is assumed not to autoupdate.
2569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static bool ReenableAutoupdatesForApp(const base::string16& app_guid);
2579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Records UMA stats about Chrome's update policy.
2599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static void RecordChromeUpdatePolicyHistograms();
2609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Returns Google Update's uninstall command line, or an empty string if none
2629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // is found.
2639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static base::string16 GetUninstallCommandLine(bool system_install);
2649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Returns the version of Google Update that is installed.
2669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static Version GetGoogleUpdateVersion(bool system_install);
2679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Returns the time at which Google Update last started an automatic update
2699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // check, or the null time if this information isn't available.
2709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static base::Time GetGoogleUpdateLastStartedAU(bool system_install);
2719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Returns the time at which Google Update last successfully contacted Google
2739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // servers and got a valid check response, or the null time if this
2749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // information isn't available.
2759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static base::Time GetGoogleUpdateLastChecked(bool system_install);
2769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Returns detailed update data for a product being managed by Google Update.
2789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Returns true if the |version| and |last_updated| fields in |data|
2799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // are modified.  The other items are considered optional.
2809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static bool GetUpdateDetailForApp(bool system_install,
2819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                                    const wchar_t* app_guid,
2829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                                    ProductData* data);
2839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Returns product data for Google Update.  (Equivalent to calling
2859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // GetUpdateDetailForAppGuid with the app guid for Google Update itself.)
2869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static bool GetUpdateDetailForGoogleUpdate(bool system_install,
2879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                                             ProductData* data);
2889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Returns product data for the current product. (Equivalent to calling
2909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // GetUpdateDetailForApp with the app guid stored in BrowserDistribution.)
2919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static bool GetUpdateDetail(bool system_install, ProductData* data);
2929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Sets |experiment_labels| as the Google Update experiment_labels value in
2949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // the ClientState key for this Chrome product, if appropriate. If
2959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // |experiment_labels| is empty, this will delete the value instead. This will
2969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // return true if the label was successfully set (or deleted), false otherwise
2979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // (even if the label does not need to be set for this particular distribution
2989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // type).
2999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static bool SetExperimentLabels(bool system_install,
3009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                                  const base::string16& experiment_labels);
3019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // Reads the Google Update experiment_labels value in the ClientState key for
3039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // this Chrome product and writes it into |experiment_labels|. If the key or
3049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // value does not exist, |experiment_labels| will be set to the empty string.
3059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // If this distribution of Chrome does not set the experiment_labels value,
3069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // this will do nothing to |experiment_labels|. This will return true if the
3079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  // label did not exist, or was successfully read.
3089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static bool ReadExperimentLabels(bool system_install,
3099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                                   base::string16* experiment_labels);
3109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson private:
3129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  DISALLOW_IMPLICIT_CONSTRUCTORS(GoogleUpdateSettings);
3139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson};
3149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson#endif  // CHROME_INSTALLER_UTIL_GOOGLE_UPDATE_SETTINGS_H_
3169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson