Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: extensions/browser/updater/update_service.cc

Issue 1362043005: Add extensions code to use common updater in components/update_client/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merged latest origin/master Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "extensions/browser/updater/update_service.h" 5 #include "extensions/browser/updater/update_service.h"
6 6
7 #include <set> 7 #include "base/bind.h"
8 #include "base/files/file_util.h"
9 #include "components/update_client/update_client.h"
10 #include "content/public/browser/browser_context.h"
11 #include "extensions/browser/extension_system.h"
12 #include "extensions/browser/extensions_browser_client.h"
13 #include "extensions/browser/updater/update_data_provider.h"
14 #include "extensions/browser/updater/update_service_factory.h"
8 15
9 #include "base/message_loop/message_loop.h" 16 namespace {
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"
15 17
16 using update_client::UpdateQueryParams; 18 void UpdateCheckCompleteCallback(int error) {}
19
20 void InstallUpdateCallback(content::BrowserContext* context,
21 const std::string& extension_id,
22 const base::FilePath& temp_dir) {
23 extensions::ExtensionSystem::Get(context)
24 ->InstallUpdate(extension_id, temp_dir);
25 }
26
27 } // namespace
17 28
18 namespace extensions { 29 namespace extensions {
19 30
20 // static 31 // static
21 UpdateService* UpdateService::Get(content::BrowserContext* context) { 32 UpdateService* UpdateService::Get(content::BrowserContext* context) {
22 return UpdateServiceFactory::GetForBrowserContext(context); 33 return UpdateServiceFactory::GetForBrowserContext(context);
23 } 34 }
24 35
25 void UpdateService::DownloadAndInstall( 36 void UpdateService::Shutdown() {
26 const std::string& id, 37 if (update_data_provider_) {
27 const base::Callback<void(bool)>& callback) { 38 update_data_provider_->Shutdown();
28 DCHECK(download_callback_.is_null()); 39 update_data_provider_ = nullptr;
29 download_callback_ = callback; 40 }
30 downloader_->AddPendingExtension(id, extension_urls::GetWebstoreUpdateUrl(), 41 update_client_ = nullptr;
31 0); 42 context_ = nullptr;
32 downloader_->StartAllPending(nullptr);
33 } 43 }
34 44
35 UpdateService::UpdateService(content::BrowserContext* context) 45 void UpdateService::StartUpdateCheck(std::vector<std::string> extension_ids) {
36 : browser_context_(context), 46 if (!update_client_)
37 downloader_(new ExtensionDownloader(this, context->GetRequestContext())) { 47 return;
38 downloader_->set_manifest_query_params( 48 update_client_->Update(extension_ids, base::Bind(&UpdateDataProvider::GetData,
39 UpdateQueryParams::Get(UpdateQueryParams::CRX)); 49 update_data_provider_),
50 base::Bind(&UpdateCheckCompleteCallback));
40 } 51 }
41 52
42 UpdateService::~UpdateService() { 53 UpdateService::UpdateService(
54 content::BrowserContext* context,
55 scoped_refptr<update_client::UpdateClient> update_client)
56 : context_(context), update_client_(update_client) {
57 CHECK(update_client_);
58 update_data_provider_ =
59 new UpdateDataProvider(context_, base::Bind(&InstallUpdateCallback));
43 } 60 }
44 61
45 void UpdateService::OnExtensionDownloadFailed( 62 UpdateService::~UpdateService() {}
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);
53 }
54
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);
69 }
70
71 bool UpdateService::IsExtensionPending(const std::string& id) {
72 // TODO(rockot): Implement this. For now all IDs are "pending".
73 return true;
74 }
75
76 bool UpdateService::GetExtensionExistingVersion(const std::string& id,
77 std::string* version) {
78 // TODO(rockot): Implement this.
79 return false;
80 }
81 63
82 } // namespace extensions 64 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/updater/update_service.h ('k') | extensions/browser/updater/update_service_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698