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 #include "base/memory/weak_ptr.h" | 5 #include "base/memory/weak_ptr.h" |
6 #include "base/strings/string16.h" | 6 #include "base/strings/string16.h" |
| 7 #include "base/task_runner_util.h" |
7 #include "base/win/win_util.h" | 8 #include "base/win/win_util.h" |
8 #include "base/win/windows_version.h" | 9 #include "base/win/windows_version.h" |
9 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/first_run/upgrade_util_win.h" | 11 #include "chrome/browser/first_run/upgrade_util.h" |
11 #include "chrome/browser/google/google_update_win.h" | 12 #include "chrome/browser/google/google_update_win.h" |
12 #include "chrome/browser/lifetime/application_lifetime.h" | 13 #include "chrome/browser/lifetime/application_lifetime.h" |
13 #include "chrome/browser/ui/webui/help/version_updater.h" | 14 #include "chrome/browser/ui/webui/help/version_updater.h" |
14 #include "chrome/grit/generated_resources.h" | 15 #include "chrome/grit/generated_resources.h" |
15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
16 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
17 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
18 #include "ui/aura/window_tree_host.h" | 19 #include "ui/aura/window_tree_host.h" |
19 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
20 #include "ui/gfx/native_widget_types.h" | 21 #include "ui/gfx/native_widget_types.h" |
(...skipping 21 matching lines...) Expand all Loading... |
42 void OnUpgradeComplete(const base::string16& new_version) override; | 43 void OnUpgradeComplete(const base::string16& new_version) override; |
43 void OnError(GoogleUpdateErrorCode error_code, | 44 void OnError(GoogleUpdateErrorCode error_code, |
44 const base::string16& error_message, | 45 const base::string16& error_message, |
45 const base::string16& new_version) override; | 46 const base::string16& new_version) override; |
46 | 47 |
47 private: | 48 private: |
48 #if defined(GOOGLE_CHROME_BUILD) | 49 #if defined(GOOGLE_CHROME_BUILD) |
49 void BeginUpdateCheckOnFileThread(bool install_update_if_possible); | 50 void BeginUpdateCheckOnFileThread(bool install_update_if_possible); |
50 #endif // GOOGLE_CHROME_BUILD | 51 #endif // GOOGLE_CHROME_BUILD |
51 | 52 |
| 53 // A task run on the UI thread with the result of checking for a pending |
| 54 // restart. |
| 55 void OnPendingRestartCheck(bool is_update_pending_restart); |
| 56 |
52 // The widget owning the UI for the update check. | 57 // The widget owning the UI for the update check. |
53 gfx::AcceleratedWidget owner_widget_; | 58 gfx::AcceleratedWidget owner_widget_; |
54 | 59 |
55 // Callback used to communicate update status to the client. | 60 // Callback used to communicate update status to the client. |
56 StatusCallback callback_; | 61 StatusCallback callback_; |
57 | 62 |
58 // Used for callbacks. | 63 // Used for callbacks. |
59 base::WeakPtrFactory<VersionUpdaterWin> weak_factory_; | 64 base::WeakPtrFactory<VersionUpdaterWin> weak_factory_; |
60 | 65 |
61 DISALLOW_COPY_AND_ASSIGN(VersionUpdaterWin); | 66 DISALLOW_COPY_AND_ASSIGN(VersionUpdaterWin); |
(...skipping 30 matching lines...) Expand all Loading... |
92 } | 97 } |
93 | 98 |
94 void VersionUpdaterWin::OnUpdateCheckComplete( | 99 void VersionUpdaterWin::OnUpdateCheckComplete( |
95 const base::string16& new_version) { | 100 const base::string16& new_version) { |
96 #if defined(GOOGLE_CHROME_BUILD) | 101 #if defined(GOOGLE_CHROME_BUILD) |
97 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 102 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
98 Status status = CHECKING; | 103 Status status = CHECKING; |
99 if (new_version.empty()) { | 104 if (new_version.empty()) { |
100 // Google Update says that no new version is available. Check to see if a | 105 // Google Update says that no new version is available. Check to see if a |
101 // restart is needed for a previously-applied update to take effect. | 106 // restart is needed for a previously-applied update to take effect. |
102 status = upgrade_util::IsRunningOldChrome() ? NEARLY_UPDATED : UPDATED; | 107 if (base::PostTaskAndReplyWithResult( |
| 108 content::BrowserThread::GetBlockingPool(), |
| 109 FROM_HERE, |
| 110 base::Bind(&upgrade_util::IsUpdatePendingRestart), |
| 111 base::Bind(&VersionUpdaterWin::OnPendingRestartCheck, |
| 112 weak_factory_.GetWeakPtr()))) { |
| 113 // Early exit since callback_ will be Run in OnPendingRestartCheck. |
| 114 return; |
| 115 } |
| 116 // Failure to post the task means that Chrome is shutting down. A pending |
| 117 // update (if there is one) will be applied as Chrome exits, so tell the |
| 118 // caller that it is up to date in either case. |
| 119 status = UPDATED; |
103 } else { | 120 } else { |
104 // Notify the caller that the update is now beginning and initiate it. | 121 // Notify the caller that the update is now beginning and initiate it. |
105 status = UPDATING; | 122 status = UPDATING; |
106 BeginUpdateCheckOnFileThread(true /* install_update_if_possible */); | 123 BeginUpdateCheckOnFileThread(true /* install_update_if_possible */); |
107 } | 124 } |
108 callback_.Run(status, 0, base::string16()); | 125 callback_.Run(status, 0, base::string16()); |
109 #endif // GOOGLE_CHROME_BUILD | 126 #endif // GOOGLE_CHROME_BUILD |
110 } | 127 } |
111 | 128 |
112 void VersionUpdaterWin::OnUpgradeProgress(int progress, | 129 void VersionUpdaterWin::OnUpgradeProgress(int progress, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 void VersionUpdaterWin::BeginUpdateCheckOnFileThread( | 166 void VersionUpdaterWin::BeginUpdateCheckOnFileThread( |
150 bool install_update_if_possible) { | 167 bool install_update_if_possible) { |
151 BeginUpdateCheck(content::BrowserThread::GetMessageLoopProxyForThread( | 168 BeginUpdateCheck(content::BrowserThread::GetMessageLoopProxyForThread( |
152 content::BrowserThread::FILE), | 169 content::BrowserThread::FILE), |
153 g_browser_process->GetApplicationLocale(), | 170 g_browser_process->GetApplicationLocale(), |
154 install_update_if_possible, owner_widget_, | 171 install_update_if_possible, owner_widget_, |
155 weak_factory_.GetWeakPtr()); | 172 weak_factory_.GetWeakPtr()); |
156 } | 173 } |
157 #endif // GOOGLE_CHROME_BUILD | 174 #endif // GOOGLE_CHROME_BUILD |
158 | 175 |
| 176 void VersionUpdaterWin::OnPendingRestartCheck(bool is_update_pending_restart) { |
| 177 callback_.Run(is_update_pending_restart ? NEARLY_UPDATED : UPDATED, 0, |
| 178 base::string16()); |
| 179 } |
| 180 |
159 } // namespace | 181 } // namespace |
160 | 182 |
161 VersionUpdater* VersionUpdater::Create(content::WebContents* web_contents) { | 183 VersionUpdater* VersionUpdater::Create(content::WebContents* web_contents) { |
162 // Retrieve the HWND for the browser window that is hosting the update check. | 184 // Retrieve the HWND for the browser window that is hosting the update check. |
163 // This will be used as the parent for a UAC prompt, if needed. It's possible | 185 // This will be used as the parent for a UAC prompt, if needed. It's possible |
164 // this this window will no longer have focus by the time UAC is needed. In | 186 // this this window will no longer have focus by the time UAC is needed. In |
165 // that case, the UAC prompt will appear in the taskbar and will require a | 187 // that case, the UAC prompt will appear in the taskbar and will require a |
166 // user click. This is the least surprising thing we can do for the user, and | 188 // user click. This is the least surprising thing we can do for the user, and |
167 // is the intended behavior for Windows applications. It's also possible that | 189 // is the intended behavior for Windows applications. It's also possible that |
168 // the browser window hosting the update check will have been closed by the | 190 // the browser window hosting the update check will have been closed by the |
169 // time the UAC prompt is needed. This will behave similarly. | 191 // time the UAC prompt is needed. This will behave similarly. |
170 return new VersionUpdaterWin(web_contents->GetTopLevelNativeWindow() | 192 return new VersionUpdaterWin(web_contents->GetTopLevelNativeWindow() |
171 ->GetHost() | 193 ->GetHost() |
172 ->GetAcceleratedWidget()); | 194 ->GetAcceleratedWidget()); |
173 } | 195 } |
OLD | NEW |