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 "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/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 | 150 |
151 #if !defined(OS_WIN) | 151 #if !defined(OS_WIN) |
152 base::string16 ShellIntegration::GetAppShortcutsSubdirName() { | 152 base::string16 ShellIntegration::GetAppShortcutsSubdirName() { |
153 if (chrome::GetChannel() == version_info::Channel::CANARY) | 153 if (chrome::GetChannel() == version_info::Channel::CANARY) |
154 return l10n_util::GetStringUTF16(IDS_APP_SHORTCUTS_SUBDIR_NAME_CANARY); | 154 return l10n_util::GetStringUTF16(IDS_APP_SHORTCUTS_SUBDIR_NAME_CANARY); |
155 return l10n_util::GetStringUTF16(IDS_APP_SHORTCUTS_SUBDIR_NAME); | 155 return l10n_util::GetStringUTF16(IDS_APP_SHORTCUTS_SUBDIR_NAME); |
156 } | 156 } |
157 #endif // !defined(OS_WIN) | 157 #endif // !defined(OS_WIN) |
158 | 158 |
159 /////////////////////////////////////////////////////////////////////////////// | 159 /////////////////////////////////////////////////////////////////////////////// |
160 // ShellIntegration::DefaultWebClientObserver | |
161 // | |
162 | |
163 bool ShellIntegration::DefaultWebClientObserver::IsOwnedByWorker() { | |
164 return false; | |
165 } | |
166 | |
167 bool ShellIntegration::DefaultWebClientObserver:: | |
168 IsInteractiveSetDefaultPermitted() { | |
169 return false; | |
170 } | |
171 | |
172 /////////////////////////////////////////////////////////////////////////////// | |
173 // ShellIntegration::DefaultWebClientWorker | 160 // ShellIntegration::DefaultWebClientWorker |
174 // | 161 // |
175 | 162 |
176 ShellIntegration::DefaultWebClientWorker::DefaultWebClientWorker( | 163 ShellIntegration::DefaultWebClientWorker::DefaultWebClientWorker( |
177 DefaultWebClientObserver* observer) | 164 DefaultWebClientObserver* observer, |
178 : observer_(observer) {} | 165 bool delete_observer) |
166 : observer_(observer), | |
167 delete_observer_(delete_observer), | |
168 interactive_permitted_(true) {} | |
grt (UTC plus 2)
2016/02/03 15:39:56
nit: remove this from the initializer list since i
Patrick Monette
2016/02/03 23:01:38
Done.
| |
179 | 169 |
180 void ShellIntegration::DefaultWebClientWorker::StartCheckIsDefault() { | 170 void ShellIntegration::DefaultWebClientWorker::StartCheckIsDefault() { |
181 if (observer_) | 171 if (observer_) |
182 observer_->SetDefaultWebClientUIState(STATE_PROCESSING); | 172 observer_->SetDefaultWebClientUIState(STATE_PROCESSING); |
183 | 173 |
184 BrowserThread::PostTask( | 174 BrowserThread::PostTask( |
185 BrowserThread::FILE, FROM_HERE, | 175 BrowserThread::FILE, FROM_HERE, |
186 base::Bind(&DefaultWebClientWorker::CheckIsDefault, this)); | 176 base::Bind(&DefaultWebClientWorker::CheckIsDefault, this)); |
187 } | 177 } |
188 | 178 |
189 void ShellIntegration::DefaultWebClientWorker::StartSetAsDefault() { | 179 void ShellIntegration::DefaultWebClientWorker::StartSetAsDefault() { |
190 // Cancel the already running process if another start is requested. | 180 // Cancel the already running process if another start is requested. |
191 if (set_as_default_in_progress_) { | 181 if (set_as_default_in_progress_) { |
192 if (set_as_default_initialized_) { | 182 if (set_as_default_initialized_) { |
193 FinalizeSetAsDefault(); | 183 FinalizeSetAsDefault(); |
194 set_as_default_initialized_ = false; | 184 set_as_default_initialized_ = false; |
195 } | 185 } |
196 | 186 |
197 ReportAttemptResult(AttemptResult::RETRY); | 187 ReportAttemptResult(AttemptResult::RETRY); |
198 } | 188 } |
199 | 189 |
200 set_as_default_in_progress_ = true; | 190 set_as_default_in_progress_ = true; |
201 bool interactive_permitted = true; | 191 if (observer_) |
202 if (observer_) { | |
203 observer_->SetDefaultWebClientUIState(STATE_PROCESSING); | 192 observer_->SetDefaultWebClientUIState(STATE_PROCESSING); |
204 interactive_permitted = observer_->IsInteractiveSetDefaultPermitted(); | |
205 } | |
206 | 193 |
207 set_as_default_initialized_ = InitializeSetAsDefault(); | 194 set_as_default_initialized_ = InitializeSetAsDefault(); |
208 | 195 |
209 // Remember the start time. | 196 // Remember the start time. |
210 start_time_ = base::TimeTicks::Now(); | 197 start_time_ = base::TimeTicks::Now(); |
211 | 198 |
212 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 199 BrowserThread::PostTask( |
213 base::Bind(&DefaultWebClientWorker::SetAsDefault, | 200 BrowserThread::FILE, FROM_HERE, |
214 this, interactive_permitted)); | 201 base::Bind(&DefaultWebClientWorker::SetAsDefault, this)); |
215 } | 202 } |
216 | 203 |
217 void ShellIntegration::DefaultWebClientWorker::ObserverDestroyed() { | 204 void ShellIntegration::DefaultWebClientWorker::ObserverDestroyed() { |
218 // Our associated view has gone away, so we shouldn't call back to it if | 205 // Our associated view has gone away, so we shouldn't call back to it if |
219 // our worker thread returns after the view is dead. | 206 // our worker thread returns after the view is dead. |
220 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 207 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
221 observer_ = nullptr; | 208 observer_ = nullptr; |
222 | 209 |
223 if (set_as_default_initialized_) { | 210 if (set_as_default_initialized_) { |
224 FinalizeSetAsDefault(); | 211 FinalizeSetAsDefault(); |
(...skipping 17 matching lines...) Expand all Loading... | |
242 if (check_default_should_report_success_) { | 229 if (check_default_should_report_success_) { |
243 check_default_should_report_success_ = false; | 230 check_default_should_report_success_ = false; |
244 | 231 |
245 ReportAttemptResult(state == DefaultWebClientState::IS_DEFAULT | 232 ReportAttemptResult(state == DefaultWebClientState::IS_DEFAULT |
246 ? AttemptResult::SUCCESS | 233 ? AttemptResult::SUCCESS |
247 : AttemptResult::NO_ERRORS_NOT_DEFAULT); | 234 : AttemptResult::NO_ERRORS_NOT_DEFAULT); |
248 } | 235 } |
249 | 236 |
250 // The worker has finished everything it needs to do, so free the observer | 237 // The worker has finished everything it needs to do, so free the observer |
251 // if we own it. | 238 // if we own it. |
252 if (observer_ && observer_->IsOwnedByWorker()) { | 239 if (observer_ && delete_observer_) { |
253 delete observer_; | 240 delete observer_; |
254 observer_ = nullptr; | 241 observer_ = nullptr; |
255 } | 242 } |
256 } | 243 } |
257 | 244 |
258 void ShellIntegration::DefaultWebClientWorker::OnSetAsDefaultAttemptComplete( | 245 void ShellIntegration::DefaultWebClientWorker::OnSetAsDefaultAttemptComplete( |
259 AttemptResult result) { | 246 AttemptResult result) { |
260 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 247 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
261 // Hold on to a reference because if this was called via the default browser | 248 // Hold on to a reference because if this was called via the default browser |
262 // callback in StartupBrowserCreator, clearing the callback in | 249 // callback in StartupBrowserCreator, clearing the callback in |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
372 } | 359 } |
373 NOTREACHED(); | 360 NOTREACHED(); |
374 return ""; | 361 return ""; |
375 } | 362 } |
376 | 363 |
377 /////////////////////////////////////////////////////////////////////////////// | 364 /////////////////////////////////////////////////////////////////////////////// |
378 // ShellIntegration::DefaultBrowserWorker | 365 // ShellIntegration::DefaultBrowserWorker |
379 // | 366 // |
380 | 367 |
381 ShellIntegration::DefaultBrowserWorker::DefaultBrowserWorker( | 368 ShellIntegration::DefaultBrowserWorker::DefaultBrowserWorker( |
382 DefaultWebClientObserver* observer) | 369 DefaultWebClientObserver* observer, |
383 : DefaultWebClientWorker(observer) { | 370 bool delete_observer) |
384 } | 371 : DefaultWebClientWorker(observer, delete_observer) {} |
385 | 372 |
386 ShellIntegration::DefaultBrowserWorker::~DefaultBrowserWorker() {} | 373 ShellIntegration::DefaultBrowserWorker::~DefaultBrowserWorker() {} |
387 | 374 |
388 /////////////////////////////////////////////////////////////////////////////// | 375 /////////////////////////////////////////////////////////////////////////////// |
389 // DefaultBrowserWorker, private: | 376 // DefaultBrowserWorker, private: |
390 | 377 |
391 void ShellIntegration::DefaultBrowserWorker::CheckIsDefault() { | 378 void ShellIntegration::DefaultBrowserWorker::CheckIsDefault() { |
392 DefaultWebClientState state = GetDefaultBrowser(); | 379 DefaultWebClientState state = GetDefaultBrowser(); |
393 BrowserThread::PostTask( | 380 BrowserThread::PostTask( |
394 BrowserThread::UI, FROM_HERE, | 381 BrowserThread::UI, FROM_HERE, |
395 base::Bind(&DefaultBrowserWorker::OnCheckIsDefaultComplete, this, state)); | 382 base::Bind(&DefaultBrowserWorker::OnCheckIsDefaultComplete, this, state)); |
396 } | 383 } |
397 | 384 |
398 void ShellIntegration::DefaultBrowserWorker::SetAsDefault( | 385 void ShellIntegration::DefaultBrowserWorker::SetAsDefault() { |
399 bool interactive_permitted) { | |
400 AttemptResult result = AttemptResult::FAILURE; | 386 AttemptResult result = AttemptResult::FAILURE; |
401 switch (CanSetAsDefaultBrowser()) { | 387 switch (CanSetAsDefaultBrowser()) { |
402 case SET_DEFAULT_NOT_ALLOWED: | 388 case SET_DEFAULT_NOT_ALLOWED: |
403 NOTREACHED(); | 389 NOTREACHED(); |
404 break; | 390 break; |
405 case SET_DEFAULT_UNATTENDED: | 391 case SET_DEFAULT_UNATTENDED: |
406 if (SetAsDefaultBrowser()) | 392 if (SetAsDefaultBrowser()) |
407 result = AttemptResult::SUCCESS; | 393 result = AttemptResult::SUCCESS; |
408 break; | 394 break; |
409 case SET_DEFAULT_INTERACTIVE: | 395 case SET_DEFAULT_INTERACTIVE: |
410 if (interactive_permitted && SetAsDefaultBrowserInteractive()) | 396 if (interactive_permitted_ && SetAsDefaultBrowserInteractive()) |
411 result = AttemptResult::SUCCESS; | 397 result = AttemptResult::SUCCESS; |
412 break; | 398 break; |
413 case SET_DEFAULT_ASYNCHRONOUS: | 399 case SET_DEFAULT_ASYNCHRONOUS: |
414 #if defined(OS_WIN) | 400 #if defined(OS_WIN) |
415 if (!interactive_permitted) | 401 if (!interactive_permitted_) |
416 break; | 402 break; |
417 if (GetDefaultBrowser() == IS_DEFAULT) { | 403 if (GetDefaultBrowser() == IS_DEFAULT) { |
418 // Don't start the asynchronous operation since it could result in | 404 // Don't start the asynchronous operation since it could result in |
419 // losing the default browser status. | 405 // losing the default browser status. |
420 result = AttemptResult::ALREADY_DEFAULT; | 406 result = AttemptResult::ALREADY_DEFAULT; |
421 break; | 407 break; |
422 } | 408 } |
423 // This function will cause OnSetAsDefaultAttemptComplete() to be called | 409 // This function will cause OnSetAsDefaultAttemptComplete() to be called |
424 // asynchronously via a filter established in InitializeSetAsDefault(). | 410 // asynchronously via a filter established in InitializeSetAsDefault(). |
425 if (!SetAsDefaultBrowserAsynchronous()) { | 411 if (!SetAsDefaultBrowserAsynchronous()) { |
(...skipping 14 matching lines...) Expand all Loading... | |
440 | 426 |
441 const char* ShellIntegration::DefaultBrowserWorker::GetHistogramPrefix() { | 427 const char* ShellIntegration::DefaultBrowserWorker::GetHistogramPrefix() { |
442 return "DefaultBrowser"; | 428 return "DefaultBrowser"; |
443 } | 429 } |
444 | 430 |
445 /////////////////////////////////////////////////////////////////////////////// | 431 /////////////////////////////////////////////////////////////////////////////// |
446 // ShellIntegration::DefaultProtocolClientWorker | 432 // ShellIntegration::DefaultProtocolClientWorker |
447 // | 433 // |
448 | 434 |
449 ShellIntegration::DefaultProtocolClientWorker::DefaultProtocolClientWorker( | 435 ShellIntegration::DefaultProtocolClientWorker::DefaultProtocolClientWorker( |
450 DefaultWebClientObserver* observer, const std::string& protocol) | 436 DefaultWebClientObserver* observer, |
451 : DefaultWebClientWorker(observer), | 437 const std::string& protocol, |
452 protocol_(protocol) { | 438 bool delete_observer) |
453 } | 439 : DefaultWebClientWorker(observer, delete_observer), protocol_(protocol) {} |
454 | 440 |
455 /////////////////////////////////////////////////////////////////////////////// | 441 /////////////////////////////////////////////////////////////////////////////// |
456 // DefaultProtocolClientWorker, private: | 442 // DefaultProtocolClientWorker, private: |
457 | 443 |
458 ShellIntegration::DefaultProtocolClientWorker::~DefaultProtocolClientWorker() {} | 444 ShellIntegration::DefaultProtocolClientWorker::~DefaultProtocolClientWorker() {} |
459 | 445 |
460 void ShellIntegration::DefaultProtocolClientWorker::CheckIsDefault() { | 446 void ShellIntegration::DefaultProtocolClientWorker::CheckIsDefault() { |
461 DefaultWebClientState state = IsDefaultProtocolClient(protocol_); | 447 DefaultWebClientState state = IsDefaultProtocolClient(protocol_); |
462 BrowserThread::PostTask( | 448 BrowserThread::PostTask( |
463 BrowserThread::UI, FROM_HERE, | 449 BrowserThread::UI, FROM_HERE, |
464 base::Bind(&DefaultProtocolClientWorker::OnCheckIsDefaultComplete, this, | 450 base::Bind(&DefaultProtocolClientWorker::OnCheckIsDefaultComplete, this, |
465 state)); | 451 state)); |
466 } | 452 } |
467 | 453 |
468 void ShellIntegration::DefaultProtocolClientWorker::SetAsDefault( | 454 void ShellIntegration::DefaultProtocolClientWorker::SetAsDefault() { |
469 bool interactive_permitted) { | |
470 AttemptResult result = AttemptResult::FAILURE; | 455 AttemptResult result = AttemptResult::FAILURE; |
471 switch (CanSetAsDefaultProtocolClient()) { | 456 switch (CanSetAsDefaultProtocolClient()) { |
472 case SET_DEFAULT_NOT_ALLOWED: | 457 case SET_DEFAULT_NOT_ALLOWED: |
473 // Not allowed, do nothing. | 458 // Not allowed, do nothing. |
474 break; | 459 break; |
475 case SET_DEFAULT_UNATTENDED: | 460 case SET_DEFAULT_UNATTENDED: |
476 if (SetAsDefaultProtocolClient(protocol_)) | 461 if (SetAsDefaultProtocolClient(protocol_)) |
477 result = AttemptResult::SUCCESS; | 462 result = AttemptResult::SUCCESS; |
478 break; | 463 break; |
479 case SET_DEFAULT_INTERACTIVE: | 464 case SET_DEFAULT_INTERACTIVE: |
480 if (interactive_permitted && | 465 if (interactive_permitted_ && |
481 SetAsDefaultProtocolClientInteractive(protocol_)) { | 466 SetAsDefaultProtocolClientInteractive(protocol_)) { |
482 result = AttemptResult::SUCCESS; | 467 result = AttemptResult::SUCCESS; |
483 } | 468 } |
484 break; | 469 break; |
485 case SET_DEFAULT_ASYNCHRONOUS: | 470 case SET_DEFAULT_ASYNCHRONOUS: |
486 NOTREACHED(); | 471 NOTREACHED(); |
487 break; | 472 break; |
488 } | 473 } |
489 BrowserThread::PostTask( | 474 BrowserThread::PostTask( |
490 BrowserThread::UI, FROM_HERE, | 475 BrowserThread::UI, FROM_HERE, |
491 base::Bind(&DefaultProtocolClientWorker::OnSetAsDefaultAttemptComplete, | 476 base::Bind(&DefaultProtocolClientWorker::OnSetAsDefaultAttemptComplete, |
492 this, result)); | 477 this, result)); |
493 } | 478 } |
494 | 479 |
495 const char* | 480 const char* |
496 ShellIntegration::DefaultProtocolClientWorker::GetHistogramPrefix() { | 481 ShellIntegration::DefaultProtocolClientWorker::GetHistogramPrefix() { |
497 return "DefaultProtocolClient"; | 482 return "DefaultProtocolClient"; |
498 } | 483 } |
OLD | NEW |