| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "components/update_client/update_client.h" | 9 #include "components/update_client/update_client.h" |
| 10 #include "components/update_client/update_client_errors.h" | 10 #include "components/update_client/update_client_errors.h" |
| 11 #include "content/public/browser/browser_context.h" | 11 #include "content/public/browser/browser_context.h" |
| 12 #include "extensions/browser/extension_system.h" | 12 #include "extensions/browser/extension_system.h" |
| 13 #include "extensions/browser/extensions_browser_client.h" | 13 #include "extensions/browser/extensions_browser_client.h" |
| 14 #include "extensions/browser/updater/update_data_provider.h" | 14 #include "extensions/browser/updater/update_data_provider.h" |
| 15 #include "extensions/browser/updater/update_service_factory.h" | 15 #include "extensions/browser/updater/update_service_factory.h" |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 void UpdateCheckCompleteCallback(update_client::Error error) {} | 19 void UpdateCheckCompleteCallback(update_client::Error error) {} |
| 20 | 20 |
| 21 void SendUninstallPingCompleteCallback(update_client::Error error) {} |
| 22 |
| 21 void InstallUpdateCallback(content::BrowserContext* context, | 23 void InstallUpdateCallback(content::BrowserContext* context, |
| 22 const std::string& extension_id, | 24 const std::string& extension_id, |
| 23 const base::FilePath& temp_dir) { | 25 const base::FilePath& temp_dir) { |
| 24 extensions::ExtensionSystem::Get(context) | 26 extensions::ExtensionSystem::Get(context) |
| 25 ->InstallUpdate(extension_id, temp_dir); | 27 ->InstallUpdate(extension_id, temp_dir); |
| 26 } | 28 } |
| 27 | 29 |
| 28 } // namespace | 30 } // namespace |
| 29 | 31 |
| 30 namespace extensions { | 32 namespace extensions { |
| 31 | 33 |
| 32 // static | 34 // static |
| 33 UpdateService* UpdateService::Get(content::BrowserContext* context) { | 35 UpdateService* UpdateService::Get(content::BrowserContext* context) { |
| 34 return UpdateServiceFactory::GetForBrowserContext(context); | 36 return UpdateServiceFactory::GetForBrowserContext(context); |
| 35 } | 37 } |
| 36 | 38 |
| 37 void UpdateService::Shutdown() { | 39 void UpdateService::Shutdown() { |
| 38 if (update_data_provider_) { | 40 if (update_data_provider_) { |
| 39 update_data_provider_->Shutdown(); | 41 update_data_provider_->Shutdown(); |
| 40 update_data_provider_ = nullptr; | 42 update_data_provider_ = nullptr; |
| 41 } | 43 } |
| 42 update_client_ = nullptr; | 44 update_client_ = nullptr; |
| 43 context_ = nullptr; | 45 context_ = nullptr; |
| 44 } | 46 } |
| 45 | 47 |
| 46 void UpdateService::SendUninstallPing(const std::string& id, | 48 void UpdateService::SendUninstallPing(const std::string& id, |
| 47 const base::Version& version, | 49 const base::Version& version, |
| 48 int reason) { | 50 int reason) { |
| 49 update_client_->SendUninstallPing(id, version, reason); | 51 update_client_->SendUninstallPing( |
| 52 id, version, reason, base::Bind(&SendUninstallPingCompleteCallback)); |
| 50 } | 53 } |
| 51 | 54 |
| 52 void UpdateService::StartUpdateCheck( | 55 void UpdateService::StartUpdateCheck( |
| 53 const std::vector<std::string>& extension_ids) { | 56 const std::vector<std::string>& extension_ids) { |
| 54 if (!update_client_) | 57 if (!update_client_) |
| 55 return; | 58 return; |
| 56 update_client_->Update(extension_ids, base::Bind(&UpdateDataProvider::GetData, | 59 update_client_->Update(extension_ids, base::Bind(&UpdateDataProvider::GetData, |
| 57 update_data_provider_), | 60 update_data_provider_), |
| 58 base::Bind(&UpdateCheckCompleteCallback)); | 61 base::Bind(&UpdateCheckCompleteCallback)); |
| 59 } | 62 } |
| 60 | 63 |
| 61 UpdateService::UpdateService( | 64 UpdateService::UpdateService( |
| 62 content::BrowserContext* context, | 65 content::BrowserContext* context, |
| 63 scoped_refptr<update_client::UpdateClient> update_client) | 66 scoped_refptr<update_client::UpdateClient> update_client) |
| 64 : context_(context), update_client_(update_client) { | 67 : context_(context), update_client_(update_client) { |
| 65 CHECK(update_client_); | 68 CHECK(update_client_); |
| 66 update_data_provider_ = | 69 update_data_provider_ = |
| 67 new UpdateDataProvider(context_, base::Bind(&InstallUpdateCallback)); | 70 new UpdateDataProvider(context_, base::Bind(&InstallUpdateCallback)); |
| 68 } | 71 } |
| 69 | 72 |
| 70 UpdateService::~UpdateService() {} | 73 UpdateService::~UpdateService() {} |
| 71 | 74 |
| 72 } // namespace extensions | 75 } // namespace extensions |
| OLD | NEW |