OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 NET_FILTER_MOCK_FILTER_CONTEXT_H_ | 5 #ifndef NET_FILTER_MOCK_FILTER_CONTEXT_H_ |
6 #define NET_FILTER_MOCK_FILTER_CONTEXT_H_ | 6 #define NET_FILTER_MOCK_FILTER_CONTEXT_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "net/base/net_log.h" | 11 #include "net/base/net_log.h" |
| 12 #include "net/base/sdch_manager.h" |
12 #include "net/filter/filter.h" | 13 #include "net/filter/filter.h" |
13 #include "url/gurl.h" | 14 #include "url/gurl.h" |
14 | 15 |
15 namespace net { | 16 namespace net { |
16 | 17 |
17 class URLRequestContext; | 18 class URLRequestContext; |
18 | 19 |
19 class MockFilterContext : public FilterContext { | 20 class MockFilterContext : public FilterContext { |
20 public: | 21 public: |
21 MockFilterContext(); | 22 MockFilterContext(); |
22 ~MockFilterContext() override; | 23 ~MockFilterContext() override; |
23 | 24 |
24 void SetMimeType(const std::string& mime_type) { mime_type_ = mime_type; } | 25 void SetMimeType(const std::string& mime_type) { mime_type_ = mime_type; } |
25 void SetURL(const GURL& gurl) { gurl_ = gurl; } | 26 void SetURL(const GURL& gurl) { gurl_ = gurl; } |
26 void SetContentDisposition(const std::string& disposition) { | 27 void SetContentDisposition(const std::string& disposition) { |
27 content_disposition_ = disposition; | 28 content_disposition_ = disposition; |
28 } | 29 } |
29 void SetRequestTime(const base::Time time) { request_time_ = time; } | 30 void SetRequestTime(const base::Time time) { request_time_ = time; } |
30 void SetCached(bool is_cached) { is_cached_content_ = is_cached; } | 31 void SetCached(bool is_cached) { is_cached_content_ = is_cached; } |
31 void SetDownload(bool is_download) { is_download_ = is_download; } | 32 void SetDownload(bool is_download) { is_download_ = is_download; } |
32 void SetResponseCode(int response_code) { response_code_ = response_code; } | 33 void SetResponseCode(int response_code) { response_code_ = response_code; } |
33 void SetSdchResponse(bool is_sdch_response) { | 34 void SetSdchResponse(scoped_ptr<SdchManager::DictionarySet> handle) { |
34 is_sdch_response_ = is_sdch_response; | 35 dictionaries_handle_ = handle.Pass(); |
35 } | 36 } |
36 URLRequestContext* GetModifiableURLRequestContext() const { | 37 URLRequestContext* GetModifiableURLRequestContext() const { |
37 return context_.get(); | 38 return context_.get(); |
38 } | 39 } |
39 | 40 |
40 // After a URLRequest's destructor is called, some interfaces may become | 41 // After a URLRequest's destructor is called, some interfaces may become |
41 // unstable. This method is used to signal that state, so we can tag use | 42 // unstable. This method is used to signal that state, so we can tag use |
42 // of those interfaces as coding errors. | 43 // of those interfaces as coding errors. |
43 void NukeUnstableInterfaces(); | 44 void NukeUnstableInterfaces(); |
44 | 45 |
45 bool GetMimeType(std::string* mime_type) const override; | 46 bool GetMimeType(std::string* mime_type) const override; |
46 | 47 |
47 // What URL was used to access this data? | 48 // What URL was used to access this data? |
48 // Return false if gurl is not present. | 49 // Return false if gurl is not present. |
49 bool GetURL(GURL* gurl) const override; | 50 bool GetURL(GURL* gurl) const override; |
50 | 51 |
51 // What Content-Disposition did the server supply for this data? | 52 // What Content-Disposition did the server supply for this data? |
52 // Return false if Content-Disposition was not present. | 53 // Return false if Content-Disposition was not present. |
53 bool GetContentDisposition(std::string* disposition) const override; | 54 bool GetContentDisposition(std::string* disposition) const override; |
54 | 55 |
55 // What was this data requested from a server? | 56 // What was this data requested from a server? |
56 base::Time GetRequestTime() const override; | 57 base::Time GetRequestTime() const override; |
57 | 58 |
58 // Is data supplied from cache, or fresh across the net? | 59 // Is data supplied from cache, or fresh across the net? |
59 bool IsCachedContent() const override; | 60 bool IsCachedContent() const override; |
60 | 61 |
61 // Is this a download? | 62 // Is this a download? |
62 bool IsDownload() const override; | 63 bool IsDownload() const override; |
63 | 64 |
64 // Was this data flagged as a response to a request with an SDCH dictionary? | 65 // Handle to dictionaries advertised. |
65 bool SdchResponseExpected() const override; | 66 SdchManager::DictionarySet* SdchDictionariesAdvertised() const override; |
66 | 67 |
67 // How many bytes were fed to filter(s) so far? | 68 // How many bytes were fed to filter(s) so far? |
68 int64 GetByteReadCount() const override; | 69 int64 GetByteReadCount() const override; |
69 | 70 |
70 int GetResponseCode() const override; | 71 int GetResponseCode() const override; |
71 | 72 |
72 // The URLRequestContext associated with the request. | 73 // The URLRequestContext associated with the request. |
73 const URLRequestContext* GetURLRequestContext() const override; | 74 const URLRequestContext* GetURLRequestContext() const override; |
74 | 75 |
75 void RecordPacketStats(StatisticSelector statistic) const override {} | 76 void RecordPacketStats(StatisticSelector statistic) const override {} |
76 | 77 |
77 const BoundNetLog& GetNetLog() const override; | 78 const BoundNetLog& GetNetLog() const override; |
78 | 79 |
79 private: | 80 private: |
80 int buffer_size_; | 81 int buffer_size_; |
81 std::string mime_type_; | 82 std::string mime_type_; |
82 std::string content_disposition_; | 83 std::string content_disposition_; |
83 GURL gurl_; | 84 GURL gurl_; |
84 base::Time request_time_; | 85 base::Time request_time_; |
85 bool is_cached_content_; | 86 bool is_cached_content_; |
86 bool is_download_; | 87 bool is_download_; |
87 bool is_sdch_response_; | 88 scoped_ptr<SdchManager::DictionarySet> dictionaries_handle_; |
88 bool ok_to_call_get_url_; | 89 bool ok_to_call_get_url_; |
89 int response_code_; | 90 int response_code_; |
90 scoped_ptr<URLRequestContext> context_; | 91 scoped_ptr<URLRequestContext> context_; |
91 BoundNetLog net_log_; | 92 BoundNetLog net_log_; |
92 | 93 |
93 DISALLOW_COPY_AND_ASSIGN(MockFilterContext); | 94 DISALLOW_COPY_AND_ASSIGN(MockFilterContext); |
94 }; | 95 }; |
95 | 96 |
96 } // namespace net | 97 } // namespace net |
97 | 98 |
98 #endif // NET_FILTER_MOCK_FILTER_CONTEXT_H_ | 99 #endif // NET_FILTER_MOCK_FILTER_CONTEXT_H_ |
OLD | NEW |