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