When enabling new profile management programmatically, make sure to set the
[chromium-blink-merge.git] / content / browser / loader / certificate_resource_handler.h
blob9c67860eb7eff02bc2958a01654a4d60acf69102
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 CONTENT_BROWSER_LOADER_CERTIFICATE_RESOURCE_HANDLER_H_
6 #define CONTENT_BROWSER_LOADER_CERTIFICATE_RESOURCE_HANDLER_H_
8 #include <string>
9 #include <utility>
10 #include <vector>
12 #include "base/compiler_specific.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "content/browser/loader/resource_handler.h"
16 #include "net/base/mime_util.h"
17 #include "url/gurl.h"
19 namespace net {
20 class IOBuffer;
21 class URLRequest;
22 class URLRequestStatus;
23 } // namespace net
25 namespace content {
27 // This class handles certificate mime types such as:
28 // - "application/x-x509-user-cert"
29 // - "application/x-x509-ca-cert"
30 // - "application/x-pkcs12"
32 class CertificateResourceHandler : public ResourceHandler {
33 public:
34 explicit CertificateResourceHandler(net::URLRequest* request);
35 virtual ~CertificateResourceHandler();
37 virtual bool OnUploadProgress(uint64 position, uint64 size) OVERRIDE;
39 // Not needed, as this event handler ought to be the final resource.
40 virtual bool OnRequestRedirected(const GURL& url,
41 ResourceResponse* resp,
42 bool* defer) OVERRIDE;
44 // Check if this indeed an X509 cert.
45 virtual bool OnResponseStarted(ResourceResponse* resp,
46 bool* defer) OVERRIDE;
48 // Pass-through implementation.
49 virtual bool OnWillStart(const GURL& url, bool* defer) OVERRIDE;
51 // Pass-through implementation.
52 virtual bool OnBeforeNetworkStart(const GURL& url, bool* defer) OVERRIDE;
54 // Create a new buffer to store received data.
55 virtual bool OnWillRead(scoped_refptr<net::IOBuffer>* buf,
56 int* buf_size,
57 int min_size) OVERRIDE;
59 // A read was completed, maybe allocate a new buffer for further data.
60 virtual bool OnReadCompleted(int bytes_read, bool* defer) OVERRIDE;
62 // Done downloading the certificate.
63 virtual void OnResponseCompleted(const net::URLRequestStatus& urs,
64 const std::string& sec_info,
65 bool* defer) OVERRIDE;
67 // N/A to cert downloading.
68 virtual void OnDataDownloaded(int bytes_downloaded) OVERRIDE;
70 private:
71 typedef std::vector<std::pair<scoped_refptr<net::IOBuffer>,
72 size_t> > ContentVector;
74 void AssembleResource();
76 GURL url_;
77 size_t content_length_;
78 ContentVector buffer_;
79 scoped_refptr<net::IOBuffer> read_buffer_;
80 scoped_refptr<net::IOBuffer> resource_buffer_; // Downloaded certificate.
81 net::CertificateMimeType cert_type_;
82 DISALLOW_COPY_AND_ASSIGN(CertificateResourceHandler);
85 } // namespace content
87 #endif // CONTENT_BROWSER_LOADER_CERTIFICATE_RESOURCE_HANDLER_H_