| 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/base/sdch_dictionary_fetcher.h" | 5 #include "net/url_request/sdch_dictionary_fetcher.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
| 13 #include "net/base/load_flags.h" | 13 #include "net/base/load_flags.h" |
| 14 #include "net/url_request/url_request_context.h" | 14 #include "net/url_request/url_request_context.h" |
| 15 #include "net/url_request/url_request_status.h" | 15 #include "net/url_request/url_request_status.h" |
| 16 #include "net/url_request/url_request_throttler_manager.h" | 16 #include "net/url_request/url_request_throttler_manager.h" |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 const int kBufferSize = 4096; | 20 const int kBufferSize = 4096; |
| 21 | 21 |
| 22 } // namespace | 22 } // namespace |
| 23 | 23 |
| 24 namespace net { | 24 namespace net { |
| 25 | 25 |
| 26 SdchDictionaryFetcher::SdchDictionaryFetcher( | 26 SdchDictionaryFetcher::SdchDictionaryFetcher( |
| 27 SdchFetcher::Delegate* consumer, | 27 URLRequestContext* context, OnDictionaryFetchedCallback callback) |
| 28 URLRequestContext* context) | |
| 29 : next_state_(STATE_NONE), | 28 : next_state_(STATE_NONE), |
| 30 in_loop_(false), | 29 in_loop_(false), |
| 31 consumer_(consumer), | |
| 32 context_(context), | 30 context_(context), |
| 31 dictionary_fetched_callback_(callback), |
| 33 weak_factory_(this) { | 32 weak_factory_(this) { |
| 34 DCHECK(CalledOnValidThread()); | 33 DCHECK(CalledOnValidThread()); |
| 35 DCHECK(consumer); | |
| 36 DCHECK(context); | 34 DCHECK(context); |
| 37 } | 35 } |
| 38 | 36 |
| 39 SdchDictionaryFetcher::~SdchDictionaryFetcher() { | 37 SdchDictionaryFetcher::~SdchDictionaryFetcher() { |
| 40 DCHECK(CalledOnValidThread()); | 38 DCHECK(CalledOnValidThread()); |
| 41 } | 39 } |
| 42 | 40 |
| 43 void SdchDictionaryFetcher::Schedule(const GURL& dictionary_url) { | 41 void SdchDictionaryFetcher::Schedule(const GURL& dictionary_url) { |
| 44 DCHECK(CalledOnValidThread()); | 42 DCHECK(CalledOnValidThread()); |
| 45 | 43 |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 next_state_ = STATE_REQUEST_COMPLETE; | 221 next_state_ = STATE_REQUEST_COMPLETE; |
| 224 | 222 |
| 225 return OK; | 223 return OK; |
| 226 } | 224 } |
| 227 | 225 |
| 228 int SdchDictionaryFetcher::DoCompleteRequest(int rv) { | 226 int SdchDictionaryFetcher::DoCompleteRequest(int rv) { |
| 229 DCHECK(CalledOnValidThread()); | 227 DCHECK(CalledOnValidThread()); |
| 230 | 228 |
| 231 // If the dictionary was successfully fetched, add it to the manager. | 229 // If the dictionary was successfully fetched, add it to the manager. |
| 232 if (rv == OK) | 230 if (rv == OK) |
| 233 consumer_->AddSdchDictionary(dictionary_, current_request_->url()); | 231 dictionary_fetched_callback_.Run(dictionary_, current_request_->url()); |
| 234 | 232 |
| 235 current_request_.reset(); | 233 current_request_.reset(); |
| 236 buffer_ = NULL; | 234 buffer_ = NULL; |
| 237 dictionary_.clear(); | 235 dictionary_.clear(); |
| 238 | 236 |
| 239 next_state_ = STATE_IDLE; | 237 next_state_ = STATE_IDLE; |
| 240 | 238 |
| 241 return OK; | 239 return OK; |
| 242 } | 240 } |
| 243 | 241 |
| 244 } // namespace net | 242 } // namespace net |
| OLD | NEW |