OLD | NEW |
1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2017 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 #include "content/browser/appcache/appcache_job.h" | 5 #include "content/browser/appcache/appcache_job.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "content/browser/appcache/appcache_request.h" | 8 #include "content/browser/appcache/appcache_request.h" |
9 #include "content/browser/appcache/appcache_url_loader_job.h" | 9 #include "content/browser/appcache/appcache_url_loader_job.h" |
10 #include "content/browser/appcache/appcache_url_request_job.h" | 10 #include "content/browser/appcache/appcache_url_request_job.h" |
11 | 11 |
12 #include "content/public/common/content_switches.h" | 12 #include "content/public/common/content_switches.h" |
13 | 13 |
14 namespace content { | 14 namespace content { |
15 | 15 |
16 std::unique_ptr<AppCacheJob> AppCacheJob::Create( | 16 std::unique_ptr<AppCacheJob> AppCacheJob::Create( |
17 bool is_main_resource, | 17 bool is_main_resource, |
18 AppCacheHost* host, | 18 AppCacheHost* host, |
19 AppCacheStorage* storage, | 19 AppCacheStorage* storage, |
20 AppCacheRequest* request, | 20 AppCacheRequest* request, |
21 net::NetworkDelegate* network_delegate, | 21 net::NetworkDelegate* network_delegate, |
22 const OnPrepareToRestartCallback& restart_callback) { | 22 const OnPrepareToRestartCallback& restart_callback) { |
23 std::unique_ptr<AppCacheJob> job; | 23 std::unique_ptr<AppCacheJob> job; |
24 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 24 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
25 switches::kEnableNetworkService)) { | 25 switches::kEnableNetworkService)) { |
26 job.reset(new AppCacheURLLoaderJob); | 26 job.reset( |
| 27 new AppCacheURLLoaderJob(*(request->GetResourceRequest()), storage)); |
27 } else { | 28 } else { |
28 job.reset(new AppCacheURLRequestJob(request->GetURLRequest(), | 29 job.reset(new AppCacheURLRequestJob(request->GetURLRequest(), |
29 network_delegate, storage, host, | 30 network_delegate, storage, host, |
30 is_main_resource, restart_callback)); | 31 is_main_resource, restart_callback)); |
31 } | 32 } |
32 return job; | 33 return job; |
33 } | 34 } |
34 | 35 |
35 AppCacheJob::~AppCacheJob() { | 36 AppCacheJob::~AppCacheJob() { |
36 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | 37 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
37 } | 38 } |
38 | 39 |
| 40 bool AppCacheJob::IsWaiting() const { |
| 41 return delivery_type_ == AWAITING_DELIVERY_ORDERS; |
| 42 } |
| 43 |
| 44 bool AppCacheJob::IsDeliveringAppCacheResponse() const { |
| 45 return delivery_type_ == APPCACHED_DELIVERY; |
| 46 } |
| 47 |
| 48 bool AppCacheJob::IsDeliveringNetworkResponse() const { |
| 49 return delivery_type_ == NETWORK_DELIVERY; |
| 50 } |
| 51 |
| 52 bool AppCacheJob::IsDeliveringErrorResponse() const { |
| 53 return delivery_type_ == ERROR_DELIVERY; |
| 54 } |
| 55 |
| 56 bool AppCacheJob::IsCacheEntryNotFound() const { |
| 57 return cache_entry_not_found_; |
| 58 } |
| 59 |
39 base::WeakPtr<AppCacheJob> AppCacheJob::GetWeakPtr() { | 60 base::WeakPtr<AppCacheJob> AppCacheJob::GetWeakPtr() { |
40 return weak_factory_.GetWeakPtr(); | 61 return weak_factory_.GetWeakPtr(); |
41 } | 62 } |
42 | 63 |
43 net::URLRequestJob* AppCacheJob::AsURLRequestJob() { | 64 net::URLRequestJob* AppCacheJob::AsURLRequestJob() { |
44 return nullptr; | 65 return nullptr; |
45 } | 66 } |
46 | 67 |
47 AppCacheURLLoaderJob* AppCacheJob::AsURLLoaderJob() { | 68 AppCacheURLLoaderJob* AppCacheJob::AsURLLoaderJob() { |
48 return nullptr; | 69 return nullptr; |
49 } | 70 } |
50 | 71 |
51 AppCacheJob::AppCacheJob() : weak_factory_(this) {} | 72 AppCacheJob::AppCacheJob() |
| 73 : cache_entry_not_found_(false), |
| 74 delivery_type_(AWAITING_DELIVERY_ORDERS), |
| 75 weak_factory_(this) {} |
52 | 76 |
53 } // namespace content | 77 } // namespace content |
OLD | NEW |