| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/net/sdch_dictionary_fetcher.h" | 5 #include "chrome/browser/net/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.h" | 9 #include "base/message_loop.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "content/public/common/url_fetcher.h" | 11 #include "content/public/common/url_fetcher.h" |
| 12 #include "net/url_request/url_request_status.h" | 12 #include "net/url_request/url_request_status.h" |
| 13 | 13 |
| 14 SdchDictionaryFetcher::SdchDictionaryFetcher() | 14 SdchDictionaryFetcher::SdchDictionaryFetcher() |
| 15 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 15 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
| 16 task_is_pending_(false) { | 16 task_is_pending_(false) { |
| 17 DCHECK(CalledOnValidThread()); |
| 17 } | 18 } |
| 18 | 19 |
| 19 SdchDictionaryFetcher::~SdchDictionaryFetcher() { | 20 SdchDictionaryFetcher::~SdchDictionaryFetcher() { |
| 21 DCHECK(CalledOnValidThread()); |
| 20 } | 22 } |
| 21 | 23 |
| 22 // static | 24 // static |
| 23 void SdchDictionaryFetcher::Shutdown() { | 25 void SdchDictionaryFetcher::Shutdown() { |
| 24 net::SdchManager::Shutdown(); | 26 net::SdchManager::Shutdown(); |
| 25 } | 27 } |
| 26 | 28 |
| 27 void SdchDictionaryFetcher::Schedule(const GURL& dictionary_url) { | 29 void SdchDictionaryFetcher::Schedule(const GURL& dictionary_url) { |
| 30 DCHECK(CalledOnValidThread()); |
| 31 |
| 28 // Avoid pushing duplicate copy onto queue. We may fetch this url again later | 32 // Avoid pushing duplicate copy onto queue. We may fetch this url again later |
| 29 // and get a different dictionary, but there is no reason to have it in the | 33 // and get a different dictionary, but there is no reason to have it in the |
| 30 // queue twice at one time. | 34 // queue twice at one time. |
| 31 if (!fetch_queue_.empty() && fetch_queue_.back() == dictionary_url) { | 35 if (!fetch_queue_.empty() && fetch_queue_.back() == dictionary_url) { |
| 32 net::SdchManager::SdchErrorRecovery( | 36 net::SdchManager::SdchErrorRecovery( |
| 33 net::SdchManager::DICTIONARY_ALREADY_SCHEDULED_TO_DOWNLOAD); | 37 net::SdchManager::DICTIONARY_ALREADY_SCHEDULED_TO_DOWNLOAD); |
| 34 return; | 38 return; |
| 35 } | 39 } |
| 36 if (attempted_load_.find(dictionary_url) != attempted_load_.end()) { | 40 if (attempted_load_.find(dictionary_url) != attempted_load_.end()) { |
| 37 net::SdchManager::SdchErrorRecovery( | 41 net::SdchManager::SdchErrorRecovery( |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 const content::URLFetcher* source) { | 82 const content::URLFetcher* source) { |
| 79 if ((200 == source->GetResponseCode()) && | 83 if ((200 == source->GetResponseCode()) && |
| 80 (source->GetStatus().status() == net::URLRequestStatus::SUCCESS)) { | 84 (source->GetStatus().status() == net::URLRequestStatus::SUCCESS)) { |
| 81 std::string data; | 85 std::string data; |
| 82 source->GetResponseAsString(&data); | 86 source->GetResponseAsString(&data); |
| 83 net::SdchManager::Global()->AddSdchDictionary(data, source->GetURL()); | 87 net::SdchManager::Global()->AddSdchDictionary(data, source->GetURL()); |
| 84 } | 88 } |
| 85 current_fetch_.reset(NULL); | 89 current_fetch_.reset(NULL); |
| 86 ScheduleDelayedRun(); | 90 ScheduleDelayedRun(); |
| 87 } | 91 } |
| OLD | NEW |