OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 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 CONTENT_PUBLIC_BROWSER_URL_DATA_SOURCE_DELEGATE_H_ |
| 6 #define CONTENT_PUBLIC_BROWSER_URL_DATA_SOURCE_DELEGATE_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "content/common/content_export.h" |
| 11 |
| 12 class ChromeURLDataManager; |
| 13 class ChromeURLDataManagerBackend; |
| 14 class ChromeWebUIDataSource; |
| 15 class MessageLoop; |
| 16 class URLDataSource; |
| 17 |
| 18 namespace content { |
| 19 |
| 20 // An interface implemented by a creator of URLDataSource to customize its |
| 21 // behavior. |
| 22 class CONTENT_EXPORT URLDataSourceDelegate { |
| 23 public: |
| 24 URLDataSourceDelegate(); |
| 25 virtual ~URLDataSourceDelegate(); |
| 26 |
| 27 // The name of this source. |
| 28 // E.g., for favicons, this could be "favicon", which results in paths for |
| 29 // specific resources like "favicon/34" getting sent to this source. |
| 30 virtual std::string GetSource() = 0; |
| 31 |
| 32 // Called by URLDataSource to request data at |path|. The delegate should |
| 33 // call URLDataSource::SendResponse() when the data is available or if the |
| 34 // request could not be satisfied. |
| 35 virtual void StartDataRequest(const std::string& path, |
| 36 bool is_incognito, |
| 37 int request_id) = 0; |
| 38 |
| 39 // Return the mimetype that should be sent with this response, or empty |
| 40 // string to specify no mime type. |
| 41 virtual std::string GetMimeType(const std::string& path) const = 0; |
| 42 |
| 43 // Returns the MessageLoop on which the delegate wishes to have |
| 44 // StartDataRequest called to handle the request for |path|. The default |
| 45 // implementation returns BrowserThread::UI. If the delegate does not care |
| 46 // which thread StartDataRequest is called on, this should return NULL. It may |
| 47 // be beneficial to return NULL for requests that are safe to handle directly |
| 48 // on the IO thread. This can improve performance by satisfying such requests |
| 49 // more rapidly when there is a large amount of UI thread contention. Or the |
| 50 // delegate can return a specific thread's Messageloop if they wish. |
| 51 virtual MessageLoop* MessageLoopForRequestPath(const std::string& path) const; |
| 52 |
| 53 // Returns true if the URLDataSource should replace an existing URLDataSource |
| 54 // with the same name that has already been registered. The default is true. |
| 55 // |
| 56 // WARNING: this is invoked on the IO thread. |
| 57 // |
| 58 // TODO: nuke this and convert all callers to not replace. |
| 59 virtual bool ShouldReplaceExistingSource() const; |
| 60 |
| 61 // Returns true if responses from this URLDataSource can be cached. |
| 62 virtual bool AllowCaching() const; |
| 63 |
| 64 void set_url_data_source_for_testing(URLDataSource* url_data_source) { |
| 65 url_data_source_ = url_data_source; |
| 66 } |
| 67 |
| 68 protected: |
| 69 URLDataSource* url_data_source() { return url_data_source_; } |
| 70 |
| 71 private: |
| 72 friend class ::ChromeURLDataManager; |
| 73 friend class ::ChromeURLDataManagerBackend; |
| 74 friend class ::ChromeWebUIDataSource; |
| 75 URLDataSource* url_data_source_; |
| 76 }; |
| 77 |
| 78 } // namespace content |
| 79 |
| 80 #endif // CONTENT_PUBLIC_BROWSER_URL_DATA_SOURCE_DELEGATE_H_ |
OLD | NEW |