Windows should animate when they are about to get docked at screen edges.
[chromium-blink-merge.git] / net / tools / quic / quic_in_memory_cache.h
blob6322e2da49d76d03baef62c33cd34dc37e8c2e39
1 // Copyright (c) 2012 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.
5 #ifndef NET_TOOLS_QUIC_QUIC_IN_MEMORY_CACHE_H_
6 #define NET_TOOLS_QUIC_QUIC_IN_MEMORY_CACHE_H_
8 #include <string>
10 #include "base/containers/hash_tables.h"
11 #include "base/memory/singleton.h"
12 #include "base/strings/string_piece.h"
13 #include "net/tools/flip_server/balsa_frame.h"
14 #include "net/tools/flip_server/balsa_headers.h"
16 template <typename T> struct DefaultSingletonTraits;
18 namespace net {
19 namespace tools {
21 extern std::string FLAGS_quic_in_memory_cache_dir;
23 class QuicServer;
25 // In-memory cache for HTTP responses.
26 // Reads from disk cache generated by:
27 // `wget -p --save_headers <url>`
28 class QuicInMemoryCache {
29 public:
30 // Container for response header/body pairs.
31 class Response {
32 public:
33 Response() {}
34 ~Response() {}
36 const BalsaHeaders& headers() const { return headers_; }
37 const base::StringPiece body() const { return base::StringPiece(body_); }
39 private:
40 friend class QuicInMemoryCache;
42 void set_headers(const BalsaHeaders& headers) {
43 headers_.CopyFrom(headers);
45 void set_body(base::StringPiece body) {
46 body.CopyToString(&body_);
49 BalsaHeaders headers_;
50 std::string body_;
52 DISALLOW_COPY_AND_ASSIGN(Response);
54 static QuicInMemoryCache* GetInstance();
56 // Retrieve a response from this cache for a given request.
57 // If no appropriate response exists, NULL is returned.
58 // Currently, responses are selected based on request URI only.
59 const Response* GetResponse(const BalsaHeaders& request_headers) const;
61 // Add a response to the cache.
62 void AddResponse(const BalsaHeaders& request_headers,
63 const BalsaHeaders& response_headers,
64 base::StringPiece response_body);
66 void ResetForTests();
68 private:
69 typedef base::hash_map<std::string, Response*> ResponseMap;
72 QuicInMemoryCache();
73 friend struct DefaultSingletonTraits<QuicInMemoryCache>;
74 ~QuicInMemoryCache();
76 void Initialize();
77 std::string GetKey(const BalsaHeaders& response_headers) const;
79 // Cached responses.
80 ResponseMap responses_;
82 DISALLOW_COPY_AND_ASSIGN(QuicInMemoryCache);
85 } // namespace tools
86 } // namespace net
88 #endif // NET_TOOLS_QUIC_QUIC_IN_MEMORY_CACHE_H_