Extension syncing: Introduce a NeedsSync pref
[chromium-blink-merge.git] / extensions / browser / updater / update_service.cc
blob0cb055cf6f5e8b48df83923299170aa46fa6f9ec
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 const InstallCallback& install_callback) {
63 // TODO(rockot): Actually unpack and install the CRX.
64 auto callback = download_callback_;
65 download_callback_.Reset();
66 callback.Run(true);
67 if (!install_callback.is_null())
68 install_callback.Run(true);
71 bool UpdateService::IsExtensionPending(const std::string& id) {
72 // TODO(rockot): Implement this. For now all IDs are "pending".
73 return true;
76 bool UpdateService::GetExtensionExistingVersion(const std::string& id,
77 std::string* version) {
78 // TODO(rockot): Implement this.
79 return false;
82 } // namespace extensions