1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_GOOGLE_GOOGLE_UPDATE_WIN_H_ 6 #define CHROME_BROWSER_GOOGLE_GOOGLE_UPDATE_WIN_H_ 7 8 #include "base/basictypes.h" 9 #include "base/memory/ref_counted.h" 10 #include "base/strings/string16.h" 11 #include "google_update/google_update_idl.h" 12 13 namespace base { 14 class MessageLoop; 15 } 16 17 namespace views { 18 class Widget; 19 } 20 21 // The status of the upgrade. UPGRADE_STARTED and UPGRADE_CHECK_STARTED are 22 // internal states and will not be reported as results to the listener. 23 enum GoogleUpdateUpgradeResult { 24 // The upgrade has started. 25 UPGRADE_STARTED = 0, 26 // A check for upgrade has been initiated. 27 UPGRADE_CHECK_STARTED, 28 // An update is available. 29 UPGRADE_IS_AVAILABLE, 30 // The upgrade happened successfully. 31 UPGRADE_SUCCESSFUL, 32 // No need to upgrade, Chrome is up to date. 33 UPGRADE_ALREADY_UP_TO_DATE, 34 // An error occurred. 35 UPGRADE_ERROR, 36 }; 37 38 enum GoogleUpdateErrorCode { 39 // The upgrade completed successfully (or hasn't been started yet). 40 GOOGLE_UPDATE_NO_ERROR = 0, 41 // Google Update only supports upgrading if Chrome is installed in the default 42 // location. This error will appear for developer builds and with 43 // installations unzipped to random locations. 44 CANNOT_UPGRADE_CHROME_IN_THIS_DIRECTORY, 45 // Failed to create Google Update JobServer COM class. 46 GOOGLE_UPDATE_JOB_SERVER_CREATION_FAILED, 47 // Failed to create Google Update OnDemand COM class. 48 GOOGLE_UPDATE_ONDEMAND_CLASS_NOT_FOUND, 49 // Google Update OnDemand COM class reported an error during a check for 50 // update (or while upgrading). 51 GOOGLE_UPDATE_ONDEMAND_CLASS_REPORTED_ERROR, 52 // A call to GetResults failed. 53 GOOGLE_UPDATE_GET_RESULT_CALL_FAILED, 54 // A call to GetVersionInfo failed. 55 GOOGLE_UPDATE_GET_VERSION_INFO_FAILED, 56 // An error occurred while upgrading (or while checking for update). 57 // Check the Google Update log in %TEMP% for more details. 58 GOOGLE_UPDATE_ERROR_UPDATING, 59 // Updates can not be downloaded because the administrator has disabled all 60 // types of updating. 61 GOOGLE_UPDATE_DISABLED_BY_POLICY, 62 // Updates can not be downloaded because the administrator has disabled 63 // manual (on-demand) updates. Automatic background updates are allowed. 64 GOOGLE_UPDATE_DISABLED_BY_POLICY_AUTO_ONLY, 65 }; 66 67 // The GoogleUpdateStatusListener interface is used by components to receive 68 // notifications about the results of an Google Update operation. 69 class GoogleUpdateStatusListener { 70 public: 71 // This function is called when Google Update has finished its operation and 72 // wants to notify us about the results. |results| represents what the end 73 // state is, |error_code| represents what error occurred, |error_message| is a 74 // string version of the same (might be blank) and |version| specifies what 75 // new version Google Update detected (or installed). This value can be a 76 // blank string, if the version tag in the Update{} block (in Google Update's 77 // server config for Chrome) is blank. 78 virtual void OnReportResults(GoogleUpdateUpgradeResult results, 79 GoogleUpdateErrorCode error_code, 80 const base::string16& error_message, 81 const base::string16& version) = 0; 82 }; 83 84 //////////////////////////////////////////////////////////////////////////////// 85 // 86 // The Google Update class is responsible for communicating with Google Update 87 // and get it to perform operations on our behalf (for example, CheckForUpdate). 88 // This class will report back to its parent via the GoogleUpdateStatusListener 89 // interface and will delete itself after reporting back. 90 // 91 //////////////////////////////////////////////////////////////////////////////// 92 class GoogleUpdate : public base::RefCountedThreadSafe<GoogleUpdate> { 93 public: 94 GoogleUpdate(); 95 96 // Ask Google Update to see if a new version is available. If the parameter 97 // |install_if_newer| is true then Google Update will also install that new 98 // version. 99 // |window| should point to a foreground window. This is needed to ensure 100 // that Vista/Windows 7 UAC prompts show up in the foreground. It may also 101 // be null. 102 void CheckForUpdate(bool install_if_newer, HWND window); 103 104 // Pass NULL to clear the listener 105 void set_status_listener(GoogleUpdateStatusListener* listener) { 106 listener_ = listener; 107 } 108 109 private: 110 friend class base::RefCountedThreadSafe<GoogleUpdate>; 111 112 virtual ~GoogleUpdate(); 113 114 // This function reports failure from the Google Update operation to the 115 // listener. 116 // Note, after this function completes, this object will have deleted itself. 117 bool ReportFailure(HRESULT hr, GoogleUpdateErrorCode error_code, 118 const base::string16& error_message, 119 base::MessageLoop* main_loop); 120 121 // The update check needs to run on another thread than the main thread, and 122 // therefore CheckForUpdate will delegate to this function. |main_loop| points 123 // to the message loop that the response must come from. 124 // |window| should point to a foreground window. This is needed to ensure that 125 // Vista/Windows 7 UAC prompts show up in the foreground. It may also be null. 126 void InitiateGoogleUpdateCheck(bool install_if_newer, HWND window, 127 base::MessageLoop* main_loop); 128 129 // This function reports the results of the GoogleUpdate operation to the 130 // listener. If results indicates an error, the |error_code| and 131 // |error_message| will indicate which error occurred. 132 // Note, after this function completes, this object will have deleted itself. 133 void ReportResults(GoogleUpdateUpgradeResult results, 134 GoogleUpdateErrorCode error_code, 135 const base::string16& error_message); 136 137 // Which version string Google Update found (if a new one was available). 138 // Otherwise, this will be blank. 139 base::string16 version_available_; 140 141 // The listener who is interested in finding out the result of the operation. 142 GoogleUpdateStatusListener* listener_; 143 144 DISALLOW_COPY_AND_ASSIGN(GoogleUpdate); 145 }; 146 147 #endif // CHROME_BROWSER_GOOGLE_GOOGLE_UPDATE_WIN_H_ 148