Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / webui / large_icon_source.h
blob7557cfd87d844d913b83baa2750d9a8dde147ee9
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 "components/favicon_base/favicon_types.h"
14 #include "content/public/browser/url_data_source.h"
16 namespace favicon {
17 class FallbackIconService;
18 class FaviconService;
21 // LargeIconSource services explicit chrome:// requests for large icons.
23 // Format:
24 // chrome://large-icon/size/url
26 // Parameter:
27 // 'size' Required (including trailing '/')
28 // Positive integer to specify the large icon's size in pixels.
29 // 'url' Optional
30 // String to specify the page URL of the large icon.
32 // Example: chrome://large-icon/48/http://www.google.com/
33 // This requests a 48x48 large icon for http://www.google.com.
34 class LargeIconSource : public content::URLDataSource {
35 public:
36 // |favicon_service| and |fallback_icon_service| are owned by caller and may
37 // be null.
38 LargeIconSource(favicon::FaviconService* favicon_service,
39 favicon::FallbackIconService* fallback_icon_service);
41 ~LargeIconSource() override;
43 // content::URLDataSource implementation.
44 std::string GetSource() const override;
45 void StartDataRequest(
46 const std::string& path,
47 int render_process_id,
48 int render_frame_id,
49 const content::URLDataSource::GotDataCallback& callback) override;
50 std::string GetMimeType(const std::string&) const override;
51 bool ShouldReplaceExistingSource() const override;
52 bool ShouldServiceRequest(const net::URLRequest* request) const override;
54 protected:
55 struct IconRequest {
56 IconRequest();
57 IconRequest(const content::URLDataSource::GotDataCallback& callback_in,
58 const GURL& path_in,
59 int size_in);
60 ~IconRequest();
62 content::URLDataSource::GotDataCallback callback;
63 GURL url;
64 int size;
67 private:
68 // Callback for icon data retrieval request.
69 void OnIconDataAvailable(
70 const IconRequest& request,
71 const favicon_base::FaviconRawBitmapResult& bitmap_result);
73 // Renders and sends a fallback icon.
74 void SendFallbackIcon(const IconRequest& request);
76 // Returns null to trigger "Not Found" response.
77 void SendNotFoundResponse(
78 const content::URLDataSource::GotDataCallback& callback);
80 base::CancelableTaskTracker cancelable_task_tracker_;
82 favicon::FaviconService* favicon_service_;
84 favicon::FallbackIconService* fallback_icon_service_;
86 DISALLOW_COPY_AND_ASSIGN(LargeIconSource);
89 #endif // CHROME_BROWSER_UI_WEBUI_LARGE_ICON_SOURCE_H_