Home | History | Annotate | Download | only in webui
      1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_UI_WEBUI_FAVICON_SOURCE_H_
      6 #define CHROME_BROWSER_UI_WEBUI_FAVICON_SOURCE_H_
      7 #pragma once
      8 
      9 #include <string>
     10 
     11 #include "base/basictypes.h"
     12 #include "base/memory/ref_counted.h"
     13 #include "chrome/browser/favicon_service.h"
     14 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
     15 
     16 class GURL;
     17 class Profile;
     18 
     19 // FaviconSource is the gateway between network-level chrome:
     20 // requests for favicons and the history backend that serves these.
     21 class FaviconSource : public ChromeURLDataManager::DataSource {
     22  public:
     23   explicit FaviconSource(Profile* profile);
     24 
     25   // Called when the network layer has requested a resource underneath
     26   // the path we registered.
     27   virtual void StartDataRequest(const std::string& path,
     28                                 bool is_incognito,
     29                                 int request_id);
     30 
     31   virtual std::string GetMimeType(const std::string&) const;
     32 
     33   virtual bool ShouldReplaceExistingSource() const;
     34 
     35  private:
     36   // Called when favicon data is available from the history backend.
     37   void OnFaviconDataAvailable(FaviconService::Handle request_handle,
     38                               history::FaviconData favicon);
     39 
     40   // Sends the default favicon.
     41   void SendDefaultResponse(int request_id);
     42 
     43   virtual ~FaviconSource();
     44 
     45   Profile* profile_;
     46   CancelableRequestConsumerT<int, 0> cancelable_consumer_;
     47 
     48   // Raw PNG representation of the favicon to show when the favicon
     49   // database doesn't have a favicon for a webpage.
     50   scoped_refptr<RefCountedMemory> default_favicon_;
     51 
     52   DISALLOW_COPY_AND_ASSIGN(FaviconSource);
     53 };
     54 
     55 #endif  // CHROME_BROWSER_UI_WEBUI_FAVICON_SOURCE_H_
     56