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.
5 #ifndef CHROME_BROWSER_GOOGLE_GOOGLE_UPDATE_WIN_H_
6 #define CHROME_BROWSER_GOOGLE_GOOGLE_UPDATE_WIN_H_
8 #include "base/basictypes.h"
9 #include "base/callback_forward.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/strings/string16.h"
13 #include "base/win/scoped_comptr.h"
14 #include "google_update/google_update_idl.h"
15 #include "ui/gfx/native_widget_types.h"
18 class SingleThreadTaskRunner
;
21 // These values are used for a histogram. Do not reorder.
22 enum GoogleUpdateErrorCode
{
23 // The upgrade completed successfully (or hasn't been started yet).
24 GOOGLE_UPDATE_NO_ERROR
= 0,
25 // Google Update only supports upgrading if Chrome is installed in the default
26 // location. This error will appear for developer builds and with
27 // installations unzipped to random locations.
28 CANNOT_UPGRADE_CHROME_IN_THIS_DIRECTORY
= 1,
29 // Failed to create Google Update JobServer COM class. DEPRECATED.
30 // GOOGLE_UPDATE_JOB_SERVER_CREATION_FAILED = 2,
31 // Failed to create Google Update OnDemand COM class.
32 GOOGLE_UPDATE_ONDEMAND_CLASS_NOT_FOUND
= 3,
33 // Google Update OnDemand COM class reported an error during a check for
34 // update (or while upgrading).
35 GOOGLE_UPDATE_ONDEMAND_CLASS_REPORTED_ERROR
= 4,
36 // A call to GetResults failed. DEPRECATED.
37 // GOOGLE_UPDATE_GET_RESULT_CALL_FAILED = 5,
38 // A call to GetVersionInfo failed. DEPRECATED
39 // GOOGLE_UPDATE_GET_VERSION_INFO_FAILED = 6,
40 // An error occurred while upgrading (or while checking for update).
41 // Check the Google Update log in %TEMP% for more details.
42 GOOGLE_UPDATE_ERROR_UPDATING
= 7,
43 // Updates can not be downloaded because the administrator has disabled all
45 GOOGLE_UPDATE_DISABLED_BY_POLICY
= 8,
46 // Updates can not be downloaded because the administrator has disabled
47 // manual (on-demand) updates. Automatic background updates are allowed.
49 // GOOGLE_UPDATE_DISABLED_BY_POLICY_AUTO_ONLY = 9,
53 // A delegate by which a caller of BeginUpdateCheck is notified of the status
54 // and results of an update check.
55 class UpdateCheckDelegate
{
57 virtual ~UpdateCheckDelegate() {}
59 // Invoked following a successful update check. |new_version|, if not empty,
60 // indicates the new version that is available. Otherwise (if |new_version| is
61 // empty), Chrome is up to date. This method will only be invoked when
62 // BeginUpdateCheck is called with |install_update_if_possible| == false.
63 virtual void OnUpdateCheckComplete(const base::string16
& new_version
) = 0;
65 // Invoked zero or more times during an upgrade. |progress|, a number between
66 // 0 and 100 (inclusive), is an estimation as to what percentage of the
67 // upgrade has completed. |new_version| indicates the version that is being
68 // download and installed. This method will only be invoked when
69 // BeginUpdateCheck is called with |install_update_if_possible| == true.
70 virtual void OnUpgradeProgress(int progress
,
71 const base::string16
& new_version
) = 0;
73 // Invoked following a successful upgrade. |new_version| indicates the version
74 // to which Chrome was updated. This method will only be invoked when
75 // BeginUpdateCheck is called with |install_update_if_possible| == true.
76 virtual void OnUpgradeComplete(const base::string16
& new_version
) = 0;
78 // Invoked following an unrecoverable error, indicated by |error_code|.
79 // |html_error_message|, if not empty, must be a localized string containing
80 // all information required by users to act on the error as well as for
81 // support staff to diagnose it (i.e. |error_code| and any other related
82 // state information). |new_version|, if not empty, indicates the version
83 // to which an upgrade attempt was made.
84 virtual void OnError(GoogleUpdateErrorCode error_code
,
85 const base::string16
& html_error_message
,
86 const base::string16
& new_version
) = 0;
89 UpdateCheckDelegate() {}
92 // Begins an asynchronous update check on |task_runner|. If a new version is
93 // available and |install_update_if_possible| is true, the new version will be
94 // automatically downloaded and installed. |elevation_window| is the window
95 // which should own any necessary elevation UI. Methods on |delegate| will be
96 // invoked on the caller's thread to provide feedback on the operation, with
97 // messages localized to |locale| if possible.
98 void BeginUpdateCheck(
99 const scoped_refptr
<base::SingleThreadTaskRunner
>& task_runner
,
100 const std::string
& locale
,
101 bool install_update_if_possible
,
102 gfx::AcceleratedWidget elevation_window
,
103 const base::WeakPtr
<UpdateCheckDelegate
>& delegate
);
105 // A type of callback supplied by tests to provide a custom IGoogleUpdate3Web
106 // implementation (see src/google_update/google_update_idl.idl).
107 typedef base::Callback
<HRESULT(base::win::ScopedComPtr
<IGoogleUpdate3Web
>*)>
108 GoogleUpdate3ClassFactory
;
110 // For use by tests that wish to provide a custom IGoogleUpdate3Web
111 // implementation independent of Google Update's.
112 void SetGoogleUpdateFactoryForTesting(
113 const GoogleUpdate3ClassFactory
& google_update_factory
);
115 #endif // CHROME_BROWSER_GOOGLE_GOOGLE_UPDATE_WIN_H_