Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(721)

Side by Side Diff: net/base/sdch_dictionary_fetcher.cc

Issue 423813002: Sdch view for net-internals (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adopt logging for URLReqest-based dict fetcher + cosmetics Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/base/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"
(...skipping 22 matching lines...) Expand all
33 weak_factory_(this) { 33 weak_factory_(this) {
34 DCHECK(CalledOnValidThread()); 34 DCHECK(CalledOnValidThread());
35 DCHECK(consumer); 35 DCHECK(consumer);
36 DCHECK(context); 36 DCHECK(context);
37 } 37 }
38 38
39 SdchDictionaryFetcher::~SdchDictionaryFetcher() { 39 SdchDictionaryFetcher::~SdchDictionaryFetcher() {
40 DCHECK(CalledOnValidThread()); 40 DCHECK(CalledOnValidThread());
41 } 41 }
42 42
43 void SdchDictionaryFetcher::Schedule(const GURL& dictionary_url) { 43 SdchFetcher::ScheduleResult SdchDictionaryFetcher::Schedule(
44 const GURL& dictionary_url) {
44 DCHECK(CalledOnValidThread()); 45 DCHECK(CalledOnValidThread());
45 46
46 // Avoid pushing duplicate copy onto queue. We may fetch this url again later 47 // Avoid pushing duplicate copy onto queue. We may fetch this url again later
47 // and get a different dictionary, but there is no reason to have it in the 48 // and get a different dictionary, but there is no reason to have it in the
48 // queue twice at one time. 49 // queue twice at one time.
49 if (!fetch_queue_.empty() && fetch_queue_.back() == dictionary_url) { 50 if (!fetch_queue_.empty() && fetch_queue_.back() == dictionary_url)
50 SdchManager::SdchErrorRecovery( 51 return ALREADY_SCHEDULED;
51 SdchManager::DICTIONARY_ALREADY_SCHEDULED_TO_DOWNLOAD); 52
52 return; 53 if (attempted_load_.find(dictionary_url) != attempted_load_.end())
53 } 54 return ALREADY_TRIED;
54 if (attempted_load_.find(dictionary_url) != attempted_load_.end()) { 55
55 SdchManager::SdchErrorRecovery(
56 SdchManager::DICTIONARY_ALREADY_TRIED_TO_DOWNLOAD);
57 return;
58 }
59 attempted_load_.insert(dictionary_url); 56 attempted_load_.insert(dictionary_url);
60 fetch_queue_.push(dictionary_url); 57 fetch_queue_.push(dictionary_url);
61 58
62 next_state_ = STATE_IDLE; 59 next_state_ = STATE_IDLE;
63 60
64 // There are no callbacks to user code from the dictionary fetcher, 61 // There are no callbacks to user code from the dictionary fetcher,
65 // and Schedule() is only called from user code, so this call to DoLoop() 62 // and Schedule() is only called from user code, so this call to DoLoop()
66 // does not require an |if (in_loop_) return;| guard. 63 // does not require an |if (in_loop_) return;| guard.
67 DoLoop(OK); 64 DoLoop(OK);
65
66 return SCHEDULE_OK;
68 } 67 }
69 68
70 void SdchDictionaryFetcher::Cancel() { 69 void SdchDictionaryFetcher::Cancel() {
71 DCHECK(CalledOnValidThread()); 70 DCHECK(CalledOnValidThread());
72 71
73 next_state_ = STATE_NONE; 72 next_state_ = STATE_NONE;
74 73
75 while (!fetch_queue_.empty()) 74 while (!fetch_queue_.empty())
76 fetch_queue_.pop(); 75 fetch_queue_.pop();
77 attempted_load_.clear(); 76 attempted_load_.clear();
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 154
156 if (fetch_queue_.empty() || current_request_.get()) { 155 if (fetch_queue_.empty() || current_request_.get()) {
157 next_state_ = STATE_NONE; 156 next_state_ = STATE_NONE;
158 return OK; 157 return OK;
159 } 158 }
160 159
161 current_request_ = context_->CreateRequest( 160 current_request_ = context_->CreateRequest(
162 fetch_queue_.front(), IDLE, this, NULL); 161 fetch_queue_.front(), IDLE, this, NULL);
163 current_request_->SetLoadFlags(LOAD_DO_NOT_SEND_COOKIES | 162 current_request_->SetLoadFlags(LOAD_DO_NOT_SEND_COOKIES |
164 LOAD_DO_NOT_SAVE_COOKIES); 163 LOAD_DO_NOT_SAVE_COOKIES);
164 current_request_->net_log().AddEvent(NetLog::TYPE_SDCH_DICTIONARY_FETCH);
165 buffer_ = new IOBuffer(kBufferSize); 165 buffer_ = new IOBuffer(kBufferSize);
166 fetch_queue_.pop(); 166 fetch_queue_.pop();
167 167
168 next_state_ = STATE_REQUEST_STARTED; 168 next_state_ = STATE_REQUEST_STARTED;
169 current_request_->Start(); 169 current_request_->Start();
170 170
171 return OK; 171 return OK;
172 } 172 }
173 173
174 int SdchDictionaryFetcher::DoRequestStarted(int rv) { 174 int SdchDictionaryFetcher::DoRequestStarted(int rv) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 next_state_ = STATE_REQUEST_COMPLETE; 214 next_state_ = STATE_REQUEST_COMPLETE;
215 215
216 return OK; 216 return OK;
217 } 217 }
218 218
219 int SdchDictionaryFetcher::DoCompleteRequest(int rv) { 219 int SdchDictionaryFetcher::DoCompleteRequest(int rv) {
220 DCHECK(CalledOnValidThread()); 220 DCHECK(CalledOnValidThread());
221 221
222 // If the dictionary was successfully fetched, add it to the manager. 222 // If the dictionary was successfully fetched, add it to the manager.
223 if (rv == OK) 223 if (rv == OK)
224 consumer_->AddSdchDictionary(dictionary_, current_request_->url()); 224 consumer_->AddSdchDictionary(
225 dictionary_, current_request_->url(), current_request_->net_log());
225 226
226 current_request_.reset(); 227 current_request_.reset();
227 buffer_ = NULL; 228 buffer_ = NULL;
228 dictionary_.clear(); 229 dictionary_.clear();
229 230
230 next_state_ = STATE_IDLE; 231 next_state_ = STATE_IDLE;
231 232
232 return OK; 233 return OK;
233 } 234 }
234 235
235 } // namespace net 236 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698