Add more checks to investigate SupervisedUserPrefStore crash at startup.
[chromium-blink-merge.git] / extensions / browser / updater / update_service.cc
blob10a86c37886bfa425a2ae0aa3c99ecf713d513d6
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "extensions/browser/updater/update_service.h"
7 #include <set>
9 #include "base/message_loop/message_loop.h"
10 #include "components/update_client/update_query_params.h"
11 #include "content/public/browser/browser_context.h"
12 #include "extensions/browser/updater/extension_downloader.h"
13 #include "extensions/browser/updater/update_service_factory.h"
14 #include "extensions/common/extension_urls.h"
16 using update_client::UpdateQueryParams;
18 namespace extensions {
20 // static
21 UpdateService* UpdateService::Get(content::BrowserContext* context) {
22 return UpdateServiceFactory::GetForBrowserContext(context);
25 void UpdateService::DownloadAndInstall(
26 const std::string& id,
27 const base::Callback<void(bool)>& callback) {
28 DCHECK(download_callback_.is_null());
29 download_callback_ = callback;
30 downloader_->AddPendingExtension(id, extension_urls::GetWebstoreUpdateUrl(),
31 0);
32 downloader_->StartAllPending(nullptr);
35 UpdateService::UpdateService(content::BrowserContext* context)
36 : browser_context_(context),
37 downloader_(new ExtensionDownloader(this, context->GetRequestContext())) {
38 downloader_->set_manifest_query_params(
39 UpdateQueryParams::Get(UpdateQueryParams::CRX));
42 UpdateService::~UpdateService() {
45 void UpdateService::OnExtensionDownloadFailed(
46 const std::string& id,
47 Error error,
48 const PingResult& ping,
49 const std::set<int>& request_ids) {
50 auto callback = download_callback_;
51 download_callback_.Reset();
52 callback.Run(false);
55 void UpdateService::OnExtensionDownloadFinished(
56 const CRXFileInfo& file,
57 bool file_ownership_passed,
58 const GURL& download_url,
59 const std::string& version,
60 const PingResult& ping,
61 const std::set<int>& request_id) {
62 // TODO(rockot): Actually unpack and install the CRX.
63 auto callback = download_callback_;
64 download_callback_.Reset();
65 callback.Run(true);
68 bool UpdateService::IsExtensionPending(const std::string& id) {
69 // TODO(rockot): Implement this. For now all IDs are "pending".
70 return true;
73 bool UpdateService::GetExtensionExistingVersion(const std::string& id,
74 std::string* version) {
75 // TODO(rockot): Implement this.
76 return false;
79 } // namespace extensions