Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: chrome/browser/extensions/api/webstore_private/webstore_private_api.cc

Issue 1534123002: [Extensions] Migrate ExtensionInstallPrompt::Delegate to be a callback (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/api/webstore_private/webstore_private_api.h" 5 #include "chrome/browser/extensions/api/webstore_private/webstore_private_api.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 if (!web_contents) { 284 if (!web_contents) {
285 // The browser window has gone away. 285 // The browser window has gone away.
286 Respond(BuildResponse(api::webstore_private::RESULT_USER_CANCELLED, 286 Respond(BuildResponse(api::webstore_private::RESULT_USER_CANCELLED,
287 kUserCancelledError)); 287 kUserCancelledError));
288 // Matches the AddRef in Run(). 288 // Matches the AddRef in Run().
289 Release(); 289 Release();
290 return; 290 return;
291 } 291 }
292 install_prompt_.reset(new ExtensionInstallPrompt(web_contents)); 292 install_prompt_.reset(new ExtensionInstallPrompt(web_contents));
293 install_prompt_->ShowDialog( 293 install_prompt_->ShowDialog(
294 this, dummy_extension_.get(), &icon_, 294 base::Bind(&WebstorePrivateBeginInstallWithManifest3Function::
295 OnInstallPromptDone,
296 this),
297 dummy_extension_.get(), &icon_,
295 ExtensionInstallPrompt::GetDefaultShowDialogCallback()); 298 ExtensionInstallPrompt::GetDefaultShowDialogCallback());
296 // Control flow finishes up in InstallUIProceed or InstallUIAbort. 299 // Control flow finishes up in OnInstallPromptDone.
297 } 300 }
298 301
299 void WebstorePrivateBeginInstallWithManifest3Function::OnWebstoreParseFailure( 302 void WebstorePrivateBeginInstallWithManifest3Function::OnWebstoreParseFailure(
300 const std::string& id, 303 const std::string& id,
301 WebstoreInstallHelper::Delegate::InstallHelperResultCode result, 304 WebstoreInstallHelper::Delegate::InstallHelperResultCode result,
302 const std::string& error_message) { 305 const std::string& error_message) {
303 CHECK_EQ(details().id, id); 306 CHECK_EQ(details().id, id);
304 307
305 Respond(BuildResponse(WebstoreInstallHelperResultToApiResult(result), 308 Respond(BuildResponse(WebstoreInstallHelperResultToApiResult(result),
306 error_message)); 309 error_message));
307 310
308 // Matches the AddRef in Run(). 311 // Matches the AddRef in Run().
309 Release(); 312 Release();
310 } 313 }
311 314
312 void WebstorePrivateBeginInstallWithManifest3Function::InstallUIProceed() { 315 void WebstorePrivateBeginInstallWithManifest3Function::OnInstallPromptDone(
316 ExtensionInstallPrompt::Result result) {
317 if (result == ExtensionInstallPrompt::Result::ACCEPTED) {
318 HandleInstallProceed();
319 } else {
320 HandleInstallAbort(result == ExtensionInstallPrompt::Result::USER_CANCELED);
321 }
322
323 // Matches the AddRef in Run().
324 Release();
325 }
326
327 void WebstorePrivateBeginInstallWithManifest3Function::HandleInstallProceed() {
313 // This gets cleared in CrxInstaller::ConfirmInstall(). TODO(asargent) - in 328 // This gets cleared in CrxInstaller::ConfirmInstall(). TODO(asargent) - in
314 // the future we may also want to add time-based expiration, where a whitelist 329 // the future we may also want to add time-based expiration, where a whitelist
315 // entry is only valid for some number of minutes. 330 // entry is only valid for some number of minutes.
316 scoped_ptr<WebstoreInstaller::Approval> approval( 331 scoped_ptr<WebstoreInstaller::Approval> approval(
317 WebstoreInstaller::Approval::CreateWithNoInstallPrompt( 332 WebstoreInstaller::Approval::CreateWithNoInstallPrompt(
318 chrome_details_.GetProfile(), details().id, 333 chrome_details_.GetProfile(), details().id,
319 std::move(parsed_manifest_), false)); 334 std::move(parsed_manifest_), false));
320 approval->use_app_installed_bubble = details().app_install_bubble; 335 approval->use_app_installed_bubble = details().app_install_bubble;
321 approval->enable_launcher = details().enable_launcher; 336 approval->enable_launcher = details().enable_launcher;
322 // If we are enabling the launcher, we should not show the app list in order 337 // If we are enabling the launcher, we should not show the app list in order
323 // to train the user to open it themselves at least once. 338 // to train the user to open it themselves at least once.
324 approval->skip_post_install_ui = details().enable_launcher; 339 approval->skip_post_install_ui = details().enable_launcher;
325 approval->dummy_extension = dummy_extension_.get(); 340 approval->dummy_extension = dummy_extension_.get();
326 approval->installing_icon = gfx::ImageSkia::CreateFrom1xBitmap(icon_); 341 approval->installing_icon = gfx::ImageSkia::CreateFrom1xBitmap(icon_);
327 if (details().authuser) 342 if (details().authuser)
328 approval->authuser = *details().authuser; 343 approval->authuser = *details().authuser;
329 g_pending_approvals.Get().PushApproval(std::move(approval)); 344 g_pending_approvals.Get().PushApproval(std::move(approval));
330 345
331 DCHECK(scoped_active_install_.get()); 346 DCHECK(scoped_active_install_.get());
332 scoped_active_install_->CancelDeregister(); 347 scoped_active_install_->CancelDeregister();
333 348
334 // The Permissions_Install histogram is recorded from the ExtensionService 349 // The Permissions_Install histogram is recorded from the ExtensionService
335 // for all extension installs, so we only need to record the web store 350 // for all extension installs, so we only need to record the web store
336 // specific histogram here. 351 // specific histogram here.
337 ExtensionService::RecordPermissionMessagesHistogram( 352 ExtensionService::RecordPermissionMessagesHistogram(
338 dummy_extension_.get(), "WebStoreInstall"); 353 dummy_extension_.get(), "WebStoreInstall");
339 354
340 Respond(BuildResponse(api::webstore_private::RESULT_SUCCESS, std::string())); 355 Respond(BuildResponse(api::webstore_private::RESULT_SUCCESS, std::string()));
341
342 // Matches the AddRef in Run().
343 Release();
344 } 356 }
345 357
346 void WebstorePrivateBeginInstallWithManifest3Function::InstallUIAbort( 358 void WebstorePrivateBeginInstallWithManifest3Function::HandleInstallAbort(
347 bool user_initiated) { 359 bool user_initiated) {
348 // The web store install histograms are a subset of the install histograms. 360 // The web store install histograms are a subset of the install histograms.
349 // We need to record both histograms here since CrxInstaller::InstallUIAbort 361 // We need to record both histograms here since CrxInstaller::InstallUIAbort
350 // is never called for web store install cancellations. 362 // is never called for web store install cancellations.
351 std::string histogram_name = user_initiated ? "WebStoreInstallCancel" 363 std::string histogram_name = user_initiated ? "WebStoreInstallCancel"
352 : "WebStoreInstallAbort"; 364 : "WebStoreInstallAbort";
353 ExtensionService::RecordPermissionMessagesHistogram(dummy_extension_.get(), 365 ExtensionService::RecordPermissionMessagesHistogram(dummy_extension_.get(),
354 histogram_name.c_str()); 366 histogram_name.c_str());
355 367
356 histogram_name = user_initiated ? "InstallCancel" : "InstallAbort"; 368 histogram_name = user_initiated ? "InstallCancel" : "InstallAbort";
357 ExtensionService::RecordPermissionMessagesHistogram(dummy_extension_.get(), 369 ExtensionService::RecordPermissionMessagesHistogram(dummy_extension_.get(),
358 histogram_name.c_str()); 370 histogram_name.c_str());
359 371
360 Respond(BuildResponse(api::webstore_private::RESULT_USER_CANCELLED, 372 Respond(BuildResponse(api::webstore_private::RESULT_USER_CANCELLED,
361 kUserCancelledError)); 373 kUserCancelledError));
362
363 // Matches the AddRef in Run().
364 Release();
365 } 374 }
366 375
367 ExtensionFunction::ResponseValue 376 ExtensionFunction::ResponseValue
368 WebstorePrivateBeginInstallWithManifest3Function::BuildResponse( 377 WebstorePrivateBeginInstallWithManifest3Function::BuildResponse(
369 api::webstore_private::Result result, const std::string& error) { 378 api::webstore_private::Result result, const std::string& error) {
370 if (result != api::webstore_private::RESULT_SUCCESS) 379 if (result != api::webstore_private::RESULT_SUCCESS)
371 return ErrorWithArguments(CreateResults(result), error); 380 return ErrorWithArguments(CreateResults(result), error);
372 381
373 // The web store expects an empty string on success, so don't use 382 // The web store expects an empty string on success, so don't use
374 // RESULT_SUCCESS here. 383 // RESULT_SUCCESS here.
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 WebstorePrivateGetEphemeralAppsEnabledFunction:: 708 WebstorePrivateGetEphemeralAppsEnabledFunction::
700 ~WebstorePrivateGetEphemeralAppsEnabledFunction() {} 709 ~WebstorePrivateGetEphemeralAppsEnabledFunction() {}
701 710
702 ExtensionFunction::ResponseAction 711 ExtensionFunction::ResponseAction
703 WebstorePrivateGetEphemeralAppsEnabledFunction::Run() { 712 WebstorePrivateGetEphemeralAppsEnabledFunction::Run() {
704 return RespondNow(ArgumentList(GetEphemeralAppsEnabled::Results::Create( 713 return RespondNow(ArgumentList(GetEphemeralAppsEnabled::Results::Create(
705 false))); 714 false)));
706 } 715 }
707 716
708 } // namespace extensions 717 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/webstore_private/webstore_private_api.h ('k') | chrome/browser/extensions/bundle_installer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698