| OLD | NEW |
| 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_client_config.h" |
| 14 #include "extensions/browser/updater/update_data_provider.h" |
| 15 #include "extensions/browser/updater/update_service_factory.h" |
| 8 | 16 |
| 9 #include "base/message_loop/message_loop.h" | 17 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 | 18 |
| 16 using update_client::UpdateQueryParams; | 19 void UpdateCheckCompleteCallback(int error) {} |
| 20 |
| 21 void InstallUpdateCallback(content::BrowserContext* context, |
| 22 const std::string& extension_id, |
| 23 const base::FilePath& temp_dir) { |
| 24 extensions::ExtensionSystem::Get(context) |
| 25 ->InstallUpdate(extension_id, temp_dir); |
| 26 } |
| 27 |
| 28 } // namespace |
| 17 | 29 |
| 18 namespace extensions { | 30 namespace extensions { |
| 19 | 31 |
| 20 // static | 32 // static |
| 21 UpdateService* UpdateService::Get(content::BrowserContext* context) { | 33 UpdateService* UpdateService::Get(content::BrowserContext* context) { |
| 22 return UpdateServiceFactory::GetForBrowserContext(context); | 34 return UpdateServiceFactory::GetForBrowserContext(context); |
| 23 } | 35 } |
| 24 | 36 |
| 25 void UpdateService::DownloadAndInstall( | 37 void UpdateService::Shutdown() { |
| 26 const std::string& id, | 38 if (update_data_provider_) { |
| 27 const base::Callback<void(bool)>& callback) { | 39 update_data_provider_->Shutdown(); |
| 28 DCHECK(download_callback_.is_null()); | 40 update_data_provider_ = nullptr; |
| 29 download_callback_ = callback; | 41 } |
| 30 downloader_->AddPendingExtension(id, extension_urls::GetWebstoreUpdateUrl(), | 42 update_client_ = nullptr; |
| 31 0); | 43 context_ = nullptr; |
| 32 downloader_->StartAllPending(nullptr); | |
| 33 } | 44 } |
| 34 | 45 |
| 35 UpdateService::UpdateService(content::BrowserContext* context) | 46 void UpdateService::StartUpdateCheck(std::vector<std::string> extension_ids) { |
| 36 : browser_context_(context), | 47 if (!update_client_) |
| 37 downloader_(new ExtensionDownloader(this, context->GetRequestContext())) { | 48 return; |
| 38 downloader_->set_manifest_query_params( | 49 update_client_->Update(extension_ids, base::Bind(&UpdateDataProvider::GetData, |
| 39 UpdateQueryParams::Get(UpdateQueryParams::CRX)); | 50 update_data_provider_), |
| 51 base::Bind(&UpdateCheckCompleteCallback)); |
| 40 } | 52 } |
| 41 | 53 |
| 42 UpdateService::~UpdateService() { | 54 UpdateService::UpdateService( |
| 55 content::BrowserContext* context, |
| 56 scoped_refptr<update_client::UpdateClient> update_client) |
| 57 : context_(context), update_client_(update_client) { |
| 58 CHECK(update_client_); |
| 59 update_data_provider_ = |
| 60 new UpdateDataProvider(context_, base::Bind(&InstallUpdateCallback)); |
| 43 } | 61 } |
| 44 | 62 |
| 45 void UpdateService::OnExtensionDownloadFailed( | 63 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 | 64 |
| 82 } // namespace extensions | 65 } // namespace extensions |
| OLD | NEW |