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/extensions/webstore_standalone_installer.h" | 5 #include "chrome/browser/extensions/webstore_standalone_installer.h" |
| 6 | 6 |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "chrome/browser/extensions/crx_installer.h" | 8 #include "chrome/browser/extensions/crx_installer.h" |
| 9 #include "chrome/browser/extensions/extension_install_prompt.h" | 9 #include "chrome/browser/extensions/extension_install_prompt.h" |
| 10 #include "chrome/browser/extensions/extension_install_ui.h" | 10 #include "chrome/browser/extensions/extension_install_ui.h" |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 DCHECK(!error.empty()); | 205 DCHECK(!error.empty()); |
| 206 CompleteInstall(error); | 206 CompleteInstall(error); |
| 207 return; | 207 return; |
| 208 } | 208 } |
| 209 | 209 |
| 210 install_prompt_ = CreateInstallPrompt(); | 210 install_prompt_ = CreateInstallPrompt(); |
| 211 if (install_prompt_) { | 211 if (install_prompt_) { |
| 212 ShowInstallUI(); | 212 ShowInstallUI(); |
| 213 // Control flow finishes up in InstallUIProceed or InstallUIAbort. | 213 // Control flow finishes up in InstallUIProceed or InstallUIAbort. |
| 214 } else { | 214 } else { |
| 215 // Balanced in InstallUIAbort or indirectly in InstallUIProceed via | |
| 216 // OnExtensionInstallSuccess or OnExtensionInstallFailure. | |
| 217 AddRef(); | |
| 218 InstallUIProceed(); | 215 InstallUIProceed(); |
| 219 } | 216 } |
| 220 } | 217 } |
| 221 | 218 |
| 222 void WebstoreStandaloneInstaller::OnWebstoreParseFailure( | 219 void WebstoreStandaloneInstaller::OnWebstoreParseFailure( |
| 223 const std::string& id, | 220 const std::string& id, |
| 224 InstallHelperResultCode result_code, | 221 InstallHelperResultCode result_code, |
| 225 const std::string& error_message) { | 222 const std::string& error_message) { |
| 226 CompleteInstall(error_message); | 223 CompleteInstall(error_message); |
| 227 } | 224 } |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 255 // enable it. | 252 // enable it. |
| 256 extension_service->EnableExtension(id_); | 253 extension_service->EnableExtension(id_); |
| 257 } // else extension is installed and enabled; no work to be done. | 254 } // else extension is installed and enabled; no work to be done. |
| 258 | 255 |
| 259 CompleteInstall(install_result); | 256 CompleteInstall(install_result); |
| 260 return; | 257 return; |
| 261 } | 258 } |
| 262 | 259 |
| 263 scoped_refptr<WebstoreInstaller> installer = new WebstoreInstaller( | 260 scoped_refptr<WebstoreInstaller> installer = new WebstoreInstaller( |
| 264 profile_, | 261 profile_, |
| 265 this, | 262 this, |
|
asargent_no_longer_on_chrome
2014/05/30 05:03:03
Inside OnWebstoreParseSuccess, we can end up calli
tmdiep
2014/05/30 05:34:32
WebstoreStandaloneInstaller::BeginInstall() starts
tmdiep
2014/05/30 06:25:26
I added this dcheck before creation of the install
| |
| 266 GetWebContents(), | 263 GetWebContents(), |
| 267 id_, | 264 id_, |
| 268 approval.Pass(), | 265 approval.Pass(), |
| 269 install_source_); | 266 install_source_); |
| 270 installer->Start(); | 267 installer->Start(); |
| 271 } | 268 } |
| 272 | 269 |
| 273 void WebstoreStandaloneInstaller::InstallUIAbort(bool user_initiated) { | 270 void WebstoreStandaloneInstaller::InstallUIAbort(bool user_initiated) { |
| 274 CompleteInstall(kUserCancelledError); | 271 CompleteInstall(kUserCancelledError); |
| 275 Release(); // Balanced in ShowInstallUI. | |
| 276 } | 272 } |
| 277 | 273 |
| 278 void WebstoreStandaloneInstaller::OnExtensionInstallSuccess( | 274 void WebstoreStandaloneInstaller::OnExtensionInstallSuccess( |
| 279 const std::string& id) { | 275 const std::string& id) { |
| 280 CHECK_EQ(id_, id); | 276 CHECK_EQ(id_, id); |
| 281 CompleteInstall(std::string()); | 277 CompleteInstall(std::string()); |
| 282 Release(); // Balanced in ShowInstallUI. | |
| 283 } | 278 } |
| 284 | 279 |
| 285 void WebstoreStandaloneInstaller::OnExtensionInstallFailure( | 280 void WebstoreStandaloneInstaller::OnExtensionInstallFailure( |
| 286 const std::string& id, | 281 const std::string& id, |
| 287 const std::string& error, | 282 const std::string& error, |
| 288 WebstoreInstaller::FailureReason cancelled) { | 283 WebstoreInstaller::FailureReason cancelled) { |
| 289 CHECK_EQ(id_, id); | 284 CHECK_EQ(id_, id); |
| 290 CompleteInstall(error); | 285 CompleteInstall(error); |
| 291 Release(); // Balanced in ShowInstallUI. | |
| 292 } | 286 } |
| 293 | 287 |
| 294 void WebstoreStandaloneInstaller::AbortInstall() { | 288 void WebstoreStandaloneInstaller::AbortInstall() { |
| 295 callback_.Reset(); | 289 callback_.Reset(); |
| 290 | |
| 296 // Abort any in-progress fetches. | 291 // Abort any in-progress fetches. |
| 297 if (webstore_data_fetcher_) { | 292 if (webstore_data_fetcher_) |
| 298 webstore_data_fetcher_.reset(); | 293 webstore_data_fetcher_.reset(); |
| 299 Release(); // Matches the AddRef in BeginInstall. | 294 |
| 300 } | 295 Release(); // Matches the AddRef in BeginInstall. |
| 301 } | 296 } |
| 302 | 297 |
| 303 void WebstoreStandaloneInstaller::InvokeCallback(const std::string& error) { | 298 void WebstoreStandaloneInstaller::InvokeCallback(const std::string& error) { |
| 304 if (!callback_.is_null()) | 299 if (!callback_.is_null()) |
| 305 callback_.Run(error.empty(), error); | 300 callback_.Run(error.empty(), error); |
| 306 } | 301 } |
| 307 | 302 |
| 308 void WebstoreStandaloneInstaller::CompleteInstall(const std::string& error) { | 303 void WebstoreStandaloneInstaller::CompleteInstall(const std::string& error) { |
| 309 InvokeCallback(error); | 304 InvokeCallback(error); |
| 310 Release(); // Matches the AddRef in BeginInstall. | 305 Release(); // Matches the AddRef in BeginInstall. |
| 311 } | 306 } |
| 312 | 307 |
| 313 void | 308 void WebstoreStandaloneInstaller::ShowInstallUI() { |
| 314 WebstoreStandaloneInstaller::ShowInstallUI() { | |
| 315 std::string error; | 309 std::string error; |
| 316 localized_extension_for_display_ = | 310 localized_extension_for_display_ = |
| 317 ExtensionInstallPrompt::GetLocalizedExtensionForDisplay( | 311 ExtensionInstallPrompt::GetLocalizedExtensionForDisplay( |
| 318 manifest_.get(), | 312 manifest_.get(), |
| 319 Extension::REQUIRE_KEY | Extension::FROM_WEBSTORE, | 313 Extension::REQUIRE_KEY | Extension::FROM_WEBSTORE, |
| 320 id_, | 314 id_, |
| 321 localized_name_, | 315 localized_name_, |
| 322 localized_description_, | 316 localized_description_, |
| 323 &error); | 317 &error); |
| 324 if (!localized_extension_for_display_.get()) { | 318 if (!localized_extension_for_display_.get()) { |
| 325 CompleteInstall(kInvalidManifestError); | 319 CompleteInstall(kInvalidManifestError); |
| 326 return; | 320 return; |
| 327 } | 321 } |
| 328 | 322 |
| 329 // Keep this alive as long as the install prompt lives. | |
| 330 // Balanced in InstallUIAbort or indirectly in InstallUIProceed via | |
| 331 // OnExtensionInstallSuccess or OnExtensionInstallFailure. | |
| 332 AddRef(); | |
| 333 | |
| 334 install_ui_ = CreateInstallUI(); | 323 install_ui_ = CreateInstallUI(); |
| 335 install_ui_->ConfirmStandaloneInstall( | 324 install_ui_->ConfirmStandaloneInstall( |
| 336 this, localized_extension_for_display_.get(), &icon_, *install_prompt_); | 325 this, localized_extension_for_display_.get(), &icon_, *install_prompt_); |
| 337 } | 326 } |
| 338 | 327 |
| 339 } // namespace extensions | 328 } // namespace extensions |
| OLD | NEW |