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

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: Fixed non-windows compilation errors. 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,
grt (UTC plus 2) 2012/06/18 19:19:13 chromium prefers to conserve vertical space in fun
motek. 2012/06/19 18:06:44 Done.
118 &DefaultWebClientWorker::ExecuteCheckIsDefault, this)); 123 this,
124 call_result));
119 } 125 }
120 } 126 }
121 127
122 void ShellIntegration::DefaultWebClientWorker::StartSetAsDefault() { 128 void ShellIntegration::DefaultWebClientWorker::StartSetAsDefault() {
123 if (observer_) { 129 if (observer_) {
124 observer_->SetDefaultWebClientUIState(STATE_PROCESSING); 130 observer_->SetDefaultWebClientUIState(STATE_PROCESSING,
131 RESULT_SET_DEFAULT_UNDEFINED);
125 } 132 }
126 BrowserThread::PostTask( 133 BrowserThread::PostTask(
127 BrowserThread::FILE, FROM_HERE, 134 BrowserThread::FILE, FROM_HERE,
128 base::Bind( 135 base::Bind(
129 &DefaultWebClientWorker::ExecuteSetAsDefault, this)); 136 &DefaultWebClientWorker::ExecuteSetAsDefault, this));
130 } 137 }
131 138
132 void ShellIntegration::DefaultWebClientWorker::ObserverDestroyed() { 139 void ShellIntegration::DefaultWebClientWorker::ObserverDestroyed() {
133 // Our associated view has gone away, so we shouldn't call back to it if 140 // 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. 141 // our worker thread returns after the view is dead.
135 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
136 observer_ = NULL; 143 observer_ = NULL;
137 } 144 }
138 145
139 /////////////////////////////////////////////////////////////////////////////// 146 ///////////////////////////////////////////////////////////////////////////////
140 // DefaultWebClientWorker, private: 147 // DefaultWebClientWorker, private:
141 148
142 void ShellIntegration::DefaultWebClientWorker::ExecuteCheckIsDefault() { 149 void ShellIntegration::DefaultWebClientWorker::ExecuteCheckIsDefault(
150 SetDefaultWebClientResult call_result) {
143 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 151 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
144 DefaultWebClientState state = CheckIsDefault(); 152 DefaultWebClientState state = CheckIsDefault();
145 BrowserThread::PostTask( 153 BrowserThread::PostTask(
146 BrowserThread::UI, FROM_HERE, 154 BrowserThread::UI, FROM_HERE,
147 base::Bind( 155 base::Bind(&DefaultWebClientWorker::CompleteCheckIsDefault,
grt (UTC plus 2) 2012/06/18 19:19:13 same note about condensing args
motek. 2012/06/19 18:06:44 Done.
148 &DefaultWebClientWorker::CompleteCheckIsDefault, this, state)); 156 this,
157 state,
158 call_result));
149 } 159 }
150 160
151 void ShellIntegration::DefaultWebClientWorker::CompleteCheckIsDefault( 161 void ShellIntegration::DefaultWebClientWorker::CompleteCheckIsDefault(
152 DefaultWebClientState state) { 162 DefaultWebClientState state, SetDefaultWebClientResult call_result) {
153 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
154 UpdateUI(state); 164 UpdateUI(state, call_result);
155 // The worker has finished everything it needs to do, so free the observer 165 // The worker has finished everything it needs to do, so free the observer
156 // if we own it. 166 // if we own it.
157 if (observer_ && observer_->IsOwnedByWorker()) { 167 if (observer_ && observer_->IsOwnedByWorker()) {
158 delete observer_; 168 delete observer_;
159 observer_ = NULL; 169 observer_ = NULL;
160 } 170 }
161 } 171 }
162 172
163 void ShellIntegration::DefaultWebClientWorker::ExecuteSetAsDefault() { 173 void ShellIntegration::DefaultWebClientWorker::ExecuteSetAsDefault() {
164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 174 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
165 SetAsDefault(observer_ && observer_->IsInteractiveSetDefaultPermitted()); 175 SetDefaultWebClientResult call_result = SetAsDefault(
176 observer_ && observer_->IsInteractiveSetDefaultPermitted());
166 BrowserThread::PostTask( 177 BrowserThread::PostTask(
167 BrowserThread::UI, FROM_HERE, 178 BrowserThread::UI, FROM_HERE,
168 base::Bind( 179 base::Bind(
169 &DefaultWebClientWorker::CompleteSetAsDefault, this)); 180 &DefaultWebClientWorker::CompleteSetAsDefault, this, call_result));
170 } 181 }
171 182
172 void ShellIntegration::DefaultWebClientWorker::CompleteSetAsDefault() { 183 void ShellIntegration::DefaultWebClientWorker::CompleteSetAsDefault(
184 SetDefaultWebClientResult call_result) {
173 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 185 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
174 // Set as default completed, check again to make sure it stuck... 186 // Set as default completed, check again to make sure it stuck...
175 StartCheckIsDefault(); 187 StartCheckIsDefault(call_result);
grt (UTC plus 2) 2012/06/18 19:19:13 is there any reason to do this when call_result is
motek. 2012/06/19 18:06:44 I think so. It may be a debug blindness, but I inv
grt (UTC plus 2) 2012/06/19 20:43:09 do you mean that the browser choice dialog pops up
176 } 188 }
177 189
178 void ShellIntegration::DefaultWebClientWorker::UpdateUI( 190 void ShellIntegration::DefaultWebClientWorker::UpdateUI(
179 DefaultWebClientState state) { 191 DefaultWebClientState state,
192 SetDefaultWebClientResult call_result) {
180 if (observer_) { 193 if (observer_) {
181 switch (state) { 194 switch (state) {
182 case NOT_DEFAULT_WEB_CLIENT: 195 case NOT_DEFAULT_WEB_CLIENT:
183 observer_->SetDefaultWebClientUIState(STATE_NOT_DEFAULT); 196 observer_->SetDefaultWebClientUIState(STATE_NOT_DEFAULT, call_result);
184 break; 197 break;
185 case IS_DEFAULT_WEB_CLIENT: 198 case IS_DEFAULT_WEB_CLIENT:
186 observer_->SetDefaultWebClientUIState(STATE_IS_DEFAULT); 199 observer_->SetDefaultWebClientUIState(STATE_IS_DEFAULT, call_result);
187 break; 200 break;
188 case UNKNOWN_DEFAULT_WEB_CLIENT: 201 case UNKNOWN_DEFAULT_WEB_CLIENT:
189 observer_->SetDefaultWebClientUIState(STATE_UNKNOWN); 202 observer_->SetDefaultWebClientUIState(STATE_UNKNOWN, call_result);
190 break; 203 break;
191 default: 204 default:
192 break; 205 break;
193 } 206 }
194 } 207 }
195 } 208 }
196 209
197 /////////////////////////////////////////////////////////////////////////////// 210 ///////////////////////////////////////////////////////////////////////////////
198 // ShellIntegration::DefaultBrowserWorker 211 // ShellIntegration::DefaultBrowserWorker
199 // 212 //
200 213
201 ShellIntegration::DefaultBrowserWorker::DefaultBrowserWorker( 214 ShellIntegration::DefaultBrowserWorker::DefaultBrowserWorker(
202 DefaultWebClientObserver* observer) 215 DefaultWebClientObserver* observer)
203 : DefaultWebClientWorker(observer) { 216 : DefaultWebClientWorker(observer) {
204 } 217 }
205 218
206 /////////////////////////////////////////////////////////////////////////////// 219 ///////////////////////////////////////////////////////////////////////////////
207 // DefaultBrowserWorker, private: 220 // DefaultBrowserWorker, private:
208 221
209 ShellIntegration::DefaultWebClientState 222 ShellIntegration::DefaultWebClientState
210 ShellIntegration::DefaultBrowserWorker::CheckIsDefault() { 223 ShellIntegration::DefaultBrowserWorker::CheckIsDefault() {
211 return ShellIntegration::IsDefaultBrowser(); 224 return ShellIntegration::IsDefaultBrowser();
212 } 225 }
213 226
214 void ShellIntegration::DefaultBrowserWorker::SetAsDefault( 227 ShellIntegration::SetDefaultWebClientResult
215 bool interactive_permitted) { 228 ShellIntegration::DefaultBrowserWorker::SetAsDefault(
229 bool interactive_permitted) {
230 SetDefaultWebClientResult result = RESULT_SET_DEFAULT_UNDEFINED;
216 switch (ShellIntegration::CanSetAsDefaultBrowser()) { 231 switch (ShellIntegration::CanSetAsDefaultBrowser()) {
217 case ShellIntegration::SET_DEFAULT_UNATTENDED: 232 case ShellIntegration::SET_DEFAULT_UNATTENDED:
218 ShellIntegration::SetAsDefaultBrowser(); 233 result = ShellIntegration::SetAsDefaultBrowser() ?
234 RESULT_SET_DEFAULT_OK : RESULT_SET_DEFAULT_FAILED_OR_CANCELLED;
219 break; 235 break;
220 case ShellIntegration::SET_DEFAULT_INTERACTIVE: 236 case ShellIntegration::SET_DEFAULT_INTERACTIVE:
221 if (interactive_permitted) 237 if (interactive_permitted) {
222 ShellIntegration::SetAsDefaultBrowserInteractive(); 238 result = ShellIntegration::SetAsDefaultBrowserInteractive() ?
239 RESULT_SET_DEFAULT_OK : RESULT_SET_DEFAULT_FAILED_OR_CANCELLED;
240 }
223 break; 241 break;
224 default: 242 default:
225 NOTREACHED(); 243 NOTREACHED();
226 } 244 }
245 return result;
227 } 246 }
228 247
229 /////////////////////////////////////////////////////////////////////////////// 248 ///////////////////////////////////////////////////////////////////////////////
230 // ShellIntegration::DefaultProtocolClientWorker 249 // ShellIntegration::DefaultProtocolClientWorker
231 // 250 //
232 251
233 ShellIntegration::DefaultProtocolClientWorker::DefaultProtocolClientWorker( 252 ShellIntegration::DefaultProtocolClientWorker::DefaultProtocolClientWorker(
234 DefaultWebClientObserver* observer, const std::string& protocol) 253 DefaultWebClientObserver* observer, const std::string& protocol)
235 : DefaultWebClientWorker(observer), 254 : DefaultWebClientWorker(observer),
236 protocol_(protocol) { 255 protocol_(protocol) {
237 } 256 }
238 257
239 /////////////////////////////////////////////////////////////////////////////// 258 ///////////////////////////////////////////////////////////////////////////////
240 // DefaultProtocolClientWorker, private: 259 // DefaultProtocolClientWorker, private:
241 260
242 ShellIntegration::DefaultWebClientState 261 ShellIntegration::DefaultWebClientState
243 ShellIntegration::DefaultProtocolClientWorker::CheckIsDefault() { 262 ShellIntegration::DefaultProtocolClientWorker::CheckIsDefault() {
244 return ShellIntegration::IsDefaultProtocolClient(protocol_); 263 return ShellIntegration::IsDefaultProtocolClient(protocol_);
245 } 264 }
246 265
247 void ShellIntegration::DefaultProtocolClientWorker::SetAsDefault( 266 ShellIntegration::SetDefaultWebClientResult
248 bool interactive_permitted) { 267 ShellIntegration::DefaultProtocolClientWorker::SetAsDefault(
249 ShellIntegration::SetAsDefaultProtocolClient(protocol_); 268 bool interactive_permitted) {
269 if (ShellIntegration::SetAsDefaultProtocolClient(protocol_))
270 return RESULT_SET_DEFAULT_OK;
271 return RESULT_SET_DEFAULT_FAILED_OR_CANCELLED;
gab 2012/06/16 19:32:51 I prefer the way you have it in the function above
motek. 2012/06/19 18:06:44 Done.
250 } 272 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698