Index: chrome/browser/chromeos/extensions/file_manager/private_api_misc.cc |
diff --git a/chrome/browser/chromeos/extensions/file_manager/private_api_misc.cc b/chrome/browser/chromeos/extensions/file_manager/private_api_misc.cc |
index 115b18cd4cf85a81f80927ccf4c8fe227565d18e..75ae01aeef435909f89a4484befd23c967eefe0c 100644 |
--- a/chrome/browser/chromeos/extensions/file_manager/private_api_misc.cc |
+++ b/chrome/browser/chromeos/extensions/file_manager/private_api_misc.cc |
@@ -10,6 +10,7 @@ |
#include "chrome/browser/chromeos/drive/drive_integration_service.h" |
#include "chrome/browser/chromeos/drive/logging.h" |
#include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" |
+#include "chrome/browser/chromeos/extensions/file_manager/webstore_app_installer.h" |
#include "chrome/browser/chromeos/settings/cros_settings.h" |
#include "chrome/browser/lifetime/application_lifetime.h" |
#include "chrome/browser/profiles/profile.h" |
@@ -201,4 +202,58 @@ bool ZoomFunction::RunImpl() { |
return true; |
} |
+InstallWebstoreAppFunction::InstallWebstoreAppFunction() { |
+} |
+ |
+InstallWebstoreAppFunction::~InstallWebstoreAppFunction() { |
+} |
+ |
+bool InstallWebstoreAppFunction::RunImpl() { |
+ if (args_->GetSize() < 1) { |
+ return false; |
+ } |
+ |
+ if (!args_->GetString(0, &webstore_item_id_) || webstore_item_id_.empty()) |
+ return false; |
+ |
+ extensions::WebstoreStandaloneInstaller::Callback callback = |
+ base::Bind(&InstallWebstoreAppFunction::OnInstallComplete, |
+ base::Unretained(this)); |
+ |
+ scoped_refptr<WebstoreAppInstaller> installer( |
+ new WebstoreAppInstaller( |
+ GetAssociatedWebContents(), // web_contents(), |
+ webstore_item_id_, |
+ profile(), |
+ callback)); |
+ // installer will be AddRef()'d in BeginInstall(). |
+ installer->BeginInstall(); |
+ |
+ AddRef(); // Balanced in Release() in OnInstallComplete. |
+ return true; |
+} |
+ |
+void InstallWebstoreAppFunction::OnInstallComplete(bool success, |
+ const std::string& error) { |
+ scoped_ptr<DictionaryValue> result(new DictionaryValue()); |
+ result->SetBoolean("result", success); |
+ result->SetString("error", error); |
+ |
+ if (success) { |
+ drive::util::Log(logging::LOG_INFO, |
+ "App install succeeded. (item id: %s)", |
+ webstore_item_id_.c_str()); |
+ } else { |
+ drive::util::Log(logging::LOG_ERROR, |
+ "App install failed. (item id: %s, reason: %s)", |
+ webstore_item_id_.c_str(), |
+ error.c_str()); |
+ } |
+ |
+ SetResult(result.release()); |
+ SendResponse(success); |
+ |
+ Release(); // Matches the AddRef in RunImpl. |
+} |
+ |
} // namespace file_manager |