| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 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 NET_FILTER_SDCH_POLICY_DELEGATE_H_ |
| 6 #define NET_FILTER_SDCH_POLICY_DELEGATE_H_ |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "base/macros.h" |
| 11 #include "base/supports_user_data.h" |
| 12 #include "net/base/net_export.h" |
| 13 #include "net/base/sdch_manager.h" |
| 14 #include "net/filter/sdch_source_stream.h" |
| 15 #include "net/log/net_log.h" |
| 16 #include "url/gurl.h" |
| 17 |
| 18 namespace net { |
| 19 |
| 20 class SdchSourceStream; |
| 21 |
| 22 // This class ascribes to the SdchSourceStream::Delegate interface to implement |
| 23 // the SDCH error-handling and stats-gathering policy. The Context object |
| 24 // supplies details about the request needed for this object to make |
| 25 // error-handling decisions. See the SdchSourceStream::Delegate documentation |
| 26 // for more details. |
| 27 class NET_EXPORT_PRIVATE SdchPolicyDelegate |
| 28 : public SdchSourceStream::Delegate { |
| 29 public: |
| 30 class Context { |
| 31 public: |
| 32 enum StatisticSelector { |
| 33 SDCH_DECODE, |
| 34 SDCH_PASSTHROUGH, |
| 35 SDCH_EXPERIMENT_DECODE, |
| 36 SDCH_EXPERIMENT_HOLDBACK, |
| 37 }; |
| 38 |
| 39 virtual ~Context() {} |
| 40 virtual bool GetMimeType(std::string* mime_type) const = 0; |
| 41 virtual bool GetURL(GURL* url) const = 0; |
| 42 virtual bool IsCachedContent() const = 0; |
| 43 virtual SdchManager* GetSdchManager() const = 0; |
| 44 virtual SdchManager::DictionarySet* SdchDictionariesAdvertised() const = 0; |
| 45 // virtual int64_t GetByteReadCount() const = 0; |
| 46 virtual int GetResponseCode() const = 0; |
| 47 virtual const BoundNetLog& GetNetLog() const = 0; |
| 48 }; |
| 49 |
| 50 SdchPolicyDelegate(std::unique_ptr<Context> context); |
| 51 |
| 52 ~SdchPolicyDelegate() override; |
| 53 |
| 54 // SdchSourceStream::Delegate implementation. |
| 55 bool OnDictionaryError(SdchSourceStream* source) override; |
| 56 bool OnDecodingError(SdchSourceStream* source) override; |
| 57 bool OnGetDictionary(const std::string& server_id, |
| 58 const std::string** text) override; |
| 59 |
| 60 private: |
| 61 // Issues a meta-refresh if the context's MIME type supports it, and returns |
| 62 // whether a refresh was issued. As a side-effect, blacklists the context's |
| 63 // domain either temporarily or permanently. |
| 64 bool IssueMetaRefreshIfPossible(SdchSourceStream* source); |
| 65 |
| 66 // Logs an SDCH failure. This logs events in UMA and the net log in |
| 67 // |context_|, but has no side-effects on this class or the stream. |
| 68 void LogSdchProblem(SdchProblemCode problem); |
| 69 |
| 70 bool dictionary_requested_; |
| 71 |
| 72 std::unique_ptr<Context> context_; |
| 73 // If the response was encoded with a dictionary different than those |
| 74 // advertised (e.g. a cached response using an old dictionary), this |
| 75 // variable preserves that dictionary from deletion during decoding. |
| 76 std::unique_ptr<SdchManager::DictionarySet> unexpected_dictionary_set_; |
| 77 |
| 78 DISALLOW_COPY_AND_ASSIGN(SdchPolicyDelegate); |
| 79 }; |
| 80 |
| 81 } // namespace net |
| 82 |
| 83 #endif // NET_FILTER_SDCH_POLICY_DELEGATE_H_ |
| OLD | NEW |