summaryrefslogtreecommitdiffstats
path: root/extensions/browser/updater/update_service.cc
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/browser/updater/update_service.cc')
-rw-r--r--extensions/browser/updater/update_service.cc78
1 files changed, 78 insertions, 0 deletions
diff --git a/extensions/browser/updater/update_service.cc b/extensions/browser/updater/update_service.cc
new file mode 100644
index 0000000..286d137
--- /dev/null
+++ b/extensions/browser/updater/update_service.cc
@@ -0,0 +1,78 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "extensions/browser/updater/update_service.h"
+
+#include "base/message_loop/message_loop.h"
+#include "components/omaha_query_params/omaha_query_params.h"
+#include "content/public/browser/browser_context.h"
+#include "extensions/browser/updater/extension_downloader.h"
+#include "extensions/browser/updater/update_service_factory.h"
+#include "extensions/common/extension_urls.h"
+
+using omaha_query_params::OmahaQueryParams;
+
+namespace extensions {
+
+// static
+UpdateService* UpdateService::Get(content::BrowserContext* context) {
+ return UpdateServiceFactory::GetForBrowserContext(context);
+}
+
+void UpdateService::DownloadAndInstall(
+ const std::string& id,
+ const base::Callback<void(bool)>& callback) {
+ DCHECK(download_callback_.is_null());
+ download_callback_ = callback;
+ downloader_->AddPendingExtension(id, extension_urls::GetWebstoreUpdateUrl(),
+ 0);
+ downloader_->StartAllPending(nullptr);
+}
+
+UpdateService::UpdateService(content::BrowserContext* context)
+ : browser_context_(context),
+ downloader_(new ExtensionDownloader(this, context->GetRequestContext())) {
+ downloader_->set_manifest_query_params(
+ OmahaQueryParams::Get(OmahaQueryParams::CRX));
+}
+
+UpdateService::~UpdateService() {
+}
+
+void UpdateService::OnExtensionDownloadFailed(
+ const std::string& id,
+ Error error,
+ const PingResult& ping,
+ const std::set<int>& request_ids) {
+ auto callback = download_callback_;
+ download_callback_.Reset();
+ callback.Run(false);
+}
+
+void UpdateService::OnExtensionDownloadFinished(
+ const std::string& id,
+ const base::FilePath& path,
+ bool file_ownership_passed,
+ const GURL& download_url,
+ const std::string& version,
+ const PingResult& ping,
+ const std::set<int>& request_id) {
+ // TODO(rockot): Actually unpack and install the CRX.
+ auto callback = download_callback_;
+ download_callback_.Reset();
+ callback.Run(true);
+}
+
+bool UpdateService::IsExtensionPending(const std::string& id) {
+ // TODO(rockot): Implement this. For now all IDs are "pending".
+ return true;
+}
+
+bool UpdateService::GetExtensionExistingVersion(const std::string& id,
+ std::string* version) {
+ // TODO(rockot): Implement this.
+ return false;
+}
+
+} // namespace extensions