Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / webui / large_icon_source.h
blobfb573ea45f6d63a76843bc80e10925dacf663775
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.
5 #ifndef CHROME_BROWSER_UI_WEBUI_LARGE_ICON_SOURCE_H_
6 #define CHROME_BROWSER_UI_WEBUI_LARGE_ICON_SOURCE_H_
8 #include <string>
10 #include "base/memory/scoped_ptr.h"
11 #include "base/task/cancelable_task_tracker.h"
12 #include "components/favicon/core/fallback_icon_service.h"
13 #include "content/public/browser/url_data_source.h"
15 namespace favicon {
16 class FallbackIconService;
17 class LargeIconService;
20 namespace favicon_base {
21 struct LargeIconResult;
24 // LargeIconSource services explicit chrome:// requests for large icons.
26 // Format:
27 // chrome://large-icon/size/url
29 // Parameter:
30 // 'size' Required (including trailing '/')
31 // Positive integer to specify the large icon's size in pixels.
32 // 'url' Optional
33 // String to specify the page URL of the large icon.
35 // Example: chrome://large-icon/48/http://www.google.com/
36 // This requests a 48x48 large icon for http://www.google.com.
37 class LargeIconSource : public content::URLDataSource {
38 public:
39 // |fallback_icon_service| and |large_icon_service| are owned by caller and
40 // may be null.
41 LargeIconSource(favicon::FallbackIconService* fallback_icon_service,
42 favicon::LargeIconService* large_icon_service);
44 ~LargeIconSource() override;
46 // content::URLDataSource implementation.
47 std::string GetSource() const override;
48 void StartDataRequest(
49 const std::string& path,
50 int render_process_id,
51 int render_frame_id,
52 const content::URLDataSource::GotDataCallback& callback) override;
53 std::string GetMimeType(const std::string&) const override;
54 bool ShouldReplaceExistingSource() const override;
55 bool ShouldServiceRequest(const net::URLRequest* request) const override;
57 private:
58 // Called with results of large icon retrieval request.
59 void OnLargeIconDataAvailable(
60 const content::URLDataSource::GotDataCallback& callback,
61 const GURL& url,
62 int size,
63 const favicon_base::LargeIconResult& bitmap_result);
65 // Returns null to trigger "Not Found" response.
66 void SendNotFoundResponse(
67 const content::URLDataSource::GotDataCallback& callback);
69 base::CancelableTaskTracker cancelable_task_tracker_;
71 // Owned by client.
72 favicon::FallbackIconService* fallback_icon_service_;
74 // Owned by client.
75 favicon::LargeIconService* large_icon_service_;
77 DISALLOW_COPY_AND_ASSIGN(LargeIconSource);
80 #endif // CHROME_BROWSER_UI_WEBUI_LARGE_ICON_SOURCE_H_