| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 return; | 47 return; |
| 48 } | 48 } |
| 49 attempted_load_.insert(dictionary_url); | 49 attempted_load_.insert(dictionary_url); |
| 50 fetch_queue_.push(dictionary_url); | 50 fetch_queue_.push(dictionary_url); |
| 51 ScheduleDelayedRun(); | 51 ScheduleDelayedRun(); |
| 52 } | 52 } |
| 53 | 53 |
| 54 void SdchDictionaryFetcher::ScheduleDelayedRun() { | 54 void SdchDictionaryFetcher::ScheduleDelayedRun() { |
| 55 if (fetch_queue_.empty() || current_fetch_.get() || task_is_pending_) | 55 if (fetch_queue_.empty() || current_fetch_.get() || task_is_pending_) |
| 56 return; | 56 return; |
| 57 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 57 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 58 base::Bind(&SdchDictionaryFetcher::StartFetching, | 58 base::Bind(&SdchDictionaryFetcher::StartFetching, |
| 59 weak_factory_.GetWeakPtr()), | 59 weak_factory_.GetWeakPtr()), |
| 60 base::TimeDelta::FromMilliseconds(kMsDelayFromRequestTillDownload)); | 60 base::TimeDelta::FromMilliseconds(kMsDelayFromRequestTillDownload)); |
| 61 task_is_pending_ = true; | 61 task_is_pending_ = true; |
| 62 } | 62 } |
| 63 | 63 |
| 64 void SdchDictionaryFetcher::StartFetching() { | 64 void SdchDictionaryFetcher::StartFetching() { |
| 65 DCHECK(task_is_pending_); | 65 DCHECK(task_is_pending_); |
| 66 task_is_pending_ = false; | 66 task_is_pending_ = false; |
| 67 | 67 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 79 const net::URLFetcher* source) { | 79 const net::URLFetcher* source) { |
| 80 if ((200 == source->GetResponseCode()) && | 80 if ((200 == source->GetResponseCode()) && |
| 81 (source->GetStatus().status() == net::URLRequestStatus::SUCCESS)) { | 81 (source->GetStatus().status() == net::URLRequestStatus::SUCCESS)) { |
| 82 std::string data; | 82 std::string data; |
| 83 source->GetResponseAsString(&data); | 83 source->GetResponseAsString(&data); |
| 84 net::SdchManager::Global()->AddSdchDictionary(data, source->GetURL()); | 84 net::SdchManager::Global()->AddSdchDictionary(data, source->GetURL()); |
| 85 } | 85 } |
| 86 current_fetch_.reset(NULL); | 86 current_fetch_.reset(NULL); |
| 87 ScheduleDelayedRun(); | 87 ScheduleDelayedRun(); |
| 88 } | 88 } |
| OLD | NEW |