| 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/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 8 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 10 #include "content/public/common/url_fetcher.h" | 11 #include "content/public/common/url_fetcher.h" |
| 11 #include "net/url_request/url_request_status.h" | 12 #include "net/url_request/url_request_status.h" |
| 12 | 13 |
| 13 SdchDictionaryFetcher::SdchDictionaryFetcher() | 14 SdchDictionaryFetcher::SdchDictionaryFetcher() |
| 14 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), | 15 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
| 15 task_is_pending_(false) { | 16 task_is_pending_(false) { |
| 16 } | 17 } |
| 17 | 18 |
| 18 SdchDictionaryFetcher::~SdchDictionaryFetcher() { | 19 SdchDictionaryFetcher::~SdchDictionaryFetcher() { |
| 19 } | 20 } |
| 20 | 21 |
| 21 // static | 22 // static |
| 22 void SdchDictionaryFetcher::Shutdown() { | 23 void SdchDictionaryFetcher::Shutdown() { |
| 23 net::SdchManager::Shutdown(); | 24 net::SdchManager::Shutdown(); |
| 24 } | 25 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 39 } | 40 } |
| 40 attempted_load_.insert(dictionary_url); | 41 attempted_load_.insert(dictionary_url); |
| 41 fetch_queue_.push(dictionary_url); | 42 fetch_queue_.push(dictionary_url); |
| 42 ScheduleDelayedRun(); | 43 ScheduleDelayedRun(); |
| 43 } | 44 } |
| 44 | 45 |
| 45 void SdchDictionaryFetcher::ScheduleDelayedRun() { | 46 void SdchDictionaryFetcher::ScheduleDelayedRun() { |
| 46 if (fetch_queue_.empty() || current_fetch_.get() || task_is_pending_) | 47 if (fetch_queue_.empty() || current_fetch_.get() || task_is_pending_) |
| 47 return; | 48 return; |
| 48 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 49 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 49 method_factory_.NewRunnableMethod(&SdchDictionaryFetcher::StartFetching), | 50 base::Bind(&SdchDictionaryFetcher::StartFetching, |
| 51 weak_factory_.GetWeakPtr()), |
| 50 kMsDelayFromRequestTillDownload); | 52 kMsDelayFromRequestTillDownload); |
| 51 task_is_pending_ = true; | 53 task_is_pending_ = true; |
| 52 } | 54 } |
| 53 | 55 |
| 54 void SdchDictionaryFetcher::StartFetching() { | 56 void SdchDictionaryFetcher::StartFetching() { |
| 55 DCHECK(task_is_pending_); | 57 DCHECK(task_is_pending_); |
| 56 task_is_pending_ = false; | 58 task_is_pending_ = false; |
| 57 | 59 |
| 58 net::URLRequestContextGetter* context = | 60 net::URLRequestContextGetter* context = |
| 59 Profile::Deprecated::GetDefaultRequestContext(); | 61 Profile::Deprecated::GetDefaultRequestContext(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 76 const content::URLFetcher* source) { | 78 const content::URLFetcher* source) { |
| 77 if ((200 == source->GetResponseCode()) && | 79 if ((200 == source->GetResponseCode()) && |
| 78 (source->GetStatus().status() == net::URLRequestStatus::SUCCESS)) { | 80 (source->GetStatus().status() == net::URLRequestStatus::SUCCESS)) { |
| 79 std::string data; | 81 std::string data; |
| 80 source->GetResponseAsString(&data); | 82 source->GetResponseAsString(&data); |
| 81 net::SdchManager::Global()->AddSdchDictionary(data, source->GetURL()); | 83 net::SdchManager::Global()->AddSdchDictionary(data, source->GetURL()); |
| 82 } | 84 } |
| 83 current_fetch_.reset(NULL); | 85 current_fetch_.reset(NULL); |
| 84 ScheduleDelayedRun(); | 86 ScheduleDelayedRun(); |
| 85 } | 87 } |
| OLD | NEW |