summaryrefslogtreecommitdiffstats
path: root/extensions/browser/updater/update_service.cc
blob: d356f59fec77b14287326b85ff83b23f258d2666 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// 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/bind.h"
#include "base/files/file_util.h"
#include "components/update_client/update_client.h"
#include "content/public/browser/browser_context.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/extensions_browser_client.h"
#include "extensions/browser/updater/update_data_provider.h"
#include "extensions/browser/updater/update_service_factory.h"

namespace {

void UpdateCheckCompleteCallback(int error) {}

void InstallUpdateCallback(content::BrowserContext* context,
                           const std::string& extension_id,
                           const base::FilePath& temp_dir) {
  extensions::ExtensionSystem::Get(context)
      ->InstallUpdate(extension_id, temp_dir);
}

}  // namespace

namespace extensions {

// static
UpdateService* UpdateService::Get(content::BrowserContext* context) {
  return UpdateServiceFactory::GetForBrowserContext(context);
}

void UpdateService::Shutdown() {
  if (update_data_provider_) {
    update_data_provider_->Shutdown();
    update_data_provider_ = nullptr;
  }
  update_client_ = nullptr;
  context_ = nullptr;
}

void UpdateService::SendUninstallPing(const std::string& id,
                                      const Version& version,
                                      int reason) {
  update_client_->SendUninstallPing(id, version, reason);
}

void UpdateService::StartUpdateCheck(std::vector<std::string> extension_ids) {
  if (!update_client_)
    return;
  update_client_->Update(extension_ids, base::Bind(&UpdateDataProvider::GetData,
                                                   update_data_provider_),
                         base::Bind(&UpdateCheckCompleteCallback));
}

UpdateService::UpdateService(
    content::BrowserContext* context,
    scoped_refptr<update_client::UpdateClient> update_client)
    : context_(context), update_client_(update_client) {
  CHECK(update_client_);
  update_data_provider_ =
      new UpdateDataProvider(context_, base::Bind(&InstallUpdateCallback));
}

UpdateService::~UpdateService() {}

}  // namespace extensions