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

Side by Side Diff: net/spdy/spdy_test_util_common.h

Issue 2096713002: Reduce SpdyHeaderBlock copies with move semantics. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 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_SPDY_SPDY_TEST_UTIL_COMMON_H_ 5 #ifndef NET_SPDY_SPDY_TEST_UTIL_COMMON_H_
6 #define NET_SPDY_SPDY_TEST_UTIL_COMMON_H_ 6 #define NET_SPDY_SPDY_TEST_UTIL_COMMON_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 289
290 class SpdyTestUtil { 290 class SpdyTestUtil {
291 public: 291 public:
292 explicit SpdyTestUtil(NextProto protocol, bool dependency_priorities); 292 explicit SpdyTestUtil(NextProto protocol, bool dependency_priorities);
293 ~SpdyTestUtil(); 293 ~SpdyTestUtil();
294 294
295 // Add the appropriate headers to put |url| into |block|. 295 // Add the appropriate headers to put |url| into |block|.
296 void AddUrlToHeaderBlock(base::StringPiece url, 296 void AddUrlToHeaderBlock(base::StringPiece url,
297 SpdyHeaderBlock* headers) const; 297 SpdyHeaderBlock* headers) const;
298 298
299 std::unique_ptr<SpdyHeaderBlock> ConstructGetHeaderBlock( 299 SpdyHeaderBlock ConstructGetHeaderBlock(base::StringPiece url) const;
300 base::StringPiece url) const; 300 SpdyHeaderBlock ConstructGetHeaderBlockForProxy(base::StringPiece url) const;
301 std::unique_ptr<SpdyHeaderBlock> ConstructGetHeaderBlockForProxy( 301 SpdyHeaderBlock ConstructHeadHeaderBlock(base::StringPiece url,
302 base::StringPiece url) const; 302 int64_t content_length) const;
303 std::unique_ptr<SpdyHeaderBlock> ConstructHeadHeaderBlock( 303 SpdyHeaderBlock ConstructPostHeaderBlock(base::StringPiece url,
304 base::StringPiece url, 304 int64_t content_length) const;
305 int64_t content_length) const; 305 SpdyHeaderBlock ConstructPutHeaderBlock(base::StringPiece url,
306 std::unique_ptr<SpdyHeaderBlock> ConstructPostHeaderBlock( 306 int64_t content_length) const;
307 base::StringPiece url,
308 int64_t content_length) const;
309 std::unique_ptr<SpdyHeaderBlock> ConstructPutHeaderBlock(
310 base::StringPiece url,
311 int64_t content_length) const;
312 307
313 // Construct a SPDY frame. If it is a SYN_STREAM or SYN_REPLY frame (as 308 // Construct a SPDY frame. If it is a SYN_STREAM or SYN_REPLY frame (as
314 // specified in header_info.kind), the provided headers are included in the 309 // specified in header_info.kind), the provided headers are included in the
315 // frame. 310 // frame.
316 SpdySerializedFrame* ConstructSpdyFrame( 311 SpdySerializedFrame* ConstructSpdyFrame(const SpdyHeaderInfo& header_info,
317 const SpdyHeaderInfo& header_info, 312 SpdyHeaderBlock headers) const;
318 std::unique_ptr<SpdyHeaderBlock> headers) const;
319 313
320 // Construct a SPDY frame. If it is a SYN_STREAM or SYN_REPLY frame (as 314 // Construct a SPDY frame. If it is a SYN_STREAM or SYN_REPLY frame (as
321 // specified in header_info.kind), the headers provided in extra_headers and 315 // specified in header_info.kind), the headers provided in extra_headers and
322 // (if non-NULL) tail_headers are concatenated and included in the frame. 316 // (if non-NULL) tail_headers are concatenated and included in the frame.
323 // (extra_headers must always be non-NULL.) 317 // (extra_headers must always be non-NULL.)
324 SpdySerializedFrame* ConstructSpdyFrame(const SpdyHeaderInfo& header_info, 318 SpdySerializedFrame* ConstructSpdyFrame(const SpdyHeaderInfo& header_info,
325 const char* const extra_headers[], 319 const char* const extra_headers[],
326 int extra_header_count, 320 int extra_header_count,
327 const char* const tail_headers[], 321 const char* const tail_headers[],
328 int tail_header_count) const; 322 int tail_header_count) const;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 int associated_stream_id, 398 int associated_stream_id,
405 const char* url); 399 const char* url);
406 SpdySerializedFrame* ConstructSpdyPush(const char* const extra_headers[], 400 SpdySerializedFrame* ConstructSpdyPush(const char* const extra_headers[],
407 int extra_header_count, 401 int extra_header_count,
408 int stream_id, 402 int stream_id,
409 int associated_stream_id, 403 int associated_stream_id,
410 const char* url, 404 const char* url,
411 const char* status, 405 const char* status,
412 const char* location); 406 const char* location);
413 407
414 SpdySerializedFrame* ConstructInitialSpdyPushFrame( 408 SpdySerializedFrame* ConstructInitialSpdyPushFrame(SpdyHeaderBlock headers,
415 std::unique_ptr<SpdyHeaderBlock> headers, 409 int stream_id,
416 int stream_id, 410 int associated_stream_id);
417 int associated_stream_id);
418 411
419 SpdySerializedFrame* ConstructSpdyPushHeaders( 412 SpdySerializedFrame* ConstructSpdyPushHeaders(
420 int stream_id, 413 int stream_id,
421 const char* const extra_headers[], 414 const char* const extra_headers[],
422 int extra_header_count); 415 int extra_header_count);
423 416
424 // Constructs a SPDY header frame with the request header compression context 417 // Constructs a SPDY header frame with the request header compression context
425 // with END_STREAM flag set to |fin|. 418 // with END_STREAM flag set to |fin|.
426 SpdySerializedFrame* ConstructSpdyResponseHeaders( 419 SpdySerializedFrame* ConstructSpdyResponseHeaders(int stream_id,
427 int stream_id, 420 SpdyHeaderBlock headers,
428 const SpdyHeaderBlock& headers, 421 bool fin);
429 bool fin);
430 422
431 // Construct a SPDY syn (HEADERS or SYN_STREAM, depending on protocol 423 // Construct a SPDY syn (HEADERS or SYN_STREAM, depending on protocol
432 // version) carrying exactly the given headers and priority. 424 // version) carrying exactly the given headers and priority.
433 SpdySerializedFrame* ConstructSpdySyn(int stream_id, 425 SpdySerializedFrame* ConstructSpdySyn(int stream_id,
434 const SpdyHeaderBlock& headers, 426 SpdyHeaderBlock headers,
435 RequestPriority priority, 427 RequestPriority priority,
436 bool fin); 428 bool fin);
437 429
438 // Construct a SPDY reply (HEADERS or SYN_REPLY, depending on protocol 430 // Construct a SPDY reply (HEADERS or SYN_REPLY, depending on protocol
439 // version) carrying exactly the given headers, and the default priority 431 // version) carrying exactly the given headers, and the default priority
440 // (or no priority, depending on protocol version). 432 // (or no priority, depending on protocol version).
441 SpdySerializedFrame* ConstructSpdyReply(int stream_id, 433 SpdySerializedFrame* ConstructSpdyReply(int stream_id,
442 const SpdyHeaderBlock& headers); 434 SpdyHeaderBlock headers);
443 435
444 // Constructs a standard SPDY SYN_REPLY frame to match the SPDY GET. 436 // Constructs a standard SPDY SYN_REPLY frame to match the SPDY GET.
445 // |extra_headers| are the extra header-value pairs, which typically 437 // |extra_headers| are the extra header-value pairs, which typically
446 // will vary the most between calls. 438 // will vary the most between calls.
447 // Returns a SpdySerializedFrame. 439 // Returns a SpdySerializedFrame.
448 SpdySerializedFrame* ConstructSpdyGetSynReply( 440 SpdySerializedFrame* ConstructSpdyGetSynReply(
449 const char* const extra_headers[], 441 const char* const extra_headers[],
450 int extra_header_count, 442 int extra_header_count,
451 int stream_id); 443 int stream_id);
452 444
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 511
520 // Serialize a SpdyFrameIR with |headerless_spdy_framer_|. 512 // Serialize a SpdyFrameIR with |headerless_spdy_framer_|.
521 SpdySerializedFrame SerializeFrame(const SpdyFrameIR& frame_ir); 513 SpdySerializedFrame SerializeFrame(const SpdyFrameIR& frame_ir);
522 514
523 // Called when necessary (when it will affect stream dependency specification 515 // Called when necessary (when it will affect stream dependency specification
524 // when setting dependencies based on priorioties) to notify the utility 516 // when setting dependencies based on priorioties) to notify the utility
525 // class of stream destruction. 517 // class of stream destruction.
526 void UpdateWithStreamDestruction(int stream_id); 518 void UpdateWithStreamDestruction(int stream_id);
527 519
528 // For versions below SPDY4, adds the version HTTP/1.1 header. 520 // For versions below SPDY4, adds the version HTTP/1.1 header.
529 void MaybeAddVersionHeader(SpdyFrameWithHeaderBlockIR* frame_ir) const;
530 void MaybeAddVersionHeader(SpdyHeaderBlock* block) const; 521 void MaybeAddVersionHeader(SpdyHeaderBlock* block) const;
531 522
532 // Maps |priority| to SPDY version priority, and sets it on |frame_ir|. 523 // Maps |priority| to SPDY version priority, and sets it on |frame_ir|.
533 void SetPriority(RequestPriority priority, SpdySynStreamIR* frame_ir) const; 524 void SetPriority(RequestPriority priority, SpdySynStreamIR* frame_ir) const;
534 525
535 NextProto protocol() const { return protocol_; } 526 NextProto protocol() const { return protocol_; }
536 SpdyMajorVersion spdy_version() const { return spdy_version_; } 527 SpdyMajorVersion spdy_version() const { return spdy_version_; }
537 bool include_version_header() const { return protocol_ < kProtoHTTP2; } 528 bool include_version_header() const { return protocol_ < kProtoHTTP2; }
538 529
539 const GURL& default_url() const { return default_url_; } 530 const GURL& default_url() const { return default_url_; }
540 void set_default_url(const GURL& url) { default_url_ = url; } 531 void set_default_url(const GURL& url) { default_url_ = url; }
541 532
542 const char* GetMethodKey() const; 533 const char* GetMethodKey() const;
543 const char* GetStatusKey() const; 534 const char* GetStatusKey() const;
544 const char* GetHostKey() const; 535 const char* GetHostKey() const;
545 const char* GetSchemeKey() const; 536 const char* GetSchemeKey() const;
546 const char* GetVersionKey() const; 537 const char* GetVersionKey() const;
547 const char* GetPathKey() const; 538 const char* GetPathKey() const;
548 539
549 private: 540 private:
550 // |content_length| may be NULL, in which case the content-length 541 // |content_length| may be NULL, in which case the content-length
551 // header will be omitted. 542 // header will be omitted.
552 std::unique_ptr<SpdyHeaderBlock> ConstructHeaderBlock( 543 SpdyHeaderBlock ConstructHeaderBlock(base::StringPiece method,
553 base::StringPiece method, 544 base::StringPiece url,
554 base::StringPiece url, 545 int64_t* content_length) const;
555 int64_t* content_length) const;
556 546
557 const NextProto protocol_; 547 const NextProto protocol_;
558 const SpdyMajorVersion spdy_version_; 548 const SpdyMajorVersion spdy_version_;
559 549
560 // Multiple SpdyFramers are required to keep track of header compression 550 // Multiple SpdyFramers are required to keep track of header compression
561 // state. 551 // state.
562 // Use to serialize frames (request or response) without headers. 552 // Use to serialize frames (request or response) without headers.
563 SpdyFramer headerless_spdy_framer_; 553 SpdyFramer headerless_spdy_framer_;
564 // Use to serialize request frames with headers. 554 // Use to serialize request frames with headers.
565 SpdyFramer request_spdy_framer_; 555 SpdyFramer request_spdy_framer_;
566 // Use to serialize response frames with headers. 556 // Use to serialize response frames with headers.
567 SpdyFramer response_spdy_framer_; 557 SpdyFramer response_spdy_framer_;
568 558
569 GURL default_url_; 559 GURL default_url_;
570 bool dependency_priorities_; 560 bool dependency_priorities_;
571 561
572 // Track a FIFO list of the stream_id of all created requests by priority. 562 // Track a FIFO list of the stream_id of all created requests by priority.
573 std::map<int, std::vector<int>> priority_to_stream_id_list_; 563 std::map<int, std::vector<int>> priority_to_stream_id_list_;
574 }; 564 };
575 565
576 } // namespace net 566 } // namespace net
577 567
578 #endif // NET_SPDY_SPDY_TEST_UTIL_COMMON_H_ 568 #endif // NET_SPDY_SPDY_TEST_UTIL_COMMON_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698