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

Unified Diff: components/component_updater/update_checker.cc

Issue 565363002: Implement support for fallback update check urls in the component updater (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: components/component_updater/update_checker.cc
diff --git a/components/component_updater/update_checker.cc b/components/component_updater/update_checker.cc
index 49b2821e7972dcd6117896f863ed55c7a71e2185..e636efd594573c449b31e1ede71b08b2dbcabd78 100644
--- a/components/component_updater/update_checker.cc
+++ b/components/component_updater/update_checker.cc
@@ -4,19 +4,26 @@
#include "components/component_updater/update_checker.h"
+#include <string>
+#include <vector>
+
#include "base/compiler_specific.h"
+#include "base/location.h"
#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
#include "base/strings/stringprintf.h"
#include "base/threading/thread_checker.h"
#include "components/component_updater/component_updater_configurator.h"
#include "components/component_updater/component_updater_utils.h"
#include "components/component_updater/crx_update_item.h"
+#include "components/component_updater/request_sender.h"
#include "net/url_request/url_fetcher.h"
-#include "net/url_request/url_fetcher_delegate.h"
#include "url/gurl.h"
namespace component_updater {
+namespace {
+
// Builds an update check request for |components|. |additional_attributes| is
// serialized as part of the <request> element of the request to customize it
// with data that is not platform or component specific. For each |item|, a
@@ -66,43 +73,31 @@ std::string BuildUpdateCheckRequest(const Configurator& config,
additional_attributes);
}
-class UpdateCheckerImpl : public UpdateChecker, public net::URLFetcherDelegate {
+class UpdateCheckerImpl : public UpdateChecker {
public:
- UpdateCheckerImpl(const Configurator& config,
- const UpdateCheckCallback& update_check_callback);
+ explicit UpdateCheckerImpl(const Configurator& config);
virtual ~UpdateCheckerImpl();
// Overrides for UpdateChecker.
virtual bool CheckForUpdates(
const std::vector<CrxUpdateItem*>& items_to_check,
- const std::string& additional_attributes) OVERRIDE;
-
- // Overrides for UrlFetcher.
- virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
+ const std::string& additional_attributes,
+ const UpdateCheckCallback& update_check_callback) OVERRIDE;
private:
- const Configurator& config_;
- const UpdateCheckCallback update_check_callback_;
+ void OnRequestSenderComplete(const net::URLFetcher* source);
- scoped_ptr<net::URLFetcher> url_fetcher_;
+ const Configurator& config_;
+ UpdateCheckCallback update_check_callback_;
+ scoped_ptr<RequestSender> request_sender_;
base::ThreadChecker thread_checker_;
DISALLOW_COPY_AND_ASSIGN(UpdateCheckerImpl);
};
-scoped_ptr<UpdateChecker> UpdateChecker::Create(
- const Configurator& config,
- const UpdateCheckCallback& update_check_callback) {
- scoped_ptr<UpdateCheckerImpl> update_checker(
- new UpdateCheckerImpl(config, update_check_callback));
- return update_checker.PassAs<UpdateChecker>();
-}
-
-UpdateCheckerImpl::UpdateCheckerImpl(
- const Configurator& config,
- const UpdateCheckCallback& update_check_callback)
- : config_(config), update_check_callback_(update_check_callback) {
+UpdateCheckerImpl::UpdateCheckerImpl(const Configurator& config)
+ : config_(config) {
}
UpdateCheckerImpl::~UpdateCheckerImpl() {
@@ -111,24 +106,31 @@ UpdateCheckerImpl::~UpdateCheckerImpl() {
bool UpdateCheckerImpl::CheckForUpdates(
const std::vector<CrxUpdateItem*>& items_to_check,
- const std::string& additional_attributes) {
+ const std::string& additional_attributes,
+ const UpdateCheckCallback& update_check_callback) {
DCHECK(thread_checker_.CalledOnValidThread());
- if (url_fetcher_)
- return false; // Another fetch is in progress.
+ if (request_sender_.get()) {
+ NOTREACHED();
+ return false; // Another update check is in progress.
+ }
- url_fetcher_.reset(SendProtocolRequest(
- config_.UpdateUrl(),
- BuildUpdateCheckRequest(config_, items_to_check, additional_attributes),
- this,
- config_.RequestContext()));
+ update_check_callback_ = update_check_callback;
+ request_sender_.reset(new RequestSender(config_));
+ request_sender_->Send(
+ BuildUpdateCheckRequest(config_, items_to_check, additional_attributes),
+ config_.UpdateUrl(),
+ base::Bind(&UpdateCheckerImpl::OnRequestSenderComplete,
+ base::Unretained(this)));
return true;
}
-void UpdateCheckerImpl::OnURLFetchComplete(const net::URLFetcher* source) {
+void UpdateCheckerImpl::OnRequestSenderComplete(const net::URLFetcher* source) {
DCHECK(thread_checker_.CalledOnValidThread());
- DCHECK(url_fetcher_.get() == source);
+
+ const GURL original_url(source->GetOriginalURL());
+ VLOG(1) << "Update check request went to: " << original_url.spec();
int error = 0;
std::string error_message;
@@ -148,8 +150,16 @@ void UpdateCheckerImpl::OnURLFetchComplete(const net::URLFetcher* source) {
VLOG(1) << "Update request failed: network error";
}
- url_fetcher_.reset();
- update_check_callback_.Run(error, error_message, update_response.results());
+ request_sender_.reset();
+ update_check_callback_.Run(
+ original_url, error, error_message, update_response.results());
+}
+
+} // namespace
+
+scoped_ptr<UpdateChecker> UpdateChecker::Create(const Configurator& config) {
+ scoped_ptr<UpdateCheckerImpl> update_checker(new UpdateCheckerImpl(config));
erikwright (departed) 2014/09/15 18:37:11 Replace these two lines with: return scoped_ptr<U
Sorin Jianu 2014/09/15 22:17:58 Done.
+ return update_checker.PassAs<UpdateChecker>();
}
} // namespace component_updater

Powered by Google App Engine
This is Rietveld 408576698