Chromium Code Reviews

Unified Diff: components/search_provider_logos/animated_logo_tracker.cc

Issue 1343913002: Introduce Animated Logo to Chrome on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Index: components/search_provider_logos/animated_logo_tracker.cc
diff --git a/components/search_provider_logos/animated_logo_tracker.cc b/components/search_provider_logos/animated_logo_tracker.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5ca77222d2e6e7f62ab55336777e6ff8b77e3f04
--- /dev/null
+++ b/components/search_provider_logos/animated_logo_tracker.cc
@@ -0,0 +1,46 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/search_provider_logos/animated_logo_tracker.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"
+
+namespace search_provider_logos {
+
+AnimatedLogoTracker::AnimatedLogoTracker(
+ scoped_refptr<net::URLRequestContextGetter> request_context_getter)
+ : request_context_getter_(request_context_getter) {}
+
+AnimatedLogoTracker::~AnimatedLogoTracker() {
+ ReturnToIdle();
+}
+
+void AnimatedLogoTracker::GetAnimatedLogo(const GURL& animated_logo_url,
+ AnimatedLogoCallback listener) {
+ DCHECK(!animated_logo_url.is_empty());
+ animated_logo_callback_ = listener;
+ fetcher_ =
newt (away) 2015/09/18 20:46:03 resetting fetcher_ will abort any currently in-pro
+ net::URLFetcher::Create(animated_logo_url, net::URLFetcher::GET, this);
+ fetcher_->SetRequestContext(request_context_getter_.get());
+ fetcher_->Start();
+}
+
+void AnimatedLogoTracker::ReturnToIdle() {
+ fetcher_.reset();
+ animated_logo_callback_.Reset();
+}
+
+void AnimatedLogoTracker::OnURLFetchComplete(const net::URLFetcher* source) {
+ if (!source->GetStatus().is_success() || (source->GetResponseCode() != 200)) {
+ ReturnToIdle();
+ return;
+ }
+ std::string raw_response;
+ source->GetResponseAsString(&raw_response);
+ animated_logo_callback_.Run(raw_response);
+ ReturnToIdle();
+}
+
+} // namespace search_provider_logos

Powered by Google App Engine