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