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