| 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/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 if (observer_) { | 115 if (observer_) { |
| 116 observer_->SetDefaultWebClientUIState(STATE_PROCESSING); | 116 observer_->SetDefaultWebClientUIState(STATE_PROCESSING); |
| 117 BrowserThread::PostTask( | 117 BrowserThread::PostTask( |
| 118 BrowserThread::FILE, FROM_HERE, | 118 BrowserThread::FILE, FROM_HERE, |
| 119 base::Bind( | 119 base::Bind( |
| 120 &DefaultWebClientWorker::ExecuteCheckIsDefault, this)); | 120 &DefaultWebClientWorker::ExecuteCheckIsDefault, this)); |
| 121 } | 121 } |
| 122 } | 122 } |
| 123 | 123 |
| 124 void ShellIntegration::DefaultWebClientWorker::StartSetAsDefault() { | 124 void ShellIntegration::DefaultWebClientWorker::StartSetAsDefault() { |
| 125 bool interactive_permitted = false; |
| 125 if (observer_) { | 126 if (observer_) { |
| 126 observer_->SetDefaultWebClientUIState(STATE_PROCESSING); | 127 observer_->SetDefaultWebClientUIState(STATE_PROCESSING); |
| 128 interactive_permitted = observer_->IsInteractiveSetDefaultPermitted(); |
| 127 } | 129 } |
| 128 BrowserThread::PostTask( | 130 BrowserThread::PostTask( |
| 129 BrowserThread::FILE, FROM_HERE, | 131 BrowserThread::FILE, FROM_HERE, |
| 130 base::Bind( | 132 base::Bind(&DefaultWebClientWorker::ExecuteSetAsDefault, this, |
| 131 &DefaultWebClientWorker::ExecuteSetAsDefault, this)); | 133 interactive_permitted)); |
| 132 } | 134 } |
| 133 | 135 |
| 134 void ShellIntegration::DefaultWebClientWorker::ObserverDestroyed() { | 136 void ShellIntegration::DefaultWebClientWorker::ObserverDestroyed() { |
| 135 // Our associated view has gone away, so we shouldn't call back to it if | 137 // Our associated view has gone away, so we shouldn't call back to it if |
| 136 // our worker thread returns after the view is dead. | 138 // our worker thread returns after the view is dead. |
| 137 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 139 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 138 observer_ = NULL; | 140 observer_ = NULL; |
| 139 } | 141 } |
| 140 | 142 |
| 141 /////////////////////////////////////////////////////////////////////////////// | 143 /////////////////////////////////////////////////////////////////////////////// |
| (...skipping 13 matching lines...) Expand all Loading... |
| 155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 156 UpdateUI(state); | 158 UpdateUI(state); |
| 157 // The worker has finished everything it needs to do, so free the observer | 159 // The worker has finished everything it needs to do, so free the observer |
| 158 // if we own it. | 160 // if we own it. |
| 159 if (observer_ && observer_->IsOwnedByWorker()) { | 161 if (observer_ && observer_->IsOwnedByWorker()) { |
| 160 delete observer_; | 162 delete observer_; |
| 161 observer_ = NULL; | 163 observer_ = NULL; |
| 162 } | 164 } |
| 163 } | 165 } |
| 164 | 166 |
| 165 void ShellIntegration::DefaultWebClientWorker::ExecuteSetAsDefault() { | 167 void ShellIntegration::DefaultWebClientWorker::ExecuteSetAsDefault( |
| 168 bool interactive_permitted) { |
| 166 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 169 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 167 SetAsDefault(observer_ && observer_->IsInteractiveSetDefaultPermitted()); | 170 |
| 171 bool result = SetAsDefault(interactive_permitted); |
| 168 BrowserThread::PostTask( | 172 BrowserThread::PostTask( |
| 169 BrowserThread::UI, FROM_HERE, | 173 BrowserThread::UI, FROM_HERE, |
| 170 base::Bind( | 174 base::Bind(&DefaultWebClientWorker::CompleteSetAsDefault, this, result)); |
| 171 &DefaultWebClientWorker::CompleteSetAsDefault, this)); | |
| 172 } | 175 } |
| 173 | 176 |
| 174 void ShellIntegration::DefaultWebClientWorker::CompleteSetAsDefault() { | 177 void ShellIntegration::DefaultWebClientWorker::CompleteSetAsDefault( |
| 178 bool succeeded) { |
| 175 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 179 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 180 // First tell the observer what the SetAsDefault call has returned. |
| 181 if (observer_) |
| 182 observer_->OnSetAsDefaultConcluded(succeeded); |
| 176 // Set as default completed, check again to make sure it stuck... | 183 // Set as default completed, check again to make sure it stuck... |
| 177 StartCheckIsDefault(); | 184 StartCheckIsDefault(); |
| 178 } | 185 } |
| 179 | 186 |
| 180 void ShellIntegration::DefaultWebClientWorker::UpdateUI( | 187 void ShellIntegration::DefaultWebClientWorker::UpdateUI( |
| 181 DefaultWebClientState state) { | 188 DefaultWebClientState state) { |
| 182 if (observer_) { | 189 if (observer_) { |
| 183 switch (state) { | 190 switch (state) { |
| 184 case NOT_DEFAULT_WEB_CLIENT: | 191 case NOT_DEFAULT_WEB_CLIENT: |
| 185 observer_->SetDefaultWebClientUIState(STATE_NOT_DEFAULT); | 192 observer_->SetDefaultWebClientUIState(STATE_NOT_DEFAULT); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 206 } | 213 } |
| 207 | 214 |
| 208 /////////////////////////////////////////////////////////////////////////////// | 215 /////////////////////////////////////////////////////////////////////////////// |
| 209 // DefaultBrowserWorker, private: | 216 // DefaultBrowserWorker, private: |
| 210 | 217 |
| 211 ShellIntegration::DefaultWebClientState | 218 ShellIntegration::DefaultWebClientState |
| 212 ShellIntegration::DefaultBrowserWorker::CheckIsDefault() { | 219 ShellIntegration::DefaultBrowserWorker::CheckIsDefault() { |
| 213 return ShellIntegration::IsDefaultBrowser(); | 220 return ShellIntegration::IsDefaultBrowser(); |
| 214 } | 221 } |
| 215 | 222 |
| 216 void ShellIntegration::DefaultBrowserWorker::SetAsDefault( | 223 bool ShellIntegration::DefaultBrowserWorker::SetAsDefault( |
| 217 bool interactive_permitted) { | 224 bool interactive_permitted) { |
| 225 bool result = false; |
| 218 switch (ShellIntegration::CanSetAsDefaultBrowser()) { | 226 switch (ShellIntegration::CanSetAsDefaultBrowser()) { |
| 219 case ShellIntegration::SET_DEFAULT_UNATTENDED: | 227 case ShellIntegration::SET_DEFAULT_UNATTENDED: |
| 220 ShellIntegration::SetAsDefaultBrowser(); | 228 result = ShellIntegration::SetAsDefaultBrowser(); |
| 221 break; | 229 break; |
| 222 case ShellIntegration::SET_DEFAULT_INTERACTIVE: | 230 case ShellIntegration::SET_DEFAULT_INTERACTIVE: |
| 223 if (interactive_permitted) | 231 if (interactive_permitted) |
| 224 ShellIntegration::SetAsDefaultBrowserInteractive(); | 232 result = ShellIntegration::SetAsDefaultBrowserInteractive(); |
| 225 break; | 233 break; |
| 226 default: | 234 default: |
| 227 NOTREACHED(); | 235 NOTREACHED(); |
| 228 } | 236 } |
| 237 |
| 238 return result; |
| 229 } | 239 } |
| 230 | 240 |
| 231 /////////////////////////////////////////////////////////////////////////////// | 241 /////////////////////////////////////////////////////////////////////////////// |
| 232 // ShellIntegration::DefaultProtocolClientWorker | 242 // ShellIntegration::DefaultProtocolClientWorker |
| 233 // | 243 // |
| 234 | 244 |
| 235 ShellIntegration::DefaultProtocolClientWorker::DefaultProtocolClientWorker( | 245 ShellIntegration::DefaultProtocolClientWorker::DefaultProtocolClientWorker( |
| 236 DefaultWebClientObserver* observer, const std::string& protocol) | 246 DefaultWebClientObserver* observer, const std::string& protocol) |
| 237 : DefaultWebClientWorker(observer), | 247 : DefaultWebClientWorker(observer), |
| 238 protocol_(protocol) { | 248 protocol_(protocol) { |
| 239 } | 249 } |
| 240 | 250 |
| 241 /////////////////////////////////////////////////////////////////////////////// | 251 /////////////////////////////////////////////////////////////////////////////// |
| 242 // DefaultProtocolClientWorker, private: | 252 // DefaultProtocolClientWorker, private: |
| 243 | 253 |
| 244 ShellIntegration::DefaultWebClientState | 254 ShellIntegration::DefaultWebClientState |
| 245 ShellIntegration::DefaultProtocolClientWorker::CheckIsDefault() { | 255 ShellIntegration::DefaultProtocolClientWorker::CheckIsDefault() { |
| 246 return ShellIntegration::IsDefaultProtocolClient(protocol_); | 256 return ShellIntegration::IsDefaultProtocolClient(protocol_); |
| 247 } | 257 } |
| 248 | 258 |
| 249 void ShellIntegration::DefaultProtocolClientWorker::SetAsDefault( | 259 bool ShellIntegration::DefaultProtocolClientWorker::SetAsDefault( |
| 250 bool interactive_permitted) { | 260 bool interactive_permitted) { |
| 251 ShellIntegration::SetAsDefaultProtocolClient(protocol_); | 261 return ShellIntegration::SetAsDefaultProtocolClient(protocol_); |
| 252 } | 262 } |
| OLD | NEW |