Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: chrome/browser/shell_integration.cc

Issue 10539169: Prototype version of the first-run dialog for Windows 8 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed some of reviewer's remarks. Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/browser/shell_integration.h" 5 #include "chrome/browser/shell_integration.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 /////////////////////////////////////////////////////////////////////////////// 103 ///////////////////////////////////////////////////////////////////////////////
104 // ShellIntegration::DefaultWebClientWorker 104 // ShellIntegration::DefaultWebClientWorker
105 // 105 //
106 106
107 ShellIntegration::DefaultWebClientWorker::DefaultWebClientWorker( 107 ShellIntegration::DefaultWebClientWorker::DefaultWebClientWorker(
108 DefaultWebClientObserver* observer) 108 DefaultWebClientObserver* observer)
109 : observer_(observer) { 109 : observer_(observer) {
110 } 110 }
111 111
112 void ShellIntegration::DefaultWebClientWorker::StartCheckIsDefault() { 112 void ShellIntegration::DefaultWebClientWorker::StartCheckIsDefault() {
113 StartCheckIsDefault(RESULT_SET_DEFAULT_UNDEFINED);
114 }
115
116 void ShellIntegration::DefaultWebClientWorker::StartCheckIsDefault(
117 SetDefaultWebClientResult call_result) {
113 if (observer_) { 118 if (observer_) {
114 observer_->SetDefaultWebClientUIState(STATE_PROCESSING); 119 observer_->SetDefaultWebClientUIState(STATE_PROCESSING, call_result);
115 BrowserThread::PostTask( 120 BrowserThread::PostTask(
116 BrowserThread::FILE, FROM_HERE, 121 BrowserThread::FILE, FROM_HERE,
117 base::Bind( 122 base::Bind(&DefaultWebClientWorker::ExecuteCheckIsDefault, this,
118 &DefaultWebClientWorker::ExecuteCheckIsDefault, this)); 123 call_result));
119 } 124 }
120 } 125 }
121 126
122 void ShellIntegration::DefaultWebClientWorker::StartSetAsDefault() { 127 void ShellIntegration::DefaultWebClientWorker::StartSetAsDefault() {
123 if (observer_) { 128 if (observer_) {
124 observer_->SetDefaultWebClientUIState(STATE_PROCESSING); 129 observer_->SetDefaultWebClientUIState(STATE_PROCESSING,
130 RESULT_SET_DEFAULT_UNDEFINED);
125 } 131 }
126 BrowserThread::PostTask( 132 BrowserThread::PostTask(
127 BrowserThread::FILE, FROM_HERE, 133 BrowserThread::FILE, FROM_HERE,
128 base::Bind( 134 base::Bind(
129 &DefaultWebClientWorker::ExecuteSetAsDefault, this)); 135 &DefaultWebClientWorker::ExecuteSetAsDefault, this));
130 } 136 }
131 137
132 void ShellIntegration::DefaultWebClientWorker::ObserverDestroyed() { 138 void ShellIntegration::DefaultWebClientWorker::ObserverDestroyed() {
133 // Our associated view has gone away, so we shouldn't call back to it if 139 // Our associated view has gone away, so we shouldn't call back to it if
134 // our worker thread returns after the view is dead. 140 // our worker thread returns after the view is dead.
135 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
136 observer_ = NULL; 142 observer_ = NULL;
137 } 143 }
138 144
139 /////////////////////////////////////////////////////////////////////////////// 145 ///////////////////////////////////////////////////////////////////////////////
140 // DefaultWebClientWorker, private: 146 // DefaultWebClientWorker, private:
141 147
142 void ShellIntegration::DefaultWebClientWorker::ExecuteCheckIsDefault() { 148 void ShellIntegration::DefaultWebClientWorker::ExecuteCheckIsDefault(
149 SetDefaultWebClientResult call_result) {
143 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 150 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
144 DefaultWebClientState state = CheckIsDefault(); 151 DefaultWebClientState state = CheckIsDefault();
145 BrowserThread::PostTask( 152 BrowserThread::PostTask(
146 BrowserThread::UI, FROM_HERE, 153 BrowserThread::UI, FROM_HERE,
147 base::Bind( 154 base::Bind(&DefaultWebClientWorker::CompleteCheckIsDefault, this,
148 &DefaultWebClientWorker::CompleteCheckIsDefault, this, state)); 155 state, call_result));
149 } 156 }
150 157
151 void ShellIntegration::DefaultWebClientWorker::CompleteCheckIsDefault( 158 void ShellIntegration::DefaultWebClientWorker::CompleteCheckIsDefault(
152 DefaultWebClientState state) { 159 DefaultWebClientState state, SetDefaultWebClientResult call_result) {
153 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
154 UpdateUI(state); 161 UpdateUI(state, call_result);
155 // The worker has finished everything it needs to do, so free the observer 162 // The worker has finished everything it needs to do, so free the observer
156 // if we own it. 163 // if we own it.
157 if (observer_ && observer_->IsOwnedByWorker()) { 164 if (observer_ && observer_->IsOwnedByWorker()) {
158 delete observer_; 165 delete observer_;
159 observer_ = NULL; 166 observer_ = NULL;
160 } 167 }
161 } 168 }
162 169
163 void ShellIntegration::DefaultWebClientWorker::ExecuteSetAsDefault() { 170 void ShellIntegration::DefaultWebClientWorker::ExecuteSetAsDefault() {
164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 171 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
165 SetAsDefault(observer_ && observer_->IsInteractiveSetDefaultPermitted()); 172 SetDefaultWebClientResult call_result = SetAsDefault(
173 observer_ && observer_->IsInteractiveSetDefaultPermitted());
grt (UTC plus 2) 2012/06/19 20:43:09 apologies for not noticing this on the previous re
motek. 2012/06/20 16:02:15 Done.
166 BrowserThread::PostTask( 174 BrowserThread::PostTask(
167 BrowserThread::UI, FROM_HERE, 175 BrowserThread::UI, FROM_HERE,
168 base::Bind( 176 base::Bind(
169 &DefaultWebClientWorker::CompleteSetAsDefault, this)); 177 &DefaultWebClientWorker::CompleteSetAsDefault, this, call_result));
170 } 178 }
171 179
172 void ShellIntegration::DefaultWebClientWorker::CompleteSetAsDefault() { 180 void ShellIntegration::DefaultWebClientWorker::CompleteSetAsDefault(
181 SetDefaultWebClientResult call_result) {
173 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 182 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
grt (UTC plus 2) 2012/06/19 20:43:09 how about making a member variable to hold call_re
motek. 2012/06/20 16:02:15 I went a different way after all (with a separate
174 // Set as default completed, check again to make sure it stuck... 183 // Set as default completed, check again to make sure it stuck...
175 StartCheckIsDefault(); 184 StartCheckIsDefault(call_result);
176 } 185 }
177 186
178 void ShellIntegration::DefaultWebClientWorker::UpdateUI( 187 void ShellIntegration::DefaultWebClientWorker::UpdateUI(
179 DefaultWebClientState state) { 188 DefaultWebClientState state,
189 SetDefaultWebClientResult call_result) {
180 if (observer_) { 190 if (observer_) {
181 switch (state) { 191 switch (state) {
182 case NOT_DEFAULT_WEB_CLIENT: 192 case NOT_DEFAULT_WEB_CLIENT:
183 observer_->SetDefaultWebClientUIState(STATE_NOT_DEFAULT); 193 observer_->SetDefaultWebClientUIState(STATE_NOT_DEFAULT, call_result);
184 break; 194 break;
185 case IS_DEFAULT_WEB_CLIENT: 195 case IS_DEFAULT_WEB_CLIENT:
186 observer_->SetDefaultWebClientUIState(STATE_IS_DEFAULT); 196 observer_->SetDefaultWebClientUIState(STATE_IS_DEFAULT, call_result);
187 break; 197 break;
188 case UNKNOWN_DEFAULT_WEB_CLIENT: 198 case UNKNOWN_DEFAULT_WEB_CLIENT:
189 observer_->SetDefaultWebClientUIState(STATE_UNKNOWN); 199 observer_->SetDefaultWebClientUIState(STATE_UNKNOWN, call_result);
190 break; 200 break;
191 default: 201 default:
192 break; 202 break;
193 } 203 }
194 } 204 }
195 } 205 }
196 206
197 /////////////////////////////////////////////////////////////////////////////// 207 ///////////////////////////////////////////////////////////////////////////////
198 // ShellIntegration::DefaultBrowserWorker 208 // ShellIntegration::DefaultBrowserWorker
199 // 209 //
200 210
201 ShellIntegration::DefaultBrowserWorker::DefaultBrowserWorker( 211 ShellIntegration::DefaultBrowserWorker::DefaultBrowserWorker(
202 DefaultWebClientObserver* observer) 212 DefaultWebClientObserver* observer)
203 : DefaultWebClientWorker(observer) { 213 : DefaultWebClientWorker(observer) {
204 } 214 }
205 215
206 /////////////////////////////////////////////////////////////////////////////// 216 ///////////////////////////////////////////////////////////////////////////////
207 // DefaultBrowserWorker, private: 217 // DefaultBrowserWorker, private:
208 218
209 ShellIntegration::DefaultWebClientState 219 ShellIntegration::DefaultWebClientState
210 ShellIntegration::DefaultBrowserWorker::CheckIsDefault() { 220 ShellIntegration::DefaultBrowserWorker::CheckIsDefault() {
211 return ShellIntegration::IsDefaultBrowser(); 221 return ShellIntegration::IsDefaultBrowser();
212 } 222 }
213 223
214 void ShellIntegration::DefaultBrowserWorker::SetAsDefault( 224 ShellIntegration::SetDefaultWebClientResult
215 bool interactive_permitted) { 225 ShellIntegration::DefaultBrowserWorker::SetAsDefault(
226 bool interactive_permitted) {
227 SetDefaultWebClientResult result = RESULT_SET_DEFAULT_UNDEFINED;
216 switch (ShellIntegration::CanSetAsDefaultBrowser()) { 228 switch (ShellIntegration::CanSetAsDefaultBrowser()) {
217 case ShellIntegration::SET_DEFAULT_UNATTENDED: 229 case ShellIntegration::SET_DEFAULT_UNATTENDED:
218 ShellIntegration::SetAsDefaultBrowser(); 230 result = ShellIntegration::SetAsDefaultBrowser() ?
231 RESULT_SET_DEFAULT_OK : RESULT_SET_DEFAULT_FAILED_OR_CANCELLED;
219 break; 232 break;
220 case ShellIntegration::SET_DEFAULT_INTERACTIVE: 233 case ShellIntegration::SET_DEFAULT_INTERACTIVE:
221 if (interactive_permitted) 234 if (interactive_permitted) {
222 ShellIntegration::SetAsDefaultBrowserInteractive(); 235 result = ShellIntegration::SetAsDefaultBrowserInteractive() ?
236 RESULT_SET_DEFAULT_OK : RESULT_SET_DEFAULT_FAILED_OR_CANCELLED;
237 }
223 break; 238 break;
224 default: 239 default:
225 NOTREACHED(); 240 NOTREACHED();
226 } 241 }
242 return result;
227 } 243 }
228 244
229 /////////////////////////////////////////////////////////////////////////////// 245 ///////////////////////////////////////////////////////////////////////////////
230 // ShellIntegration::DefaultProtocolClientWorker 246 // ShellIntegration::DefaultProtocolClientWorker
231 // 247 //
232 248
233 ShellIntegration::DefaultProtocolClientWorker::DefaultProtocolClientWorker( 249 ShellIntegration::DefaultProtocolClientWorker::DefaultProtocolClientWorker(
234 DefaultWebClientObserver* observer, const std::string& protocol) 250 DefaultWebClientObserver* observer, const std::string& protocol)
235 : DefaultWebClientWorker(observer), 251 : DefaultWebClientWorker(observer),
236 protocol_(protocol) { 252 protocol_(protocol) {
237 } 253 }
238 254
239 /////////////////////////////////////////////////////////////////////////////// 255 ///////////////////////////////////////////////////////////////////////////////
240 // DefaultProtocolClientWorker, private: 256 // DefaultProtocolClientWorker, private:
241 257
242 ShellIntegration::DefaultWebClientState 258 ShellIntegration::DefaultWebClientState
243 ShellIntegration::DefaultProtocolClientWorker::CheckIsDefault() { 259 ShellIntegration::DefaultProtocolClientWorker::CheckIsDefault() {
244 return ShellIntegration::IsDefaultProtocolClient(protocol_); 260 return ShellIntegration::IsDefaultProtocolClient(protocol_);
245 } 261 }
246 262
247 void ShellIntegration::DefaultProtocolClientWorker::SetAsDefault( 263 ShellIntegration::SetDefaultWebClientResult
248 bool interactive_permitted) { 264 ShellIntegration::DefaultProtocolClientWorker::SetAsDefault(
249 ShellIntegration::SetAsDefaultProtocolClient(protocol_); 265 bool interactive_permitted) {
266 return ShellIntegration::SetAsDefaultProtocolClient(protocol_) ?
267 RESULT_SET_DEFAULT_OK : RESULT_SET_DEFAULT_FAILED_OR_CANCELLED;
250 } 268 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698