15c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// Copyright 2014 The Chromium Authors. All rights reserved. 25c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// Use of this source code is governed by a BSD-style license that can be 35c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// found in the LICENSE file. 45c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 55c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#ifndef COMPONENTS_SEARCH_PROVIDER_LOGOS_LOGO_TRACKER_H_ 65c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#define COMPONENTS_SEARCH_PROVIDER_LOGOS_LOGO_TRACKER_H_ 75c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 85c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include <string> 95c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include <vector> 105c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 115c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "base/callback.h" 125c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "base/files/file_path.h" 135c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "base/memory/scoped_ptr.h" 145c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "base/memory/weak_ptr.h" 155c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "base/observer_list.h" 165c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "base/sequenced_task_runner.h" 175c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "base/time/clock.h" 185c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "base/time/time.h" 195c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "components/search_provider_logos/logo_cache.h" 205c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "components/search_provider_logos/logo_common.h" 215c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "net/url_request/url_fetcher_delegate.h" 225c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "url/gurl.h" 235c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 245c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liunamespace net { 255c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liuclass URLFetcher; 265c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liuclass URLRequestContextGetter; 275c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu} 285c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 295c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liunamespace search_provider_logos { 305c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 315c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// Receives updates when the search provider's logo is available. 325c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liuclass LogoObserver { 335c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu public: 345c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu virtual ~LogoObserver() {} 355c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 365c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Called when the cached logo is available and possibly when a freshly 375c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // downloaded logo is available. |logo| will be NULL if no logo is available. 385c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // |from_cache| indicates whether the logo was loaded from the cache. 395c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // 405c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // If the fresh logo is the same as the cached logo, this will not be called 415c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // again. 425c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu virtual void OnLogoAvailable(const Logo* logo, bool from_cache) = 0; 435c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 445c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Called when the LogoTracker will no longer send updates to this 455c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // LogoObserver. For example: after the cached logo is validated, after 465c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // OnFreshLogoAvailable() is called, or when the LogoTracker is destructed. 475c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // This is not called when an observer is removed using 485c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // LogoTracker::RemoveObserver(). 495c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu virtual void OnObserverRemoved() = 0; 505c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu}; 515c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 525c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// Provides a LogoTracker with methods it needs to download and cache logos. 535c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liuclass LogoDelegate { 545c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu public: 555c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu virtual ~LogoDelegate() {} 565c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 575c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Decodes an untrusted image safely and returns it as an SkBitmap via 585c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // |image_decoded_callback|. If image decoding fails, |image_decoded_callback| 595c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // should be called with NULL. This will be called on the thread that 605c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // LogoTracker lives on and |image_decoded_callback| must be called on the 615c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // same thread. 625c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu virtual void DecodeUntrustedImage( 635c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu const scoped_refptr<base::RefCountedString>& encoded_image, 645c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu base::Callback<void(const SkBitmap&)> image_decoded_callback) = 0; 655c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu}; 665c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 675c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// Parses the response from the server and returns it as an EncodedLogo. Returns 685c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// NULL if the response is invalid. 695c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liutypedef base::Callback< 705c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu scoped_ptr<EncodedLogo>(const scoped_ptr<std::string>& response, 715c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu base::Time response_time)> ParseLogoResponse; 725c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 735c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// Encodes the fingerprint of the cached logo in the logo URL. This enables the 745c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// server to verify whether the cached logo is up-to-date. 755c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liutypedef base::Callback< 765c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu GURL(const GURL& logo_url, const std::string& fingerprint)> 775c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu AppendFingerprintToLogoURL; 785c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 795c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// This class provides the logo for a search provider. Logos are downloaded from 805c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// the search provider's logo URL and cached on disk. 815c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// 825c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// Call SetServerAPI() at least once to specify how to get the logo from the 835c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// server. Then call GetLogo() to trigger retrieval of the logo and receive 845c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// updates once the cached and/or fresh logos are available. 855c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liuclass LogoTracker : public net::URLFetcherDelegate { 865c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu public: 875c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Constructs a LogoTracker with the given LogoDelegate. Takes ownership of 885c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // |delegate|, which will be deleted at the same time as the LogoTracker. 895c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // 905c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // |cached_logo_directory| is the directory in which the cached logo and its 915c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // metadata should be saved. 925c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // 935c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // |file_task_runner| is the SequencedTaskRunner that should be used to run 945c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // file system operations. 955c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // 965c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // |background_task_runner| is the TaskRunner that should be used to for 975c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // CPU-intensive background operations. 985c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // 995c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // |request_context_getter| is the URLRequestContextGetter used to download 1005c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // the logo. 1015c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu explicit LogoTracker( 1025c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu base::FilePath cached_logo_directory, 1035c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu scoped_refptr<base::SequencedTaskRunner> file_task_runner, 1045c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu scoped_refptr<base::TaskRunner> background_task_runner, 1055c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu scoped_refptr<net::URLRequestContextGetter> request_context_getter, 1065c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu scoped_ptr<LogoDelegate> delegate); 1075c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 1085c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu virtual ~LogoTracker(); 1095c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 1105c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Defines the server API for downloading and parsing the logo. This must be 1115c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // called at least once before calling GetLogo(). 1125c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // 1135c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // |logo_url| is the URL from which the logo will be downloaded. If |logo_url| 1145c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // is different than the current logo URL, any pending LogoObservers will be 1155c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // canceled. 1165c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // 1175c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // |parse_logo_response_func| is a callback that will be used to parse the 1185c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // server's response into a EncodedLogo object. |append_fingerprint_func| is a 1195c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // callback that will return the URL from which to download the logo if a 1205c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // cached logo with a fingerprint is already available. Note: 1215c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // |parse_logo_response_func| and |append_fingerprint_func| must be suitable 1225c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // for running multiple times, concurrently, and on multiple threads. 1235c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu void SetServerAPI(const GURL& logo_url, 1245c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu const ParseLogoResponse& parse_logo_response_func, 1255c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu const AppendFingerprintToLogoURL& append_fingerprint_func); 1265c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 1275c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Retrieves the current search provider's logo from the local cache and/or 1285c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // over the network, and registers |observer| to be called when the cached 1295c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // and/or fresh logos are available. 1305c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu void GetLogo(LogoObserver* observer); 1315c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 1325c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Prevents |observer| from receiving future updates. This is safe to call 1335c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // even when the observer is being notified of an update. 1345c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu void RemoveObserver(LogoObserver* observer); 1355c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 1365c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Overrides the cache used to store logos. 1375c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu void SetLogoCacheForTests(scoped_ptr<LogoCache> cache); 1385c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 1395c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Overrides the clock used to check the time. 1405c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu void SetClockForTests(scoped_ptr<base::Clock> clock); 1415c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 1425c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu private: 1435c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Cancels the current asynchronous operation, if any, and resets all member 1445c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // variables that change as the logo is fetched. 1455c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu void ReturnToIdle(); 1465c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 1475c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Called when the cached logo has been read from the cache. |cached_logo| 1485c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // will be NULL if there wasn't a valid, up-to-date logo in the cache. 1495c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu void OnCachedLogoRead(scoped_ptr<EncodedLogo> cached_logo); 1505c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 1515c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Called when the cached logo has been decoded into an SkBitmap. |image| will 1525c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // be NULL if decoding failed. 1535c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu void OnCachedLogoAvailable(const LogoMetadata& metadata, 1545c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu const SkBitmap& image); 1555c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 1565c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Stores |logo| in the cache. 1575c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu void SetCachedLogo(scoped_ptr<EncodedLogo> logo); 1585c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 1595c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Updates the metadata for the logo already stored in the cache. 1605c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu void SetCachedMetadata(const LogoMetadata& metadata); 1615c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 1625c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Starts fetching the current logo over the network. 1635c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu void FetchLogo(); 1645c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 1655c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Called when the logo has been downloaded and parsed. |logo| will be NULL 1665c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // if the server's response was invalid. 1675c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu void OnFreshLogoParsed(scoped_ptr<EncodedLogo> logo); 1685c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 1695c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Called when the fresh logo has been decoded into an SkBitmap. |image| will 1705c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // be NULL if decoding failed. 1715c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu void OnFreshLogoAvailable(scoped_ptr<EncodedLogo> logo, 1725c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu const SkBitmap& image); 1735c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 1745c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // net::URLFetcherDelegate: 1755c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; 1765c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu virtual void OnURLFetchDownloadProgress(const net::URLFetcher* source, 1775c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu int64 current, 1785c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu int64 total) OVERRIDE; 1795c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 1805c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // The URL from which the logo is fetched. 1815c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu GURL logo_url_; 1825c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 1835c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // The function used to parse the logo response from the server. 1845c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu ParseLogoResponse parse_logo_response_func_; 1855c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 1865c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // The function used to include the cached logo's fingerprint in the logo URL. 1875c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu AppendFingerprintToLogoURL append_fingerprint_func_; 1885c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 1895c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // False if an asynchronous task is currently running. 1905c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu bool is_idle_; 1915c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 1925c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // The logo that's been read from the cache, or NULL if the cache is empty. 1935c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Meaningful only if is_cached_logo_valid_ is true; NULL otherwise. 1945c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu scoped_ptr<Logo> cached_logo_; 1955c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 1965c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Whether the value of |cached_logo_| reflects the actual cached logo. 1975c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // This will be false if the logo hasn't been read from the cache yet. 1985c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // |cached_logo_| may be NULL even if |is_cached_logo_valid_| is true, if no 1995c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // logo is cached. 2005c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu bool is_cached_logo_valid_; 2015c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 2025c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // The URLFetcher currently fetching the logo. NULL when not fetching. 2035c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu scoped_ptr<net::URLFetcher> fetcher_; 2045c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 2055c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // The list of observers to be notified when the logo is available. This 2065c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // should be empty when the state is IDLE. 2075c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu ObserverList<LogoObserver> logo_observers_; 2085c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 2095c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu scoped_ptr<LogoDelegate> logo_delegate_; 2105c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 2115c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // The cache used to persist the logo on disk. Used only on the file thread. 2125c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu LogoCache* logo_cache_; 2135c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 2145c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Clock used to determine current time. Can be overridden in tests. 2155c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu scoped_ptr<base::Clock> clock_; 2165c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 2175c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // The SequencedTaskRunner on which file system operations will be run. 2185c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu scoped_refptr<base::SequencedTaskRunner> file_task_runner_; 2195c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 2205c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // The TaskRunner on which the server's response will be parsed. 2215c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu scoped_refptr<base::TaskRunner> background_task_runner_; 2225c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 2235c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // The URLRequestContextGetter used for network requests. 2245c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu scoped_refptr<net::URLRequestContextGetter> request_context_getter_; 2255c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 2265c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu base::WeakPtrFactory<LogoTracker> weak_ptr_factory_; 2275c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 2285c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu DISALLOW_COPY_AND_ASSIGN(LogoTracker); 2295c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu}; 2305c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 2315c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu} // namespace search_provider_logos 2325c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 2335c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#endif // COMPONENTS_SEARCH_PROVIDER_LOGOS_LOGO_TRACKER_H_ 234