1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
// Copyright (c) 2013 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.
#include "net/spdy/spdy_test_util_common.h"
#include <cstddef>
#include "base/compiler_specific.h"
#include "net/spdy/buffered_spdy_framer.h"
namespace net {
namespace {
class PriorityGetter : public BufferedSpdyFramerVisitorInterface {
public:
PriorityGetter() : priority_(0) {}
virtual ~PriorityGetter() {}
SpdyPriority priority() const {
return priority_;
}
virtual void OnError(SpdyFramer::SpdyError error_code) OVERRIDE {}
virtual void OnStreamError(SpdyStreamId stream_id,
const std::string& description) OVERRIDE {}
virtual void OnSynStream(SpdyStreamId stream_id,
SpdyStreamId associated_stream_id,
SpdyPriority priority,
uint8 credential_slot,
bool fin,
bool unidirectional,
const SpdyHeaderBlock& headers) OVERRIDE {
priority_ = priority;
}
virtual void OnSynReply(SpdyStreamId stream_id,
bool fin,
const SpdyHeaderBlock& headers) OVERRIDE {}
virtual void OnHeaders(SpdyStreamId stream_id,
bool fin,
const SpdyHeaderBlock& headers) OVERRIDE {}
virtual void OnStreamFrameData(SpdyStreamId stream_id,
const char* data,
size_t len,
SpdyDataFlags flags) OVERRIDE {}
virtual void OnSetting(
SpdySettingsIds id, uint8 flags, uint32 value) OVERRIDE {}
virtual void OnPing(uint32 unique_id) OVERRIDE {}
virtual void OnRstStream(SpdyStreamId stream_id,
SpdyRstStreamStatus status) OVERRIDE {}
virtual void OnGoAway(SpdyStreamId last_accepted_stream_id,
SpdyGoAwayStatus status) OVERRIDE {}
virtual void OnWindowUpdate(SpdyStreamId stream_id,
int delta_window_size) OVERRIDE {}
virtual void OnSynStreamCompressed(
size_t uncompressed_size,
size_t compressed_size) OVERRIDE {}
private:
SpdyPriority priority_;
};
} // namespace
bool GetSpdyPriority(int version,
const SpdyFrame& frame,
SpdyPriority* priority) {
BufferedSpdyFramer framer(version, false);
PriorityGetter priority_getter;
framer.set_visitor(&priority_getter);
size_t frame_size = frame.length() + SpdyFrame::kHeaderSize;
if (framer.ProcessInput(frame.data(), frame_size) != frame_size) {
return false;
}
*priority = priority_getter.priority();
return true;
}
} // namespace net
|