1 // Copyright (c) 2012 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_FILEICON_SOURCE_H_
6 #define CHROME_BROWSER_UI_WEBUI_FILEICON_SOURCE_H_
10 #include "base/files/file_path.h"
11 #include "base/task/cancelable_task_tracker.h"
12 #include "chrome/browser/icon_manager.h"
13 #include "content/public/browser/url_data_source.h"
19 // FileIconSource is the gateway between network-level chrome:
20 // requests for favicons and the history backend that serves these.
21 class FileIconSource
: public content::URLDataSource
{
23 explicit FileIconSource();
25 // content::URLDataSource implementation.
26 std::string
GetSource() const override
;
27 void StartDataRequest(
28 const std::string
& path
,
29 int render_process_id
,
31 const content::URLDataSource::GotDataCallback
& callback
) override
;
32 std::string
GetMimeType(const std::string
&) const override
;
35 ~FileIconSource() override
;
37 // Once the |path| and |icon_size| has been determined from the request, this
38 // function is called to perform the actual fetch. Declared as virtual for
40 virtual void FetchFileIcon(
41 const base::FilePath
& path
,
43 IconLoader::IconSize icon_size
,
44 const content::URLDataSource::GotDataCallback
& callback
);
47 // Contains the necessary information for completing an icon fetch request.
48 struct IconRequestDetails
{
50 ~IconRequestDetails();
52 // The callback to run with the response.
53 content::URLDataSource::GotDataCallback callback
;
55 // The requested scale factor to respond with.
59 // Called when favicon data is available from the history backend.
60 void OnFileIconDataAvailable(const IconRequestDetails
& details
,
63 // Tracks tasks requesting file icons.
64 base::CancelableTaskTracker cancelable_task_tracker_
;
66 DISALLOW_COPY_AND_ASSIGN(FileIconSource
);
68 #endif // CHROME_BROWSER_UI_WEBUI_FILEICON_SOURCE_H_