| 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 | 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/profiler/scoped_tracker.h" |
| 12 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
| 13 #include "net/base/load_flags.h" | 14 #include "net/base/load_flags.h" |
| 14 #include "net/url_request/url_request_context.h" | 15 #include "net/url_request/url_request_context.h" |
| 15 #include "net/url_request/url_request_status.h" | 16 #include "net/url_request/url_request_status.h" |
| 16 #include "net/url_request/url_request_throttler_manager.h" | 17 #include "net/url_request/url_request_throttler_manager.h" |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 const int kBufferSize = 4096; | 21 const int kBufferSize = 4096; |
| 21 | 22 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 while (!fetch_queue_.empty()) | 75 while (!fetch_queue_.empty()) |
| 75 fetch_queue_.pop(); | 76 fetch_queue_.pop(); |
| 76 attempted_load_.clear(); | 77 attempted_load_.clear(); |
| 77 weak_factory_.InvalidateWeakPtrs(); | 78 weak_factory_.InvalidateWeakPtrs(); |
| 78 current_request_.reset(NULL); | 79 current_request_.reset(NULL); |
| 79 buffer_ = NULL; | 80 buffer_ = NULL; |
| 80 dictionary_.clear(); | 81 dictionary_.clear(); |
| 81 } | 82 } |
| 82 | 83 |
| 83 void SdchDictionaryFetcher::OnResponseStarted(URLRequest* request) { | 84 void SdchDictionaryFetcher::OnResponseStarted(URLRequest* request) { |
| 85 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed. |
| 86 tracked_objects::ScopedTracker tracking_profile( |
| 87 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 88 "423948 SdchDictionaryFetcher::OnResponseStarted")); |
| 89 |
| 84 DCHECK(CalledOnValidThread()); | 90 DCHECK(CalledOnValidThread()); |
| 85 DCHECK_EQ(request, current_request_.get()); | 91 DCHECK_EQ(request, current_request_.get()); |
| 86 DCHECK_EQ(next_state_, STATE_REQUEST_STARTED); | 92 DCHECK_EQ(next_state_, STATE_REQUEST_STARTED); |
| 87 | 93 |
| 88 // The response has started, so the stream can be read from. | 94 // The response has started, so the stream can be read from. |
| 89 next_state_ = STATE_REQUEST_READING; | 95 next_state_ = STATE_REQUEST_READING; |
| 90 | 96 |
| 91 // If this function was synchronously called, the containing | 97 // If this function was synchronously called, the containing |
| 92 // state machine loop will handle the state transition. Otherwise, | 98 // state machine loop will handle the state transition. Otherwise, |
| 93 // restart the state machine loop. | 99 // restart the state machine loop. |
| 94 if (in_loop_) | 100 if (in_loop_) |
| 95 return; | 101 return; |
| 96 | 102 |
| 97 DoLoop(request->status().error()); | 103 DoLoop(request->status().error()); |
| 98 } | 104 } |
| 99 | 105 |
| 100 void SdchDictionaryFetcher::OnReadCompleted(URLRequest* request, | 106 void SdchDictionaryFetcher::OnReadCompleted(URLRequest* request, |
| 101 int bytes_read) { | 107 int bytes_read) { |
| 108 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed. |
| 109 tracked_objects::ScopedTracker tracking_profile( |
| 110 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 111 "423948 SdchDictionaryFetcher::OnReadCompleted")); |
| 112 |
| 102 DCHECK(CalledOnValidThread()); | 113 DCHECK(CalledOnValidThread()); |
| 103 DCHECK_EQ(request, current_request_.get()); | 114 DCHECK_EQ(request, current_request_.get()); |
| 104 DCHECK_EQ(next_state_, STATE_REQUEST_READING); | 115 DCHECK_EQ(next_state_, STATE_REQUEST_READING); |
| 105 | 116 |
| 106 // No state transition is required in this function; the | 117 // No state transition is required in this function; the |
| 107 // completion of the request is detected in DoRead(). | 118 // completion of the request is detected in DoRead(). |
| 108 | 119 |
| 109 if (request->status().is_success()) | 120 if (request->status().is_success()) |
| 110 dictionary_.append(buffer_->data(), bytes_read); | 121 dictionary_.append(buffer_->data(), bytes_read); |
| 111 | 122 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 current_request_.reset(); | 245 current_request_.reset(); |
| 235 buffer_ = NULL; | 246 buffer_ = NULL; |
| 236 dictionary_.clear(); | 247 dictionary_.clear(); |
| 237 | 248 |
| 238 next_state_ = STATE_IDLE; | 249 next_state_ = STATE_IDLE; |
| 239 | 250 |
| 240 return OK; | 251 return OK; |
| 241 } | 252 } |
| 242 | 253 |
| 243 } // namespace net | 254 } // namespace net |
| OLD | NEW |