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

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: Create Dictionary JSON directly in SdchManager::SdchInfoToValue Created 6 years, 4 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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "net/base/load_flags.h" 10 #include "net/base/load_flags.h"
11 #include "net/base/sdch_net_log_params.h"
11 #include "net/url_request/url_fetcher.h" 12 #include "net/url_request/url_fetcher.h"
13 #include "net/url_request/url_request_context.h"
12 #include "net/url_request/url_request_context_getter.h" 14 #include "net/url_request/url_request_context_getter.h"
13 #include "net/url_request/url_request_status.h" 15 #include "net/url_request/url_request_status.h"
14 16
15 namespace net { 17 namespace net {
16 18
17 SdchDictionaryFetcher::SdchDictionaryFetcher( 19 SdchDictionaryFetcher::SdchDictionaryFetcher(SdchManager* manager,
18 SdchManager* manager, 20 URLRequestContextGetter* context)
19 URLRequestContextGetter* context)
20 : manager_(manager), 21 : manager_(manager),
21 weak_factory_(this), 22 weak_factory_(this),
22 task_is_pending_(false), 23 task_is_pending_(false),
23 context_(context) { 24 context_(context),
25 net_log_(BoundNetLog::Make(context_->GetURLRequestContext()->net_log(),
26 NetLog::SOURCE_SDCH_DICTIONARY_FETCHER)) {
24 DCHECK(CalledOnValidThread()); 27 DCHECK(CalledOnValidThread());
25 DCHECK(manager); 28 DCHECK(manager);
26 } 29 }
27 30
28 SdchDictionaryFetcher::~SdchDictionaryFetcher() { 31 SdchDictionaryFetcher::~SdchDictionaryFetcher() {
29 DCHECK(CalledOnValidThread()); 32 DCHECK(CalledOnValidThread());
30 } 33 }
31 34
32 void SdchDictionaryFetcher::Schedule(const GURL& dictionary_url) { 35 void SdchDictionaryFetcher::Schedule(const GURL& dictionary_url) {
33 DCHECK(CalledOnValidThread()); 36 DCHECK(CalledOnValidThread());
34 37
35 // Avoid pushing duplicate copy onto queue. We may fetch this url again later 38 // Avoid pushing duplicate copy onto queue. We may fetch this url again later
36 // and get a different dictionary, but there is no reason to have it in the 39 // and get a different dictionary, but there is no reason to have it in the
37 // queue twice at one time. 40 // queue twice at one time.
38 if (!fetch_queue_.empty() && fetch_queue_.back() == dictionary_url) { 41 if (!fetch_queue_.empty() && fetch_queue_.back() == dictionary_url) {
Randy Smith (Not in Mondays) 2014/08/13 17:35:45 Huh. It looks to me like this line is in error; w
baranovich 2014/08/13 19:13:47 I think it's done more or less by purpose, since |
39 SdchManager::SdchErrorRecovery( 42 LogSdchProblem(SdchManager::DICTIONARY_ALREADY_SCHEDULED_TO_DOWNLOAD,
40 SdchManager::DICTIONARY_ALREADY_SCHEDULED_TO_DOWNLOAD); 43 dictionary_url);
Randy Smith (Not in Mondays) 2014/08/13 17:35:45 I'm not sure this counts as an error that should b
baranovich 2014/08/13 19:13:47 Done.
41 return; 44 return;
42 } 45 }
43 if (attempted_load_.find(dictionary_url) != attempted_load_.end()) { 46 if (attempted_load_.find(dictionary_url) != attempted_load_.end()) {
44 SdchManager::SdchErrorRecovery( 47 LogSdchProblem(SdchManager::DICTIONARY_ALREADY_TRIED_TO_DOWNLOAD,
45 SdchManager::DICTIONARY_ALREADY_TRIED_TO_DOWNLOAD); 48 dictionary_url);
Randy Smith (Not in Mondays) 2014/08/13 17:35:45 Similar; this could be the result of a race, and I
baranovich 2014/08/13 19:13:47 Done.
46 return; 49 return;
47 } 50 }
48 attempted_load_.insert(dictionary_url); 51 attempted_load_.insert(dictionary_url);
49 fetch_queue_.push(dictionary_url); 52 fetch_queue_.push(dictionary_url);
50 ScheduleDelayedRun(); 53 ScheduleDelayedRun();
51 } 54 }
52 55
53 void SdchDictionaryFetcher::Cancel() { 56 void SdchDictionaryFetcher::Cancel() {
54 DCHECK(CalledOnValidThread()); 57 DCHECK(CalledOnValidThread());
55 58
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 current_fetch_->Start(); 92 current_fetch_->Start();
90 } 93 }
91 94
92 void SdchDictionaryFetcher::OnURLFetchComplete( 95 void SdchDictionaryFetcher::OnURLFetchComplete(
93 const URLFetcher* source) { 96 const URLFetcher* source) {
94 DCHECK(CalledOnValidThread()); 97 DCHECK(CalledOnValidThread());
95 if ((200 == source->GetResponseCode()) && 98 if ((200 == source->GetResponseCode()) &&
96 (source->GetStatus().status() == URLRequestStatus::SUCCESS)) { 99 (source->GetStatus().status() == URLRequestStatus::SUCCESS)) {
97 std::string data; 100 std::string data;
98 source->GetResponseAsString(&data); 101 source->GetResponseAsString(&data);
99 manager_->AddSdchDictionary(data, source->GetURL()); 102 SdchManager::ProblemCodes problem;
103 manager_->AddSdchDictionary(data, source->GetURL(), &problem);
104 if (problem != SdchManager::PROBLEM_CODE_OK)
105 LogSdchProblem(problem, source->GetURL());
Randy Smith (Not in Mondays) 2014/08/13 17:35:45 I'm a bit uncomfortable with the implication of th
baranovich 2014/08/13 18:38:58 PROBLEM_CODE_OK may be even if we haven't added th
Randy Smith (Not in Mondays) 2014/08/19 19:00:53 As noted in my other comment, I think we're ok add
100 } 106 }
101 current_fetch_.reset(NULL); 107 current_fetch_.reset(NULL);
102 ScheduleDelayedRun(); 108 ScheduleDelayedRun();
103 } 109 }
104 110
111 void SdchDictionaryFetcher::LogSdchProblem(SdchManager::ProblemCodes problem,
112 GURL url) const {
113 SdchManager::SdchErrorRecovery(problem);
114 net_log_.AddEvent(
115 NetLog::TYPE_SDCH_DICTIONARY_FETCH_ERROR,
116 base::Bind(&NetLogSdchDictionaryFetchProblemCallback, problem, &url));
117 }
118
105 } // namespace net 119 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698