diff options
Diffstat (limited to 'chromium/components/search_provider_logos')
7 files changed, 111 insertions, 120 deletions
diff --git a/chromium/components/search_provider_logos/BUILD.gn b/chromium/components/search_provider_logos/BUILD.gn index 07e2f6cd5aa..1861979218b 100644 --- a/chromium/components/search_provider_logos/BUILD.gn +++ b/chromium/components/search_provider_logos/BUILD.gn @@ -36,6 +36,8 @@ static_library("search_provider_logos") { "//components/search_engines", "//components/signin/core/browser", "//net", + "//services/network/public/cpp", + "//services/network/public/mojom", "//ui/gfx", "//url", ] @@ -99,6 +101,7 @@ source_set("unit_tests") { "//components/signin/core/browser:test_support", "//components/sync_preferences:test_support", "//net:test_support", + "//services/network:test_support", "//testing/gmock", "//testing/gtest", "//ui/gfx", diff --git a/chromium/components/search_provider_logos/DEPS b/chromium/components/search_provider_logos/DEPS index 0d5e959a2a7..10a30abb6b2 100644 --- a/chromium/components/search_provider_logos/DEPS +++ b/chromium/components/search_provider_logos/DEPS @@ -6,6 +6,9 @@ include_rules = [ "+components/signin/core/browser", "+components/sync_preferences/testing_pref_service_syncable.h", "+net", + "+services/network/public/cpp", + "+services/network/public/mojom", + "+services/network/test", "+third_party/skia/include/core/SkBitmap.h", "+ui/gfx/image", ] diff --git a/chromium/components/search_provider_logos/logo_service_impl.cc b/chromium/components/search_provider_logos/logo_service_impl.cc index 3c7ec3f5de7..6dc002751be 100644 --- a/chromium/components/search_provider_logos/logo_service_impl.cc +++ b/chromium/components/search_provider_logos/logo_service_impl.cc @@ -22,7 +22,7 @@ #include "components/search_provider_logos/logo_tracker.h" #include "components/search_provider_logos/switches.h" #include "components/signin/core/browser/gaia_cookie_manager_service.h" -#include "net/url_request/url_request_context_getter.h" +#include "services/network/public/cpp/shared_url_loader_factory.h" #include "ui/gfx/image/image.h" using search_provider_logos::LogoDelegate; @@ -178,11 +178,11 @@ LogoServiceImpl::LogoServiceImpl( GaiaCookieManagerService* cookie_service, TemplateURLService* template_url_service, std::unique_ptr<image_fetcher::ImageDecoder> image_decoder, - scoped_refptr<net::URLRequestContextGetter> request_context_getter, + scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory, base::RepeatingCallback<bool()> want_gray_logo_getter) : cache_directory_(cache_directory), template_url_service_(template_url_service), - request_context_getter_(request_context_getter), + url_loader_factory_(url_loader_factory), want_gray_logo_getter_(std::move(want_gray_logo_getter)), image_decoder_(std::move(image_decoder)), signin_observer_(std::make_unique<SigninObserver>( @@ -304,7 +304,7 @@ void LogoServiceImpl::InitializeLogoTrackerIfNecessary() { } logo_tracker_ = std::make_unique<LogoTracker>( - request_context_getter_, + url_loader_factory_, std::make_unique<LogoDelegateImpl>(std::move(image_decoder_)), std::move(logo_cache), clock); } diff --git a/chromium/components/search_provider_logos/logo_service_impl.h b/chromium/components/search_provider_logos/logo_service_impl.h index 6dbf07912bb..16bf1186692 100644 --- a/chromium/components/search_provider_logos/logo_service_impl.h +++ b/chromium/components/search_provider_logos/logo_service_impl.h @@ -23,9 +23,9 @@ namespace image_fetcher { class ImageDecoder; } // namespace image_fetcher -namespace net { -class URLRequestContextGetter; -} // namespace net +namespace network { +class SharedURLLoaderFactory; +} // namespace network namespace search_provider_logos { @@ -40,7 +40,7 @@ class LogoServiceImpl : public LogoService { GaiaCookieManagerService* cookie_service, TemplateURLService* template_url_service, std::unique_ptr<image_fetcher::ImageDecoder> image_decoder, - scoped_refptr<net::URLRequestContextGetter> request_context_getter, + scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory, base::RepeatingCallback<bool()> want_gray_logo_getter); ~LogoServiceImpl() override; @@ -68,7 +68,7 @@ class LogoServiceImpl : public LogoService { // Constructor arguments. const base::FilePath cache_directory_; TemplateURLService* const template_url_service_; - const scoped_refptr<net::URLRequestContextGetter> request_context_getter_; + const scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_; // Callback to get the type of logo to fetch. Returns whether we want a logo // optimized for gray backgrounds or not. diff --git a/chromium/components/search_provider_logos/logo_service_impl_unittest.cc b/chromium/components/search_provider_logos/logo_service_impl_unittest.cc index 83ac25aff14..9ea86f4bd7e 100644 --- a/chromium/components/search_provider_logos/logo_service_impl_unittest.cc +++ b/chromium/components/search_provider_logos/logo_service_impl_unittest.cc @@ -45,8 +45,9 @@ #include "net/http/http_response_headers.h" #include "net/http/http_status_code.h" #include "net/url_request/test_url_fetcher_factory.h" -#include "net/url_request/url_request_status.h" #include "net/url_request/url_request_test_util.h" +#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h" +#include "services/network/test/test_url_loader_factory.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/gfx/image/image.h" @@ -280,16 +281,13 @@ class FakeImageDecoder : public image_fetcher::ImageDecoder { // signing in/out. class SigninHelper { public: - SigninHelper(base::test::ScopedTaskEnvironment* task_environment, - net::FakeURLFetcherFactory* fetcher_factory) + explicit SigninHelper(base::test::ScopedTaskEnvironment* task_environment) : task_environment_(task_environment), signin_client_(&pref_service_), cookie_service_(&token_service_, "test_source", &signin_client_) { // GaiaCookieManagerService calls static methods of AccountTrackerService // which access prefs. AccountTrackerService::RegisterPrefs(pref_service_.registry()); - - cookie_service_.Init(fetcher_factory); } GaiaCookieManagerService* cookie_service() { return &cookie_service_; } @@ -321,12 +319,14 @@ class LogoServiceImplTest : public ::testing::Test { LogoServiceImplTest() : template_url_service_(nullptr, 0), logo_cache_(new NiceMock<MockLogoCache>()), - fake_url_fetcher_factory_( - nullptr, - base::Bind(&LogoServiceImplTest::CapturingFakeURLFetcherCreator, - base::Unretained(this))), - signin_helper_(&task_environment_, &fake_url_fetcher_factory_), + shared_factory_( + base::MakeRefCounted<network::WeakWrapperSharedURLLoaderFactory>( + &test_url_loader_factory_)), + signin_helper_(&task_environment_), use_gray_background_(false) { + test_url_loader_factory_.SetInterceptor(base::BindRepeating( + &LogoServiceImplTest::CapturingInterceptor, base::Unretained(this))); + // Default search engine with logo. All 3P doodle_urls use ddljson API. AddSearchEngine("ex", "Logo Example", "https://example.com/?q={searchTerms}", @@ -337,8 +337,7 @@ class LogoServiceImplTest : public ::testing::Test { logo_service_ = std::make_unique<LogoServiceImpl>( base::FilePath(), signin_helper_.cookie_service(), &template_url_service_, std::make_unique<FakeImageDecoder>(), - new net::TestURLRequestContextGetter( - base::ThreadTaskRunnerHandle::Get()), + shared_factory_, base::BindRepeating(&LogoServiceImplTest::use_gray_background, base::Unretained(this))); logo_service_->SetClockForTests(&test_clock_); @@ -359,8 +358,7 @@ class LogoServiceImplTest : public ::testing::Test { // Sets the response to be returned when the LogoTracker fetches the logo. void SetServerResponse(const std::string& response, - net::URLRequestStatus::Status request_status = - net::URLRequestStatus::SUCCESS, + int error_code = net::OK, net::HttpStatusCode response_code = net::HTTP_OK); // Sets the response to be returned when the LogoTracker fetches the logo and @@ -368,8 +366,7 @@ class LogoServiceImplTest : public ::testing::Test { void SetServerResponseWhenFingerprint( const std::string& fingerprint, const std::string& response_when_fingerprint, - net::URLRequestStatus::Status request_status = - net::URLRequestStatus::SUCCESS, + int error_code = net::OK, net::HttpStatusCode response_code = net::HTTP_OK); const GURL& DoodleURL() const; @@ -385,12 +382,7 @@ class LogoServiceImplTest : public ::testing::Test { GURL doodle_url, bool make_default); - std::unique_ptr<net::FakeURLFetcher> CapturingFakeURLFetcherCreator( - const GURL& url, - net::URLFetcherDelegate* delegate, - const std::string& response_data, - net::HttpStatusCode response_code, - net::URLRequestStatus::Status status); + void CapturingInterceptor(const network::ResourceRequest& request); bool use_gray_background() const { return use_gray_background_; } @@ -398,24 +390,21 @@ class LogoServiceImplTest : public ::testing::Test { TemplateURLService template_url_service_; base::SimpleTestClock test_clock_; NiceMock<MockLogoCache>* logo_cache_; - net::FakeURLFetcherFactory fake_url_fetcher_factory_; + + // Used for mocking |logo_service_| URLs. + network::TestURLLoaderFactory test_url_loader_factory_; + scoped_refptr<network::SharedURLLoaderFactory> shared_factory_; std::unique_ptr<LogoServiceImpl> logo_service_; + SigninHelper signin_helper_; GURL latest_url_; bool use_gray_background_; }; -std::unique_ptr<net::FakeURLFetcher> -LogoServiceImplTest::CapturingFakeURLFetcherCreator( - const GURL& url, - net::URLFetcherDelegate* delegate, - const std::string& response_data, - net::HttpStatusCode response_code, - net::URLRequestStatus::Status status) { - latest_url_ = url; - return std::make_unique<net::FakeURLFetcher>(url, delegate, response_data, - response_code, status); +void LogoServiceImplTest::CapturingInterceptor( + const network::ResourceRequest& request) { + latest_url_ = request.url; } std::string LogoServiceImplTest::ServerResponse(const Logo& logo) { @@ -425,23 +414,34 @@ std::string LogoServiceImplTest::ServerResponse(const Logo& logo) { return MakeServerResponse(logo, time_to_live); } -void LogoServiceImplTest::SetServerResponse( - const std::string& response, - net::URLRequestStatus::Status request_status, - net::HttpStatusCode response_code) { - SetServerResponseWhenFingerprint(std::string(), response, request_status, +void LogoServiceImplTest::SetServerResponse(const std::string& response, + int error_code, + net::HttpStatusCode response_code) { + SetServerResponseWhenFingerprint(std::string(), response, error_code, response_code); } void LogoServiceImplTest::SetServerResponseWhenFingerprint( const std::string& fingerprint, const std::string& response_when_fingerprint, - net::URLRequestStatus::Status request_status, + int error_code, net::HttpStatusCode response_code) { GURL url_with_fp = AppendFingerprintParamToDoodleURL( AppendPreliminaryParamsToDoodleURL(false, DoodleURL()), fingerprint); - fake_url_fetcher_factory_.SetFakeResponse( - url_with_fp, response_when_fingerprint, response_code, request_status); + + network::ResourceResponseHead head; + std::string headers(base::StringPrintf( + "HTTP/1.1 %d %s\nContent-type: text/html\n\n", + static_cast<int>(response_code), GetHttpReasonPhrase(response_code))); + head.headers = new net::HttpResponseHeaders( + net::HttpUtil::AssembleRawHeaders(headers.c_str(), headers.size())); + head.mime_type = "text/html"; + network::URLLoaderCompletionStatus status; + status.error_code = error_code; + status.decoded_body_length = response_when_fingerprint.size(); + + test_url_loader_factory_.AddResponse(url_with_fp, head, + response_when_fingerprint, status); } const GURL& LogoServiceImplTest::DoodleURL() const { @@ -498,10 +498,9 @@ TEST_F(LogoServiceImplTest, CTARequestedBackgroundCanUpdate) { AppendPreliminaryParamsToDoodleURL(false, DoodleURL()), std::string()); use_gray_background_ = false; - fake_url_fetcher_factory_.ClearFakeResponses(); - fake_url_fetcher_factory_.SetFakeResponse(query_without_gray_background, - response, net::HTTP_OK, - net::URLRequestStatus::SUCCESS); + test_url_loader_factory_.ClearResponses(); + test_url_loader_factory_.AddResponse(query_without_gray_background.spec(), + response, net::HTTP_OK); { StrictMock<MockLogoCallback> fresh; EXPECT_CALL(fresh, Run(_, _)); @@ -513,10 +512,9 @@ TEST_F(LogoServiceImplTest, CTARequestedBackgroundCanUpdate) { EXPECT_EQ(latest_url_.query().find("graybg:1"), std::string::npos); use_gray_background_ = true; - fake_url_fetcher_factory_.ClearFakeResponses(); - fake_url_fetcher_factory_.SetFakeResponse(query_with_gray_background, - response, net::HTTP_OK, - net::URLRequestStatus::SUCCESS); + test_url_loader_factory_.ClearResponses(); + test_url_loader_factory_.AddResponse(query_with_gray_background.spec(), + response, net::HTTP_OK); { StrictMock<MockLogoCallback> fresh; EXPECT_CALL(fresh, Run(_, _)); @@ -589,7 +587,7 @@ TEST_F(LogoServiceImplTest, EmptyCacheAndFailedDownload) { { StrictMock<MockLogoCallback> cached; StrictMock<MockLogoCallback> fresh; - SetServerResponse("", net::URLRequestStatus::FAILED, net::HTTP_OK); + SetServerResponse("", net::ERR_FAILED, net::HTTP_OK); EXPECT_CALL(cached, Run(LogoCallbackReason::DETERMINED, Eq(base::nullopt))); EXPECT_CALL(fresh, Run(LogoCallbackReason::FAILED, Eq(base::nullopt))); GetDecodedLogo(cached.Get(), fresh.Get()); @@ -598,8 +596,7 @@ TEST_F(LogoServiceImplTest, EmptyCacheAndFailedDownload) { { StrictMock<MockLogoCallback> cached; StrictMock<MockLogoCallback> fresh; - SetServerResponse("", net::URLRequestStatus::SUCCESS, - net::HTTP_BAD_GATEWAY); + SetServerResponse("", net::OK, net::HTTP_BAD_GATEWAY); EXPECT_CALL(cached, Run(LogoCallbackReason::DETERMINED, Eq(base::nullopt))); EXPECT_CALL(fresh, Run(LogoCallbackReason::FAILED, Eq(base::nullopt))); GetDecodedLogo(cached.Get(), fresh.Get()); @@ -632,7 +629,7 @@ TEST_F(LogoServiceImplTest, ReturnCachedLogo) { Logo cached_logo = GetSampleLogo(DoodleURL(), test_clock_.Now()); logo_cache_->EncodeAndSetCachedLogo(cached_logo); SetServerResponseWhenFingerprint(cached_logo.metadata.fingerprint, "", - net::URLRequestStatus::FAILED, net::HTTP_OK); + net::ERR_FAILED, net::HTTP_OK); EXPECT_CALL(*logo_cache_, UpdateCachedLogoMetadata(_)).Times(0); EXPECT_CALL(*logo_cache_, SetCachedLogo(_)).Times(0); @@ -769,7 +766,7 @@ TEST_F(LogoServiceImplTest, InvalidateCachedLogo) { } TEST_F(LogoServiceImplTest, DeleteCachedLogoFromOldUrl) { - SetServerResponse("", net::URLRequestStatus::FAILED, net::HTTP_OK); + SetServerResponse("", net::ERR_FAILED, net::HTTP_OK); Logo cached_logo = GetSampleLogo(GURL("https://oldsearchprovider.com"), test_clock_.Now()); logo_cache_->EncodeAndSetCachedLogo(cached_logo); @@ -820,7 +817,7 @@ TEST_F(LogoServiceImplTest, LogoWithoutTTLCanBeShownAfterExpiration) { } TEST_F(LogoServiceImplTest, UseSoftExpiredCachedLogo) { - SetServerResponse("", net::URLRequestStatus::FAILED, net::HTTP_OK); + SetServerResponse("", net::ERR_FAILED, net::HTTP_OK); Logo cached_logo = GetSampleLogo(DoodleURL(), test_clock_.Now()); cached_logo.metadata.expiration_time = test_clock_.Now() - base::TimeDelta::FromSeconds(1); @@ -862,7 +859,7 @@ TEST_F(LogoServiceImplTest, RerequestSoftExpiredCachedLogo) { } TEST_F(LogoServiceImplTest, DeleteAncientCachedLogo) { - SetServerResponse("", net::URLRequestStatus::FAILED, net::HTTP_OK); + SetServerResponse("", net::ERR_FAILED, net::HTTP_OK); Logo cached_logo = GetSampleLogo(DoodleURL(), test_clock_.Now()); cached_logo.metadata.expiration_time = test_clock_.Now() - base::TimeDelta::FromDays(200); @@ -883,7 +880,7 @@ TEST_F(LogoServiceImplTest, DeleteAncientCachedLogo) { } TEST_F(LogoServiceImplTest, DeleteExpiredCachedLogo) { - SetServerResponse("", net::URLRequestStatus::FAILED, net::HTTP_OK); + SetServerResponse("", net::ERR_FAILED, net::HTTP_OK); Logo cached_logo = GetSampleLogo(DoodleURL(), test_clock_.Now()); cached_logo.metadata.expiration_time = test_clock_.Now() - base::TimeDelta::FromSeconds(1); diff --git a/chromium/components/search_provider_logos/logo_tracker.cc b/chromium/components/search_provider_logos/logo_tracker.cc index 4c48e4f3fe3..f8e50cd9cb6 100644 --- a/chromium/components/search_provider_logos/logo_tracker.cc +++ b/chromium/components/search_provider_logos/logo_tracker.cc @@ -17,9 +17,9 @@ #include "net/http/http_response_headers.h" #include "net/http/http_status_code.h" #include "net/traffic_annotation/network_traffic_annotation.h" -#include "net/url_request/url_fetcher.h" -#include "net/url_request/url_request_context_getter.h" -#include "net/url_request/url_request_status.h" +#include "services/network/public/cpp/resource_request.h" +#include "services/network/public/cpp/shared_url_loader_factory.h" +#include "services/network/public/cpp/simple_url_loader.h" namespace search_provider_logos { @@ -81,7 +81,7 @@ void NotifyAndClear(std::vector<EncodedLogoCallback>* encoded_callbacks, } // namespace LogoTracker::LogoTracker( - scoped_refptr<net::URLRequestContextGetter> request_context_getter, + scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory, std::unique_ptr<LogoDelegate> delegate, std::unique_ptr<LogoCache> logo_cache, base::Clock* clock) @@ -94,7 +94,7 @@ LogoTracker::LogoTracker( logo_cache_(logo_cache.release(), base::OnTaskRunnerDeleter(cache_task_runner_)), clock_(clock), - request_context_getter_(request_context_getter), + url_loader_factory_(std::move(url_loader_factory)), weak_ptr_factory_(this) {} LogoTracker::~LogoTracker() { @@ -169,7 +169,7 @@ void LogoTracker::ReturnToIdle(int outcome) { DOWNLOAD_OUTCOME_COUNT); } // Cancel the current asynchronous operation, if any. - fetcher_.reset(); + loader_.reset(); weak_ptr_factory_.InvalidateWeakPtrs(); // Reset state. @@ -235,7 +235,7 @@ void LogoTracker::SetCachedMetadata(const LogoMetadata& metadata) { } void LogoTracker::FetchLogo() { - DCHECK(!fetcher_); + DCHECK(!loader_); DCHECK(!is_idle_); std::string fingerprint; @@ -268,13 +268,18 @@ void LogoTracker::FetchLogo() { "Not implemented, considered not useful as it does not upload any" "data and just downloads a logo image." })"); - fetcher_ = net::URLFetcher::Create(url, net::URLFetcher::GET, this, - traffic_annotation); - fetcher_->SetRequestContext(request_context_getter_.get()); - data_use_measurement::DataUseUserData::AttachToFetcher( - fetcher_.get(), - data_use_measurement::DataUseUserData::SEARCH_PROVIDER_LOGOS); - fetcher_->Start(); + auto request = std::make_unique<network::ResourceRequest>(); + request->url = url; + // TODO(https://crbug.com/808498) re-add data use measurement once + // SimpleURLLoader supports it: + // data_use_measurement::DataUseUserData::SEARCH_PROVIDER_LOGOS + loader_ = + network::SimpleURLLoader::Create(std::move(request), traffic_annotation); + loader_->DownloadToString( + url_loader_factory_.get(), + base::BindOnce(&LogoTracker::OnURLLoadComplete, base::Unretained(this), + loader_.get()), + kMaxDownloadBytes); logo_download_start_time_ = base::TimeTicks::Now(); } @@ -414,21 +419,19 @@ void LogoTracker::OnFreshLogoAvailable( ReturnToIdle(download_outcome); } -void LogoTracker::OnURLFetchComplete(const net::URLFetcher* source) { +void LogoTracker::OnURLLoadComplete(const network::SimpleURLLoader* source, + std::unique_ptr<std::string> body) { DCHECK(!is_idle_); - std::unique_ptr<net::URLFetcher> cleanup_fetcher(fetcher_.release()); + std::unique_ptr<network::SimpleURLLoader> cleanup_loader(loader_.release()); - if (!source->GetStatus().is_success()) { + if (source->NetError() != net::OK) { OnFreshLogoAvailable({}, /*download_failed=*/true, false, false, SkBitmap()); return; } - int response_code = source->GetResponseCode(); - if (response_code != net::HTTP_OK && - response_code != net::URLFetcher::RESPONSE_CODE_INVALID) { - // RESPONSE_CODE_INVALID is returned when fetching from a file: URL - // (for testing). In all other cases we would have had a non-success status. + if (!source->ResponseInfo() || !source->ResponseInfo()->headers || + source->ResponseInfo()->headers->response_code() != net::HTTP_OK) { OnFreshLogoAvailable({}, /*download_failed=*/true, false, false, SkBitmap()); return; @@ -437,11 +440,11 @@ void LogoTracker::OnURLFetchComplete(const net::URLFetcher* source) { UMA_HISTOGRAM_TIMES("NewTabPage.LogoDownloadTime", base::TimeTicks::Now() - logo_download_start_time_); - std::unique_ptr<std::string> response(new std::string()); - source->GetResponseAsString(response.get()); + std::unique_ptr<std::string> response = + body ? std::move(body) : std::make_unique<std::string>(); base::Time response_time = clock_->Now(); - bool from_http_cache = source->WasCached(); + bool from_http_cache = !source->ResponseInfo()->network_accessed; bool* parsing_failed = new bool(false); base::PostTaskWithTraitsAndReplyWithResult( @@ -455,15 +458,4 @@ void LogoTracker::OnURLFetchComplete(const net::URLFetcher* source) { base::Owned(parsing_failed), from_http_cache)); } -void LogoTracker::OnURLFetchDownloadProgress(const net::URLFetcher* source, - int64_t current, - int64_t total, - int64_t current_network_bytes) { - if (total > kMaxDownloadBytes || current > kMaxDownloadBytes) { - LOG(WARNING) << "Search provider logo exceeded download size limit"; - OnFreshLogoAvailable({}, /*download_failed=*/true, false, false, - SkBitmap()); - } -} - } // namespace search_provider_logos diff --git a/chromium/components/search_provider_logos/logo_tracker.h b/chromium/components/search_provider_logos/logo_tracker.h index 8c3191beb7b..7951bcfd1a9 100644 --- a/chromium/components/search_provider_logos/logo_tracker.h +++ b/chromium/components/search_provider_logos/logo_tracker.h @@ -21,12 +21,11 @@ #include "base/time/time.h" #include "components/search_provider_logos/logo_cache.h" #include "components/search_provider_logos/logo_common.h" -#include "net/url_request/url_fetcher_delegate.h" #include "url/gurl.h" -namespace net { -class URLFetcher; -class URLRequestContextGetter; +namespace network { +class SimpleURLLoader; +class SharedURLLoaderFactory; } namespace search_provider_logos { @@ -73,7 +72,7 @@ class LogoDelegate { // Call SetServerAPI() at least once to specify how to get the logo from the // server. Then call GetLogo() to trigger retrieval of the logo and receive // updates once the cached and/or fresh logos are available. -class LogoTracker : public net::URLFetcherDelegate { +class LogoTracker { public: // Constructs a LogoTracker with the given LogoDelegate. Takes ownership of // |delegate|, which will be deleted at the same time as the LogoTracker. @@ -84,15 +83,15 @@ class LogoTracker : public net::URLFetcherDelegate { // |background_task_runner| is the TaskRunner that should be used to for // CPU-intensive background operations. // - // |request_context_getter| is the URLRequestContextGetter used to download + // |url_loader_factory| is the SharedURLLoaderFactory used to download // the logo. explicit LogoTracker( - scoped_refptr<net::URLRequestContextGetter> request_context_getter, + scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory, std::unique_ptr<LogoDelegate> delegate, std::unique_ptr<LogoCache> logo_cache, base::Clock* clock); - ~LogoTracker() override; + ~LogoTracker(); // Defines the server API for downloading and parsing the logo. This must be // called at least once before calling GetLogo(). @@ -173,12 +172,9 @@ class LogoTracker : public net::URLFetcherDelegate { bool from_http_cache, const SkBitmap& image); - // net::URLFetcherDelegate: - void OnURLFetchComplete(const net::URLFetcher* source) override; - void OnURLFetchDownloadProgress(const net::URLFetcher* source, - int64_t current, - int64_t total, - int64_t current_network_bytes) override; + // Invoked by |loader|. + void OnURLLoadComplete(const network::SimpleURLLoader* source, + std::unique_ptr<std::string> body); // The URL from which the logo is fetched. GURL logo_url_; @@ -207,8 +203,8 @@ class LogoTracker : public net::URLFetcherDelegate { // The timestamp for the last time a logo is stated to be downloaded. base::TimeTicks logo_download_start_time_; - // The URLFetcher currently fetching the logo. NULL when not fetching. - std::unique_ptr<net::URLFetcher> fetcher_; + // The SimpleURLLoader currently fetching the logo. NULL when not loading. + std::unique_ptr<network::SimpleURLLoader> loader_; // Lists of callbacks to be invoked when logos are available. All should be // empty when the state is IDLE. @@ -229,8 +225,8 @@ class LogoTracker : public net::URLFetcherDelegate { // Clock used to determine current time. Can be overridden in tests. base::Clock* clock_; - // The URLRequestContextGetter used for network requests. - scoped_refptr<net::URLRequestContextGetter> request_context_getter_; + // Used for network requests. + scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_; base::WeakPtrFactory<LogoTracker> weak_ptr_factory_; |