Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / content / browser / service_worker / service_worker_read_from_cache_job.h
1 // Copyright 2014 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.
4
5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_READ_FROM_CACHE_JOB_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_READ_FROM_CACHE_JOB_
7
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/weak_ptr.h"
10 #include "content/browser/service_worker/service_worker_disk_cache.h"
11 #include "content/common/content_export.h"
12 #include "net/http/http_byte_range.h"
13 #include "net/url_request/url_request_job.h"
14
15 namespace content {
16
17 class ServiceWorkerContextCore;
18 class ServiceWorkerResponseReader;
19
20 // A URLRequestJob derivative used to retrieve script resources
21 // from the service workers script cache. It uses a response reader
22 // and pipes the response to the consumer of this url request job.
23 class CONTENT_EXPORT ServiceWorkerReadFromCacheJob
24     : public net::URLRequestJob {
25  public:
26   ServiceWorkerReadFromCacheJob(
27       net::URLRequest* request,
28       net::NetworkDelegate* network_delegate,
29       base::WeakPtr<ServiceWorkerContextCore> context,
30       int64 response_id);
31
32  private:
33   virtual ~ServiceWorkerReadFromCacheJob();
34
35   // net::URLRequestJob overrides
36   virtual void Start() OVERRIDE;
37   virtual void Kill() OVERRIDE;
38   virtual net::LoadState GetLoadState() const OVERRIDE;
39   virtual bool GetCharset(std::string* charset) OVERRIDE;
40   virtual bool GetMimeType(std::string* mime_type) const OVERRIDE;
41   virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE;
42   virtual int GetResponseCode() const OVERRIDE;
43   virtual void SetExtraRequestHeaders(
44       const net::HttpRequestHeaders& headers) OVERRIDE;
45   virtual bool ReadRawData(net::IOBuffer* buf,
46                            int buf_size,
47                            int *bytes_read) OVERRIDE;
48
49   // Reader completion callbacks.
50   void OnReadInfoComplete(int result);
51   void OnReadComplete(int result);
52
53   // Helpers
54   const net::HttpResponseInfo* http_info() const;
55   bool is_range_request() const { return range_requested_.IsValid(); }
56   void SetupRangeResponse(int response_data_size);
57
58   base::WeakPtr<ServiceWorkerContextCore> context_;
59   int64 response_id_;
60   scoped_ptr<ServiceWorkerResponseReader> reader_;
61   scoped_refptr<HttpResponseInfoIOBuffer> http_info_io_buffer_;
62   scoped_ptr<net::HttpResponseInfo> http_info_;
63   net::HttpByteRange range_requested_;
64   scoped_ptr<net::HttpResponseInfo> range_response_info_;
65   bool has_been_killed_;
66   base::WeakPtrFactory<ServiceWorkerReadFromCacheJob> weak_factory_;
67
68   DISALLOW_COPY_AND_ASSIGN(ServiceWorkerReadFromCacheJob);
69 };
70
71 }  // namespace content
72
73 #endif  // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_READ_FROM_CACHE_JOB_