diff options
author | sorin <sorin@chromium.org> | 2016-01-14 15:01:31 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-01-14 23:04:09 +0000 |
commit | 805aa031138fcaa9bff81322aea044f421d39d3e (patch) | |
tree | 9d66604c0bc1092c7f7eb60fe05446e2fbca3db1 | |
parent | 11195385967983a0b5fc3865576a9fa826d51711 (diff) | |
download | chromium_src-805aa031138fcaa9bff81322aea044f421d39d3e.zip chromium_src-805aa031138fcaa9bff81322aea044f421d39d3e.tar.gz chromium_src-805aa031138fcaa9bff81322aea044f421d39d3e.tar.bz2 |
Implements an UpdateClient::SendUninstallPing API for the
extension manager to send uninstall pings through Omaha.
BUG=501641
Review URL: https://codereview.chromium.org/1578083002
Cr-Commit-Position: refs/heads/master@{#369594}
-rw-r--r-- | chrome/browser/ui/webui/components_ui.cc | 1 | ||||
-rw-r--r-- | components/component_updater/component_updater_service_unittest.cc | 2 | ||||
-rw-r--r-- | components/update_client/action.cc | 3 | ||||
-rw-r--r-- | components/update_client/crx_update_item.h | 1 | ||||
-rw-r--r-- | components/update_client/ping_manager.cc | 36 | ||||
-rw-r--r-- | components/update_client/ping_manager.h | 2 | ||||
-rw-r--r-- | components/update_client/ping_manager_unittest.cc | 10 | ||||
-rw-r--r-- | components/update_client/update_client.cc | 17 | ||||
-rw-r--r-- | components/update_client/update_client.h | 9 | ||||
-rw-r--r-- | components/update_client/update_client_internal.h | 3 | ||||
-rw-r--r-- | components/update_client/update_client_unittest.cc | 60 | ||||
-rw-r--r-- | extensions/browser/updater/update_service_unittest.cc | 3 |
12 files changed, 136 insertions, 11 deletions
diff --git a/chrome/browser/ui/webui/components_ui.cc b/chrome/browser/ui/webui/components_ui.cc index 581ca6f..7eb610a 100644 --- a/chrome/browser/ui/webui/components_ui.cc +++ b/chrome/browser/ui/webui/components_ui.cc @@ -237,6 +237,7 @@ base::string16 ComponentsUI::ServiceStatusToString( return l10n_util::GetStringUTF16(IDS_COMPONENTS_SVC_STATUS_UPTODATE); case update_client::CrxUpdateItem::State::kNoUpdate: return l10n_util::GetStringUTF16(IDS_COMPONENTS_SVC_STATUS_NOUPDATE); + case update_client::CrxUpdateItem::State::kUninstalled: // Fall through. case update_client::CrxUpdateItem::State::kLastStatus: return l10n_util::GetStringUTF16(IDS_COMPONENTS_UNKNOWN); } diff --git a/components/component_updater/component_updater_service_unittest.cc b/components/component_updater/component_updater_service_unittest.cc index a5a839d..15b62bb 100644 --- a/components/component_updater/component_updater_service_unittest.cc +++ b/components/component_updater/component_updater_service_unittest.cc @@ -72,6 +72,8 @@ class MockUpdateClient : public UpdateClient { bool(const std::string& id, CrxUpdateItem* update_item)); MOCK_CONST_METHOD1(IsUpdating, bool(const std::string& id)); MOCK_METHOD0(Stop, void()); + MOCK_METHOD3(SendUninstallPing, + void(const std::string& id, const Version& version, int reason)); private: ~MockUpdateClient() override; diff --git a/components/update_client/action.cc b/components/update_client/action.cc index 3cdce79..de795e6 100644 --- a/components/update_client/action.cc +++ b/components/update_client/action.cc @@ -89,6 +89,7 @@ void ActionImpl::ChangeItemState(CrxUpdateItem* item, CrxUpdateItem::State to) { case CrxUpdateItem::State::kDownloading: case CrxUpdateItem::State::kDownloadingDiff: case CrxUpdateItem::State::kDownloaded: + case CrxUpdateItem::State::kUninstalled: case CrxUpdateItem::State::kLastStatus: // No notification for these states. break; @@ -135,7 +136,7 @@ void ActionImpl::UpdateCrx() { } void ActionImpl::UpdateCrxComplete(CrxUpdateItem* item) { - update_context_->ping_manager->OnUpdateComplete(item); + update_context_->ping_manager->SendPing(item); update_context_->queue.pop(); diff --git a/components/update_client/crx_update_item.h b/components/update_client/crx_update_item.h index a9cf171..e137e6e 100644 --- a/components/update_client/crx_update_item.h +++ b/components/update_client/crx_update_item.h @@ -68,6 +68,7 @@ struct CrxUpdateItem { kUpdated, kUpToDate, kNoUpdate, + kUninstalled, kLastStatus }; diff --git a/components/update_client/ping_manager.cc b/components/update_client/ping_manager.cc index 0169a64..7d05e5a 100644 --- a/components/update_client/ping_manager.cc +++ b/components/update_client/ping_manager.cc @@ -81,7 +81,8 @@ std::string BuildDownloadCompleteEventElements(const CrxUpdateItem* item) { return download_events; } -// Returns a string representing one ping event xml element for an update item. +// Returns a string representing one ping event for the update of an item. +// The event type for this ping event is 3. std::string BuildUpdateCompleteEventElement(const CrxUpdateItem* item) { DCHECK(item->state == CrxUpdateItem::State::kNoUpdate || item->state == CrxUpdateItem::State::kUpdated); @@ -117,6 +118,20 @@ std::string BuildUpdateCompleteEventElement(const CrxUpdateItem* item) { return ping_event; } +// Returns a string representing one ping event for the uninstall of an item. +// The event type for this ping event is 4. +std::string BuildUninstalledEventElement(const CrxUpdateItem* item) { + DCHECK(item->state == CrxUpdateItem::State::kUninstalled); + + using base::StringAppendF; + + std::string ping_event("<event eventtype=\"4\" eventresult=\"1\""); + if (item->extra_code1) + StringAppendF(&ping_event, " extracode1=\"%d\"", item->extra_code1); + StringAppendF(&ping_event, "/>"); + return ping_event; +} + // Builds a ping message for the specified update item. std::string BuildPing(const Configurator& config, const CrxUpdateItem* item) { const char app_element_format[] = @@ -124,12 +139,27 @@ std::string BuildPing(const Configurator& config, const CrxUpdateItem* item) { "%s" "%s" "</app>"; + + std::string ping_event; + switch (item->state) { + case CrxUpdateItem::State::kNoUpdate: // Fall through. + case CrxUpdateItem::State::kUpdated: + ping_event = BuildUpdateCompleteEventElement(item); + break; + case CrxUpdateItem::State::kUninstalled: + ping_event = BuildUninstalledEventElement(item); + break; + default: + NOTREACHED(); + break; + } + const std::string app_element(base::StringPrintf( app_element_format, item->id.c_str(), // "appid" item->previous_version.GetString().c_str(), // "version" item->next_version.GetString().c_str(), // "nextversion" - BuildUpdateCompleteEventElement(item).c_str(), // update event + ping_event.c_str(), // ping event BuildDownloadCompleteEventElements(item).c_str())); // download events return BuildProtocolRequest(config.GetBrowserVersion().GetString(), @@ -195,7 +225,7 @@ PingManager::~PingManager() { // Sends a fire and forget ping when the updates are complete. The ping // sender object self-deletes after sending the ping has completed asynchrously. -void PingManager::OnUpdateComplete(const CrxUpdateItem* item) { +void PingManager::SendPing(const CrxUpdateItem* item) { PingSender* ping_sender(new PingSender(config_)); if (!ping_sender->SendPing(item)) delete ping_sender; diff --git a/components/update_client/ping_manager.h b/components/update_client/ping_manager.h index be6180e..d5a6311 100644 --- a/components/update_client/ping_manager.h +++ b/components/update_client/ping_manager.h @@ -19,7 +19,7 @@ class PingManager { explicit PingManager(const scoped_refptr<Configurator>& config); virtual ~PingManager(); - virtual void OnUpdateComplete(const CrxUpdateItem* item); + virtual void SendPing(const CrxUpdateItem* item); private: const scoped_refptr<Configurator> config_; diff --git a/components/update_client/ping_manager_unittest.cc b/components/update_client/ping_manager_unittest.cc index 4a9f381..cf1d147 100644 --- a/components/update_client/ping_manager_unittest.cc +++ b/components/update_client/ping_manager_unittest.cc @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <string> + #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/run_loop.h" @@ -70,7 +72,7 @@ TEST_F(ComponentUpdaterPingManagerTest, DISABLED_PingManagerTest) { item.previous_version = base::Version("1.0"); item.next_version = base::Version("2.0"); - ping_manager_->OnUpdateComplete(&item); + ping_manager_->SendPing(&item); base::RunLoop().RunUntilIdle(); EXPECT_EQ(1, interceptor->GetCount()) << interceptor->GetRequestsAsString(); @@ -88,7 +90,7 @@ TEST_F(ComponentUpdaterPingManagerTest, DISABLED_PingManagerTest) { item.previous_version = base::Version("1.0"); item.next_version = base::Version("2.0"); - ping_manager_->OnUpdateComplete(&item); + ping_manager_->SendPing(&item); base::RunLoop().RunUntilIdle(); EXPECT_EQ(1, interceptor->GetCount()) << interceptor->GetRequestsAsString(); @@ -116,7 +118,7 @@ TEST_F(ComponentUpdaterPingManagerTest, DISABLED_PingManagerTest) { item.diff_update_failed = true; item.crx_diffurls.push_back(GURL("http://host/path")); - ping_manager_->OnUpdateComplete(&item); + ping_manager_->SendPing(&item); base::RunLoop().RunUntilIdle(); EXPECT_EQ(1, interceptor->GetCount()) << interceptor->GetRequestsAsString(); @@ -156,7 +158,7 @@ TEST_F(ComponentUpdaterPingManagerTest, DISABLED_PingManagerTest) { download_metrics.download_time_ms = 9870; item.download_metrics.push_back(download_metrics); - ping_manager_->OnUpdateComplete(&item); + ping_manager_->SendPing(&item); base::RunLoop().RunUntilIdle(); EXPECT_EQ(1, interceptor->GetCount()) << interceptor->GetRequestsAsString(); diff --git a/components/update_client/update_client.cc b/components/update_client/update_client.cc index 05d8fbe..9f6e9559 100644 --- a/components/update_client/update_client.cc +++ b/components/update_client/update_client.cc @@ -226,6 +226,23 @@ void UpdateClientImpl::Stop() { } } +void UpdateClientImpl::SendUninstallPing(const std::string& id, + const Version& version, + int reason) { + DCHECK(thread_checker_.CalledOnValidThread()); + + // The implementation of PingManager::SendPing contains a self-deleting + // object responsible for sending the ping. + CrxUpdateItem item; + item.state = CrxUpdateItem::State::kUninstalled; + item.id = id; + item.previous_version = version; + item.next_version = base::Version("0"); + item.extra_code1 = reason; + + ping_manager_->SendPing(&item); +} + scoped_refptr<UpdateClient> UpdateClientFactory( const scoped_refptr<Configurator>& config) { scoped_ptr<PingManager> ping_manager(new PingManager(config)); diff --git a/components/update_client/update_client.h b/components/update_client/update_client.h index f5107d5..7e6329f 100644 --- a/components/update_client/update_client.h +++ b/components/update_client/update_client.h @@ -289,6 +289,15 @@ class UpdateClient : public base::RefCounted<UpdateClient> { const CrxDataCallback& crx_data_callback, const CompletionCallback& completion_callback) = 0; + // Sends an uninstall ping for the CRX identified by |id| and |version|. The + // |reason| parameter is defined by the caller. The current implementation of + // this function only sends a best-effort, fire-and-forget ping. It has no + // other side effects regarding installs or updates done through an instance + // of this class. + virtual void SendUninstallPing(const std::string& id, + const Version& version, + int reason) = 0; + // Returns status details about a CRX update. The function returns true in // case of success and false in case of errors, such as |id| was // invalid or not known. diff --git a/components/update_client/update_client_internal.h b/components/update_client/update_client_internal.h index 6a5bf39..6df2b99 100644 --- a/components/update_client/update_client_internal.h +++ b/components/update_client/update_client_internal.h @@ -53,6 +53,9 @@ class UpdateClientImpl : public UpdateClient { CrxUpdateItem* update_item) const override; bool IsUpdating(const std::string& id) const override; void Stop() override; + void SendUninstallPing(const std::string& id, + const Version& version, + int reason) override; private: ~UpdateClientImpl() override; diff --git a/components/update_client/update_client_unittest.cc b/components/update_client/update_client_unittest.cc index 6420439..5b7e663 100644 --- a/components/update_client/update_client_unittest.cc +++ b/components/update_client/update_client_unittest.cc @@ -97,7 +97,7 @@ class FakePingManagerImpl : public PingManager { explicit FakePingManagerImpl(const scoped_refptr<Configurator>& config); ~FakePingManagerImpl() override; - void OnUpdateComplete(const CrxUpdateItem* item) override; + void SendPing(const CrxUpdateItem* item) override; const std::vector<CrxUpdateItem>& items() const; @@ -113,7 +113,7 @@ FakePingManagerImpl::FakePingManagerImpl( FakePingManagerImpl::~FakePingManagerImpl() { } -void FakePingManagerImpl::OnUpdateComplete(const CrxUpdateItem* item) { +void FakePingManagerImpl::SendPing(const CrxUpdateItem* item) { items_.push_back(*item); } @@ -2135,4 +2135,60 @@ TEST_F(UpdateClientTest, EmptyIdList) { runloop.Run(); } +TEST_F(UpdateClientTest, SendUninstallPing) { + class FakeUpdateChecker : public UpdateChecker { + public: + static scoped_ptr<UpdateChecker> Create( + const scoped_refptr<Configurator>& config) { + return nullptr; + } + + bool CheckForUpdates( + const std::vector<CrxUpdateItem*>& items_to_check, + const std::string& additional_attributes, + const UpdateCheckCallback& update_check_callback) override { + return false; + } + }; + + class FakeCrxDownloader : public CrxDownloader { + public: + static scoped_ptr<CrxDownloader> Create( + bool is_background_download, + net::URLRequestContextGetter* context_getter, + const scoped_refptr<base::SequencedTaskRunner>& + url_fetcher_task_runner) { + return nullptr; + } + + private: + FakeCrxDownloader() : CrxDownloader(scoped_ptr<CrxDownloader>()) {} + ~FakeCrxDownloader() override {} + + void DoStartDownload(const GURL& url) override {} + }; + + class FakePingManager : public FakePingManagerImpl { + public: + explicit FakePingManager(const scoped_refptr<Configurator>& config) + : FakePingManagerImpl(config) {} + ~FakePingManager() override { + const auto& ping_items = items(); + EXPECT_EQ(1U, ping_items.size()); + EXPECT_EQ("jebgalgnebhfojomionfpkfelancnnkf", ping_items[0].id); + EXPECT_TRUE(base::Version("1.0").Equals(ping_items[0].previous_version)); + EXPECT_TRUE(base::Version("0.0").Equals(ping_items[0].next_version)); + EXPECT_EQ(10, ping_items[0].extra_code1); + } + }; + + scoped_ptr<PingManager> ping_manager(new FakePingManager(config())); + scoped_refptr<UpdateClient> update_client(new UpdateClientImpl( + config(), std::move(ping_manager), &FakeUpdateChecker::Create, + &FakeCrxDownloader::Create)); + + update_client->SendUninstallPing("jebgalgnebhfojomionfpkfelancnnkf", + base::Version("1.0"), 10); +} + } // namespace update_client diff --git a/extensions/browser/updater/update_service_unittest.cc b/extensions/browser/updater/update_service_unittest.cc index 283ff20..a6ed8b7 100644 --- a/extensions/browser/updater/update_service_unittest.cc +++ b/extensions/browser/updater/update_service_unittest.cc @@ -49,6 +49,9 @@ class FakeUpdateClient : public update_client::UpdateClient { } bool IsUpdating(const std::string& id) const override { return false; } void Stop() override {} + void SendUninstallPing(const std::string& id, + const Version& version, + int reason) override {} protected: friend class base::RefCounted<FakeUpdateClient>; |