OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/apps/ephemeral_app_launcher.h" | 5 #include "chrome/browser/apps/ephemeral_app_launcher.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/extensions/extension_install_checker.h" | 9 #include "chrome/browser/extensions/extension_install_checker.h" |
10 #include "chrome/browser/extensions/extension_install_prompt.h" | 10 #include "chrome/browser/extensions/extension_install_prompt.h" |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 if (!extensions::util::IsAppLaunchable(extension->id(), profile())) { | 217 if (!extensions::util::IsAppLaunchable(extension->id(), profile())) { |
218 *reason = webstore_install::REQUIREMENT_VIOLATIONS; | 218 *reason = webstore_install::REQUIREMENT_VIOLATIONS; |
219 *error = kRequirementsError; | 219 *error = kRequirementsError; |
220 return false; | 220 return false; |
221 } | 221 } |
222 | 222 |
223 return true; | 223 return true; |
224 } | 224 } |
225 | 225 |
226 void EphemeralAppLauncher::EnableInstalledApp(const Extension* extension) { | 226 void EphemeralAppLauncher::EnableInstalledApp(const Extension* extension) { |
| 227 // Keep this object alive until the enable flow is complete. Either |
| 228 // ExtensionEnableFlowFinished() or ExtensionEnableFlowAborted() will be |
| 229 // called. |
| 230 AddRef(); |
| 231 |
227 extension_enable_flow_.reset( | 232 extension_enable_flow_.reset( |
228 new ExtensionEnableFlow(profile(), extension->id(), this)); | 233 new ExtensionEnableFlow(profile(), extension->id(), this)); |
229 if (web_contents()) | 234 if (web_contents()) |
230 extension_enable_flow_->StartForWebContents(web_contents()); | 235 extension_enable_flow_->StartForWebContents(web_contents()); |
231 else | 236 else |
232 extension_enable_flow_->StartForNativeWindow(parent_window_); | 237 extension_enable_flow_->StartForNativeWindow(parent_window_); |
233 | |
234 // Keep this object alive until the enable flow is complete. Either | |
235 // ExtensionEnableFlowFinished() or ExtensionEnableFlowAborted() will be | |
236 // called. | |
237 AddRef(); | |
238 } | 238 } |
239 | 239 |
240 void EphemeralAppLauncher::MaybeLaunchApp() { | 240 void EphemeralAppLauncher::MaybeLaunchApp() { |
241 webstore_install::Result result = webstore_install::UNKNOWN_ERROR; | 241 webstore_install::Result result = webstore_install::UNKNOWN_ERROR; |
242 std::string error; | 242 std::string error; |
243 | 243 |
244 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); | 244 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); |
245 const Extension* extension = | 245 const Extension* extension = |
246 registry->GetExtensionById(id(), ExtensionRegistry::EVERYTHING); | 246 registry->GetExtensionById(id(), ExtensionRegistry::EVERYTHING); |
247 if (extension) { | 247 if (extension) { |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 | 439 |
440 void EphemeralAppLauncher::ExtensionEnableFlowFinished() { | 440 void EphemeralAppLauncher::ExtensionEnableFlowFinished() { |
441 MaybeLaunchApp(); | 441 MaybeLaunchApp(); |
442 Release(); // Matches the AddRef in EnableInstalledApp(). | 442 Release(); // Matches the AddRef in EnableInstalledApp(). |
443 } | 443 } |
444 | 444 |
445 void EphemeralAppLauncher::ExtensionEnableFlowAborted(bool user_initiated) { | 445 void EphemeralAppLauncher::ExtensionEnableFlowAborted(bool user_initiated) { |
446 InvokeCallback(webstore_install::USER_CANCELLED, kUserCancelledError); | 446 InvokeCallback(webstore_install::USER_CANCELLED, kUserCancelledError); |
447 Release(); // Matches the AddRef in EnableInstalledApp(). | 447 Release(); // Matches the AddRef in EnableInstalledApp(). |
448 } | 448 } |
OLD | NEW |