| 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/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "net/url_request/url_request_status.h" | 9 #include "net/url_request/url_request_status.h" |
| 10 | 10 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 46 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 47 method_factory_.NewRunnableMethod(&SdchDictionaryFetcher::StartFetching), | 47 method_factory_.NewRunnableMethod(&SdchDictionaryFetcher::StartFetching), |
| 48 kMsDelayFromRequestTillDownload); | 48 kMsDelayFromRequestTillDownload); |
| 49 task_is_pending_ = true; | 49 task_is_pending_ = true; |
| 50 } | 50 } |
| 51 | 51 |
| 52 void SdchDictionaryFetcher::StartFetching() { | 52 void SdchDictionaryFetcher::StartFetching() { |
| 53 DCHECK(task_is_pending_); | 53 DCHECK(task_is_pending_); |
| 54 task_is_pending_ = false; | 54 task_is_pending_ = false; |
| 55 | 55 |
| 56 net::URLRequestContextGetter* context = Profile::GetDefaultRequestContext(); | 56 net::URLRequestContextGetter* context = |
| 57 Profile::Deprecated::GetDefaultRequestContext(); |
| 57 if (!context) { | 58 if (!context) { |
| 58 // Shutdown in progress. | 59 // Shutdown in progress. |
| 59 // Simulate handling of all dictionary requests by clearing queue. | 60 // Simulate handling of all dictionary requests by clearing queue. |
| 60 while (!fetch_queue_.empty()) | 61 while (!fetch_queue_.empty()) |
| 61 fetch_queue_.pop(); | 62 fetch_queue_.pop(); |
| 62 return; | 63 return; |
| 63 } | 64 } |
| 64 | 65 |
| 65 current_fetch_.reset(new URLFetcher(fetch_queue_.front(), URLFetcher::GET, | 66 current_fetch_.reset(new URLFetcher(fetch_queue_.front(), URLFetcher::GET, |
| 66 this)); | 67 this)); |
| 67 fetch_queue_.pop(); | 68 fetch_queue_.pop(); |
| 68 current_fetch_->set_request_context(context); | 69 current_fetch_->set_request_context(context); |
| 69 current_fetch_->Start(); | 70 current_fetch_->Start(); |
| 70 } | 71 } |
| 71 | 72 |
| 72 void SdchDictionaryFetcher::OnURLFetchComplete( | 73 void SdchDictionaryFetcher::OnURLFetchComplete( |
| 73 const URLFetcher* source, | 74 const URLFetcher* source, |
| 74 const GURL& url, | 75 const GURL& url, |
| 75 const net::URLRequestStatus& status, | 76 const net::URLRequestStatus& status, |
| 76 int response_code, | 77 int response_code, |
| 77 const net::ResponseCookies& cookies, | 78 const net::ResponseCookies& cookies, |
| 78 const std::string& data) { | 79 const std::string& data) { |
| 79 if ((200 == response_code) && | 80 if ((200 == response_code) && |
| 80 (status.status() == net::URLRequestStatus::SUCCESS)) { | 81 (status.status() == net::URLRequestStatus::SUCCESS)) { |
| 81 net::SdchManager::Global()->AddSdchDictionary(data, url); | 82 net::SdchManager::Global()->AddSdchDictionary(data, url); |
| 82 } | 83 } |
| 83 current_fetch_.reset(NULL); | 84 current_fetch_.reset(NULL); |
| 84 ScheduleDelayedRun(); | 85 ScheduleDelayedRun(); |
| 85 } | 86 } |
| OLD | NEW |