OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "net/url_request/sdch_dictionary_fetcher.h" | 5 #include "net/url_request/sdch_dictionary_fetcher.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <queue> | 8 #include <queue> |
9 #include <set> | 9 #include <set> |
10 | 10 |
11 #include "base/auto_reset.h" | 11 #include "base/auto_reset.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
16 #include "net/base/io_buffer.h" | 16 #include "net/base/io_buffer.h" |
17 #include "net/base/load_flags.h" | 17 #include "net/base/load_flags.h" |
18 #include "net/base/sdch_net_log_params.h" | 18 #include "net/base/sdch_net_log_params.h" |
19 #include "net/http/http_response_headers.h" | 19 #include "net/http/http_response_headers.h" |
20 #include "net/log/net_log.h" | 20 #include "net/log/net_log.h" |
| 21 #include "net/log/net_log_event_type.h" |
21 #include "net/url_request/redirect_info.h" | 22 #include "net/url_request/redirect_info.h" |
22 #include "net/url_request/url_request_context.h" | 23 #include "net/url_request/url_request_context.h" |
23 #include "net/url_request/url_request_status.h" | 24 #include "net/url_request/url_request_status.h" |
24 #include "net/url_request/url_request_throttler_manager.h" | 25 #include "net/url_request/url_request_throttler_manager.h" |
25 | 26 |
26 namespace net { | 27 namespace net { |
27 | 28 |
28 namespace { | 29 namespace { |
29 | 30 |
30 const int kBufferSize = 4096; | 31 const int kBufferSize = 4096; |
31 | 32 |
32 // Map the bytes_read result from a read attempt and a URLRequest's | 33 // Map the bytes_read result from a read attempt and a URLRequest's |
33 // status into a single net return value. | 34 // status into a single net return value. |
34 int GetReadResult(int rv, const URLRequest* request) { | 35 int GetReadResult(int rv, const URLRequest* request) { |
35 DCHECK_NE(ERR_IO_PENDING, rv); | 36 DCHECK_NE(ERR_IO_PENDING, rv); |
36 | 37 |
37 if (rv < 0) { | 38 if (rv < 0) { |
38 rv = ERR_FAILED; | 39 rv = ERR_FAILED; |
39 request->net_log().AddEventWithNetErrorCode( | 40 request->net_log().AddEventWithNetErrorCode( |
40 NetLog::TYPE_SDCH_DICTIONARY_FETCH_IMPLIED_ERROR, rv); | 41 NetLogEventType::SDCH_DICTIONARY_FETCH_IMPLIED_ERROR, rv); |
41 } | 42 } |
42 | 43 |
43 return rv; | 44 return rv; |
44 } | 45 } |
45 | 46 |
46 struct FetchInfo { | 47 struct FetchInfo { |
47 FetchInfo(const GURL& url, | 48 FetchInfo(const GURL& url, |
48 bool cache_only, | 49 bool cache_only, |
49 const SdchDictionaryFetcher::OnDictionaryFetchedCallback& callback) | 50 const SdchDictionaryFetcher::OnDictionaryFetchedCallback& callback) |
50 : url(url), cache_only(cache_only), callback(callback) {} | 51 : url(url), cache_only(cache_only), callback(callback) {} |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 int load_flags = LOAD_DO_NOT_SEND_COOKIES | LOAD_DO_NOT_SAVE_COOKIES; | 284 int load_flags = LOAD_DO_NOT_SEND_COOKIES | LOAD_DO_NOT_SAVE_COOKIES; |
284 if (info.cache_only) | 285 if (info.cache_only) |
285 load_flags |= LOAD_ONLY_FROM_CACHE; | 286 load_flags |= LOAD_ONLY_FROM_CACHE; |
286 current_request_->SetLoadFlags(load_flags); | 287 current_request_->SetLoadFlags(load_flags); |
287 | 288 |
288 buffer_ = new IOBuffer(kBufferSize); | 289 buffer_ = new IOBuffer(kBufferSize); |
289 dictionary_.reset(new std::string()); | 290 dictionary_.reset(new std::string()); |
290 current_callback_ = info.callback; | 291 current_callback_ = info.callback; |
291 | 292 |
292 current_request_->Start(); | 293 current_request_->Start(); |
293 current_request_->net_log().AddEvent(NetLog::TYPE_SDCH_DICTIONARY_FETCH); | 294 current_request_->net_log().AddEvent(NetLogEventType::SDCH_DICTIONARY_FETCH); |
294 | 295 |
295 return ERR_IO_PENDING; | 296 return ERR_IO_PENDING; |
296 } | 297 } |
297 | 298 |
298 int SdchDictionaryFetcher::DoReceivedRedirect(int rv) { | 299 int SdchDictionaryFetcher::DoReceivedRedirect(int rv) { |
299 // Fetching SDCH through a redirect is forbidden; it raises possible | 300 // Fetching SDCH through a redirect is forbidden; it raises possible |
300 // security issues cross-origin, and isn't obviously useful within | 301 // security issues cross-origin, and isn't obviously useful within |
301 // an origin. | 302 // an origin. |
302 ResetRequest(); | 303 ResetRequest(); |
303 next_state_ = STATE_SEND_REQUEST; | 304 next_state_ = STATE_SEND_REQUEST; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 current_request_->net_log(), | 370 current_request_->net_log(), |
370 current_request_->was_cached()); | 371 current_request_->was_cached()); |
371 } | 372 } |
372 | 373 |
373 ResetRequest(); | 374 ResetRequest(); |
374 next_state_ = STATE_SEND_REQUEST; | 375 next_state_ = STATE_SEND_REQUEST; |
375 return OK; | 376 return OK; |
376 } | 377 } |
377 | 378 |
378 } // namespace net | 379 } // namespace net |
OLD | NEW |