OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_GOOGLE_GOOGLE_UPDATE_WIN_H_ | 5 #ifndef CHROME_BROWSER_GOOGLE_GOOGLE_UPDATE_WIN_H_ |
6 #define CHROME_BROWSER_GOOGLE_GOOGLE_UPDATE_WIN_H_ | 6 #define CHROME_BROWSER_GOOGLE_GOOGLE_UPDATE_WIN_H_ |
7 | 7 |
8 #include <windows.h> | |
9 | |
8 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/callback_forward.h" | |
9 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
10 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
14 #include "base/win/scoped_comptr.h" | |
11 #include "google_update/google_update_idl.h" | 15 #include "google_update/google_update_idl.h" |
12 | 16 |
13 namespace base { | 17 namespace base { |
14 class MessageLoop; | 18 class TaskRunner; |
15 } | 19 } // namespace base |
16 | |
17 namespace views { | |
18 class Widget; | |
19 } | |
20 | 20 |
21 // The status of the upgrade. UPGRADE_STARTED and UPGRADE_CHECK_STARTED are | 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. | 22 // internal states and will not be reported as results to the listener. |
23 // These values are used for a histogram. Do not reorder. | 23 // These values are used for a histogram. Do not reorder. |
24 enum GoogleUpdateUpgradeResult { | 24 enum GoogleUpdateUpgradeResult { |
25 // The upgrade has started. | 25 // The upgrade has started. |
26 UPGRADE_STARTED = 0, | 26 UPGRADE_STARTED = 0, |
27 // A check for upgrade has been initiated. | 27 // A check for upgrade has been initiated. |
28 UPGRADE_CHECK_STARTED = 1, | 28 UPGRADE_CHECK_STARTED = 1, |
29 // An update is available. | 29 // An update is available. |
(...skipping 15 matching lines...) Expand all Loading... | |
45 // location. This error will appear for developer builds and with | 45 // location. This error will appear for developer builds and with |
46 // installations unzipped to random locations. | 46 // installations unzipped to random locations. |
47 CANNOT_UPGRADE_CHROME_IN_THIS_DIRECTORY = 1, | 47 CANNOT_UPGRADE_CHROME_IN_THIS_DIRECTORY = 1, |
48 // Failed to create Google Update JobServer COM class. | 48 // Failed to create Google Update JobServer COM class. |
49 GOOGLE_UPDATE_JOB_SERVER_CREATION_FAILED = 2, | 49 GOOGLE_UPDATE_JOB_SERVER_CREATION_FAILED = 2, |
50 // Failed to create Google Update OnDemand COM class. | 50 // Failed to create Google Update OnDemand COM class. |
51 GOOGLE_UPDATE_ONDEMAND_CLASS_NOT_FOUND = 3, | 51 GOOGLE_UPDATE_ONDEMAND_CLASS_NOT_FOUND = 3, |
52 // Google Update OnDemand COM class reported an error during a check for | 52 // Google Update OnDemand COM class reported an error during a check for |
53 // update (or while upgrading). | 53 // update (or while upgrading). |
54 GOOGLE_UPDATE_ONDEMAND_CLASS_REPORTED_ERROR = 4, | 54 GOOGLE_UPDATE_ONDEMAND_CLASS_REPORTED_ERROR = 4, |
55 // A call to GetResults failed. | 55 // A call to GetResults failed. DEPRECATED. |
56 GOOGLE_UPDATE_GET_RESULT_CALL_FAILED = 5, | 56 // GOOGLE_UPDATE_GET_RESULT_CALL_FAILED = 5, |
57 // A call to GetVersionInfo failed. | 57 // A call to GetVersionInfo failed. DEPRECATED |
58 GOOGLE_UPDATE_GET_VERSION_INFO_FAILED = 6, | 58 // GOOGLE_UPDATE_GET_VERSION_INFO_FAILED = 6, |
59 // An error occurred while upgrading (or while checking for update). | 59 // An error occurred while upgrading (or while checking for update). |
60 // Check the Google Update log in %TEMP% for more details. | 60 // Check the Google Update log in %TEMP% for more details. |
61 GOOGLE_UPDATE_ERROR_UPDATING = 7, | 61 GOOGLE_UPDATE_ERROR_UPDATING = 7, |
62 // Updates can not be downloaded because the administrator has disabled all | 62 // Updates can not be downloaded because the administrator has disabled all |
63 // types of updating. | 63 // types of updating. |
64 GOOGLE_UPDATE_DISABLED_BY_POLICY = 8, | 64 GOOGLE_UPDATE_DISABLED_BY_POLICY = 8, |
65 // Updates can not be downloaded because the administrator has disabled | 65 // Updates can not be downloaded because the administrator has disabled |
66 // manual (on-demand) updates. Automatic background updates are allowed. | 66 // manual (on-demand) updates. Automatic background updates are allowed. |
67 GOOGLE_UPDATE_DISABLED_BY_POLICY_AUTO_ONLY = 9, | 67 GOOGLE_UPDATE_DISABLED_BY_POLICY_AUTO_ONLY = 9, |
68 NUM_ERROR_CODES | 68 NUM_ERROR_CODES |
69 }; | 69 }; |
70 | 70 |
71 // The GoogleUpdateStatusListener interface is used by components to receive | 71 // A callback run when a check for updates has completed. |result| indicates the |
72 // notifications about the results of an Google Update operation. | 72 // end state of the operation. When |result| is UPGRADE_ERROR, |error_code| and |
73 class GoogleUpdateStatusListener { | 73 // |error_message| indicate the the nature of the error. When |result| is |
74 public: | 74 // UPGRADE_IS_AVAILABLE or UPGRADE_SUCCESSFUL, |version| may indicate the new |
75 // This function is called when Google Update has finished its operation and | 75 // version Google Update detected (it may, however, be empty). |
76 // wants to notify us about the results. |results| represents what the end | 76 typedef base::Callback<void(GoogleUpdateUpgradeResult result, |
77 // state is, |error_code| represents what error occurred, |error_message| is a | 77 GoogleUpdateErrorCode error_code, |
78 // string version of the same (might be blank) and |version| specifies what | 78 const base::string16& error_message, |
79 // new version Google Update detected (or installed). This value can be a | 79 const base::string16& version)> UpdateCheckCallback; |
80 // blank string, if the version tag in the Update{} block (in Google Update's | |
81 // server config for Chrome) is blank. | |
82 virtual void OnReportResults(GoogleUpdateUpgradeResult results, | |
83 GoogleUpdateErrorCode error_code, | |
84 const base::string16& error_message, | |
85 const base::string16& version) = 0; | |
86 }; | |
87 | 80 |
88 //////////////////////////////////////////////////////////////////////////////// | 81 // Initiates an update check on the FILE thread. If |install_if_newer| is true, |
89 // | 82 // an update will be applied. |elevation_window| is the window which should own |
90 // The Google Update class is responsible for communicating with Google Update | 83 // any necessary elevation UI. |callback| will be run on the caller's thread |
91 // and get it to perform operations on our behalf (for example, CheckForUpdate). | 84 // when the check completes. |
92 // This class will report back to its parent via the GoogleUpdateStatusListener | 85 void CheckForUpdate(bool install_if_newer, |
93 // interface and will delete itself after reporting back. | 86 HWND elevation_window, |
94 // | 87 const UpdateCheckCallback& callback); |
95 //////////////////////////////////////////////////////////////////////////////// | |
96 class GoogleUpdate : public base::RefCountedThreadSafe<GoogleUpdate> { | |
97 public: | |
98 GoogleUpdate(); | |
99 | 88 |
100 // Ask Google Update to see if a new version is available. If the parameter | 89 namespace internal { |
Peter Kasting
2014/11/26 22:13:05
We also shouldn't be using an ad-hoc "internal" na
grt (UTC plus 2)
2014/11/27 04:44:57
I don't understand this suggestion, nor why it see
Peter Kasting
2014/11/27 08:07:34
Namespace usage in Chrome has been discussed on th
| |
101 // |install_if_newer| is true then Google Update will also install that new | |
102 // version. | |
103 // |window| should point to a foreground window. This is needed to ensure | |
104 // that Vista/Windows 7 UAC prompts show up in the foreground. It may also | |
105 // be null. | |
106 void CheckForUpdate(bool install_if_newer, HWND window); | |
107 | 90 |
108 // Pass NULL to clear the listener | 91 // A type of callback supplied by tests to provide a custom IGoogleUpdate |
109 void set_status_listener(GoogleUpdateStatusListener* listener) { | 92 // implementation. |
110 listener_ = listener; | 93 typedef base::Callback<HRESULT(base::win::ScopedComPtr<IGoogleUpdate>*)> |
111 } | 94 OnDemandAppsClassFactory; |
112 | 95 |
113 private: | 96 // For use by tests that wish to provide a custom IGoogleUpdate implementation |
114 friend class base::RefCountedThreadSafe<GoogleUpdate>; | 97 // independent of Google Update's. |
98 void SetGoogleUpdateFactory( | |
99 const OnDemandAppsClassFactory& google_update_factory); | |
115 | 100 |
116 virtual ~GoogleUpdate(); | 101 // Runs the update check described in CheckForUpdate above on |task_runner|. |
102 // Exposed for unit testing. | |
103 void CheckForUpdate(const scoped_refptr<base::TaskRunner>& task_runner, | |
104 bool install_if_newer, | |
105 HWND elevation_window, | |
106 const UpdateCheckCallback& callback); | |
117 | 107 |
118 // This function reports failure from the Google Update operation to the | 108 } // namespace internal |
119 // listener. | |
120 // Note, after this function completes, this object will have deleted itself. | |
121 bool ReportFailure(HRESULT hr, GoogleUpdateErrorCode error_code, | |
122 const base::string16& error_message, | |
123 base::MessageLoop* main_loop); | |
124 | |
125 // The update check needs to run on another thread than the main thread, and | |
126 // therefore CheckForUpdate will delegate to this function. |main_loop| points | |
127 // to the message loop that the response must come from. | |
128 // |window| should point to a foreground window. This is needed to ensure that | |
129 // Vista/Windows 7 UAC prompts show up in the foreground. It may also be null. | |
130 void InitiateGoogleUpdateCheck(bool install_if_newer, HWND window, | |
131 base::MessageLoop* main_loop); | |
132 | |
133 // This function reports the results of the GoogleUpdate operation to the | |
134 // listener. If results indicates an error, the |error_code| and | |
135 // |error_message| will indicate which error occurred. | |
136 // Note, after this function completes, this object will have deleted itself. | |
137 void ReportResults(GoogleUpdateUpgradeResult results, | |
138 GoogleUpdateErrorCode error_code, | |
139 const base::string16& error_message); | |
140 | |
141 // Which version string Google Update found (if a new one was available). | |
142 // Otherwise, this will be blank. | |
143 base::string16 version_available_; | |
144 | |
145 // The listener who is interested in finding out the result of the operation. | |
146 GoogleUpdateStatusListener* listener_; | |
147 | |
148 DISALLOW_COPY_AND_ASSIGN(GoogleUpdate); | |
149 }; | |
150 | 109 |
151 #endif // CHROME_BROWSER_GOOGLE_GOOGLE_UPDATE_WIN_H_ | 110 #endif // CHROME_BROWSER_GOOGLE_GOOGLE_UPDATE_WIN_H_ |
OLD | NEW |