OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/search_provider_logos/animated_logo_tracker.h" |
| 6 #include "net/url_request/url_fetcher.h" |
| 7 #include "net/url_request/url_request_context_getter.h" |
| 8 #include "net/url_request/url_request_status.h" |
| 9 |
| 10 namespace search_provider_logos { |
| 11 |
| 12 AnimatedLogoTracker::AnimatedLogoTracker( |
| 13 scoped_refptr<net::URLRequestContextGetter> request_context_getter) |
| 14 : request_context_getter_(request_context_getter) {} |
| 15 |
| 16 AnimatedLogoTracker::~AnimatedLogoTracker() { |
| 17 ReturnToIdle(); |
| 18 } |
| 19 |
| 20 void AnimatedLogoTracker::GetAnimatedLogo(const GURL& animated_logo_url, |
| 21 AnimatedLogoCallback listener) { |
| 22 DCHECK(!animated_logo_url.is_empty()); |
| 23 animated_logo_callback_ = listener; |
| 24 fetcher_ = |
| 25 net::URLFetcher::Create(animated_logo_url, net::URLFetcher::GET, this); |
| 26 fetcher_->SetRequestContext(request_context_getter_.get()); |
| 27 fetcher_->Start(); |
| 28 } |
| 29 |
| 30 void AnimatedLogoTracker::ReturnToIdle() { |
| 31 fetcher_.reset(); |
| 32 animated_logo_callback_.Reset(); |
| 33 } |
| 34 |
| 35 void AnimatedLogoTracker::OnURLFetchComplete(const net::URLFetcher* source) { |
| 36 if (!source->GetStatus().is_success() || (source->GetResponseCode() != 200)) { |
| 37 ReturnToIdle(); |
| 38 return; |
| 39 } |
| 40 std::string raw_response; |
| 41 source->GetResponseAsString(&raw_response); |
| 42 animated_logo_callback_.Run(raw_response); |
| 43 ReturnToIdle(); |
| 44 } |
| 45 |
| 46 } // namespace search_provider_logos |
OLD | NEW |