Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Unified Diff: net/filter/sdch_policy_delegate.h

Issue 2368433002: Add net::SdchSourceStream and net::SdchPolicyDelegate (Closed)
Patch Set: Make SdchPolicyDelegate owned by SdchSourceStream Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/filter/sdch_policy_delegate.cc » ('j') | net/filter/sdch_policy_delegate.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/filter/sdch_policy_delegate.h
diff --git a/net/filter/sdch_policy_delegate.h b/net/filter/sdch_policy_delegate.h
new file mode 100644
index 0000000000000000000000000000000000000000..43d01ece13a14bd66b6ed5749cad717dace7879b
--- /dev/null
+++ b/net/filter/sdch_policy_delegate.h
@@ -0,0 +1,143 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_FILTER_SDCH_POLICY_DELEGATE_H_
+#define NET_FILTER_SDCH_POLICY_DELEGATE_H_
+
+#include <memory>
+#include <string>
+
+#include "base/macros.h"
+#include "base/supports_user_data.h"
+#include "net/base/net_export.h"
+#include "net/base/sdch_manager.h"
+#include "net/filter/sdch_source_stream.h"
+#include "net/log/net_log.h"
+#include "net/log/net_log_with_source.h"
+#include "url/gurl.h"
+
+namespace open_vcdiff {
+class VCDiffStreamingDecoder;
+}
+
+namespace net {
+
+class SdchSourceStream;
+
+// This class implements the SdchSourceStream::Delegate interface to perform
+// the SDCH error handling and stats gathering. The Context object supplies
+// details about the request needed for this object to make error-handling
+// decisions. See the SdchSourceStream::Delegate documentation for more details.
+class NET_EXPORT_PRIVATE SdchPolicyDelegate
+ : public SdchSourceStream::Delegate {
+ public:
+ enum StatisticSelector {
+ SDCH_DECODE,
+ SDCH_PASSTHROUGH,
+ SDCH_EXPERIMENT_DECODE,
+ SDCH_EXPERIMENT_HOLDBACK,
+ };
+
+ SdchPolicyDelegate(std::string mime_type,
+ const GURL& url,
+ bool is_cached_content,
+ SdchManager* sdch_manager,
+ std::unique_ptr<SdchManager::DictionarySet> dictionary_set,
+ int response_code,
+ const NetLogWithSource& net_log);
+
+ ~SdchPolicyDelegate() override;
+
+ // Logs an SDCH failure to UMA and |netlog|.
+ static void LogSdchProblem(NetLogWithSource netlog, SdchProblemCode problem);
+
+ // Sdch specific hacks to fix up encoding types.
+ static void FixUpSdchContentEncodings(
+ const NetLogWithSource& net_log,
+ const std::string& mime_type,
+ SdchManager::DictionarySet* dictionary_set,
+ std::vector<SourceStream::SourceType>* types);
+
+ // SdchSourceStream::Delegate implementation.
+ ErrorRecovery OnDictionaryIdError(bool possible_pass_through,
+ std::string* replace_output) override;
+ ErrorRecovery OnGetDictionaryError(bool possible_pass_through,
+ std::string* replace_output) override;
+ ErrorRecovery OnDecodingError(std::string* replace_output) override;
+ bool OnGetDictionary(const std::string& server_id,
+ const std::string** text) override;
+
+ void OnStreamDestroyed(SdchSourceStream::InputState input_state,
+ const std::string& buffered_output,
+ open_vcdiff::VCDiffStreamingDecoder* decoder) override;
+
+ private:
+ // Disambiguate various types of responses that trigger a meta-refresh,
+ // failure, or fallback to pass-through.
+ enum ResponseCorruptionDetectionCause {
+ RESPONSE_NONE,
+
+ // 404 Http Response Code
+ RESPONSE_404 = 1,
+
+ // Not a 200 Http Response Code
+ RESPONSE_NOT_200 = 2,
+
+ // Cached before dictionary retrieved.
+ RESPONSE_OLD_UNENCODED = 3,
+
+ // Speculative but incorrect SDCH filtering was added added.
+ RESPONSE_TENTATIVE_SDCH = 4,
+
+ // Missing correct dict for decoding.
+ RESPONSE_NO_DICTIONARY = 5,
+
+ // Not an SDCH response but should be.
+ RESPONSE_CORRUPT_SDCH = 6,
+
+ // No dictionary was advertised with the request, the server claims
+ // to have encoded with SDCH anyway, but it isn't an SDCH response.
+ RESPONSE_ENCODING_LIE = 7,
+
+ RESPONSE_MAX,
+ };
+
+ // Issues a meta-refresh if the context's MIME type supports it, and returns
+ // whether a refresh was issued. As a side-effect, blacklists the context's
+ // domain either temporarily or permanently.
+ ErrorRecovery IssueMetaRefreshIfPossible(std::string* replace_output);
+
+ // Logs ResponseCorruptionDetection cause. This is very similar to
+ // LogSdchProblem(). TODO(xunjieli): Can we get rid of this?
+ void LogCorruptionDetection(ResponseCorruptionDetectionCause cause);
+
+ static const char* ResponseCorruptionDetectionCauseToString(
+ ResponseCorruptionDetectionCause cause);
+
+ static std::unique_ptr<base::Value> NetLogResponseCorruptionDetectionCallback(
+ ResponseCorruptionDetectionCause cause,
+ bool cached,
+ NetLogCaptureMode capture_mode);
+
+ const std::string mime_type_;
+ const GURL url_;
+ const bool is_cached_content_;
+ SdchManager* sdch_manager_;
+ std::unique_ptr<SdchManager::DictionarySet> dictionary_set_;
+ const int response_code_;
+ const NetLogWithSource net_log_;
+
+ std::string server_id_;
+
+ // If the response was encoded with a dictionary different than those
+ // advertised (e.g. a cached response using an old dictionary), this
+ // variable preserves that dictionary from deletion during decoding.
+ std::unique_ptr<SdchManager::DictionarySet> unexpected_dictionary_set_;
+
+ DISALLOW_COPY_AND_ASSIGN(SdchPolicyDelegate);
+};
+
+} // namespace net
+
+#endif // NET_FILTER_SDCH_POLICY_DELEGATE_H_
« no previous file with comments | « no previous file | net/filter/sdch_policy_delegate.cc » ('j') | net/filter/sdch_policy_delegate.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698