| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_UI_WEBUI_FILEICON_SOURCE_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_FILEICON_SOURCE_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_FILEICON_SOURCE_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_FILEICON_SOURCE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "chrome/browser/icon_manager.h" | 11 #include "chrome/browser/icon_manager.h" |
| 12 #include "chrome/common/cancelable_task_tracker.h" | 12 #include "chrome/common/cancelable_task_tracker.h" |
| 13 #include "content/public/browser/url_data_source_delegate.h" | 13 #include "content/public/browser/url_data_source.h" |
| 14 #include "ui/base/layout.h" | 14 #include "ui/base/layout.h" |
| 15 | 15 |
| 16 namespace gfx { | 16 namespace gfx { |
| 17 class Image; | 17 class Image; |
| 18 } | 18 } |
| 19 | 19 |
| 20 // FileIconSource is the gateway between network-level chrome: | 20 // FileIconSource is the gateway between network-level chrome: |
| 21 // requests for favicons and the history backend that serves these. | 21 // requests for favicons and the history backend that serves these. |
| 22 class FileIconSource : public content::URLDataSourceDelegate { | 22 class FileIconSource : public content::URLDataSource { |
| 23 public: | 23 public: |
| 24 explicit FileIconSource(); | 24 explicit FileIconSource(); |
| 25 | 25 |
| 26 // content::URLDataSourceDelegate implementation. | 26 // content::URLDataSource implementation. |
| 27 virtual std::string GetSource() OVERRIDE; | 27 virtual std::string GetSource() OVERRIDE; |
| 28 virtual void StartDataRequest(const std::string& path, | 28 virtual void StartDataRequest( |
| 29 bool is_incognito, | 29 const std::string& path, |
| 30 int request_id) OVERRIDE; | 30 bool is_incognito, |
| 31 const content::URLDataSource::GotDataCallback& callback) OVERRIDE; |
| 31 virtual std::string GetMimeType(const std::string&) const OVERRIDE; | 32 virtual std::string GetMimeType(const std::string&) const OVERRIDE; |
| 32 | 33 |
| 33 protected: | 34 protected: |
| 34 virtual ~FileIconSource(); | 35 virtual ~FileIconSource(); |
| 35 | 36 |
| 36 // Once the |path| and |icon_size| has been determined from the request, this | 37 // Once the |path| and |icon_size| has been determined from the request, this |
| 37 // function is called to perform the actual fetch. Declared as virtual for | 38 // function is called to perform the actual fetch. Declared as virtual for |
| 38 // testing. | 39 // testing. |
| 39 virtual void FetchFileIcon(const FilePath& path, | 40 virtual void FetchFileIcon( |
| 40 ui::ScaleFactor scale_factor, | 41 const FilePath& path, |
| 41 IconLoader::IconSize icon_size, | 42 ui::ScaleFactor scale_factor, |
| 42 int request_id); | 43 IconLoader::IconSize icon_size, |
| 44 const content::URLDataSource::GotDataCallback& callback); |
| 43 | 45 |
| 44 private: | 46 private: |
| 45 // Contains the necessary information for completing an icon fetch request. | 47 // Contains the necessary information for completing an icon fetch request. |
| 46 struct IconRequestDetails { | 48 struct IconRequestDetails { |
| 47 // The request id corresponding to these details. | 49 IconRequestDetails(); |
| 48 int request_id; | 50 ~IconRequestDetails(); |
| 51 |
| 52 // The callback to run with the response. |
| 53 content::URLDataSource::GotDataCallback callback; |
| 49 | 54 |
| 50 // The requested scale factor to respond with. | 55 // The requested scale factor to respond with. |
| 51 ui::ScaleFactor scale_factor; | 56 ui::ScaleFactor scale_factor; |
| 52 }; | 57 }; |
| 53 | 58 |
| 54 // Called when favicon data is available from the history backend. | 59 // Called when favicon data is available from the history backend. |
| 55 void OnFileIconDataAvailable(const IconRequestDetails& details, | 60 void OnFileIconDataAvailable(const IconRequestDetails& details, |
| 56 gfx::Image* icon); | 61 gfx::Image* icon); |
| 57 | 62 |
| 58 // Tracks tasks requesting file icons. | 63 // Tracks tasks requesting file icons. |
| 59 CancelableTaskTracker cancelable_task_tracker_; | 64 CancelableTaskTracker cancelable_task_tracker_; |
| 60 | 65 |
| 61 DISALLOW_COPY_AND_ASSIGN(FileIconSource); | 66 DISALLOW_COPY_AND_ASSIGN(FileIconSource); |
| 62 }; | 67 }; |
| 63 #endif // CHROME_BROWSER_UI_WEBUI_FILEICON_SOURCE_H_ | 68 #endif // CHROME_BROWSER_UI_WEBUI_FILEICON_SOURCE_H_ |
| OLD | NEW |