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