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

Unified Diff: chrome/browser/net/sdch_dictionary_fetcher.cc

Issue 341553005: Move of SdchDictionaryFetcher to net. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync'd to r278311. Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/net/sdch_dictionary_fetcher.cc
diff --git a/chrome/browser/net/sdch_dictionary_fetcher.cc b/chrome/browser/net/sdch_dictionary_fetcher.cc
deleted file mode 100644
index 0a838bd37fa9adb86be501707f81888b9f30e66b..0000000000000000000000000000000000000000
--- a/chrome/browser/net/sdch_dictionary_fetcher.cc
+++ /dev/null
@@ -1,102 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/net/sdch_dictionary_fetcher.h"
-
-#include "base/bind.h"
-#include "base/compiler_specific.h"
-#include "base/message_loop/message_loop.h"
-#include "chrome/browser/profiles/profile.h"
-#include "net/base/load_flags.h"
-#include "net/url_request/url_fetcher.h"
-#include "net/url_request/url_request_context_getter.h"
-#include "net/url_request/url_request_status.h"
-
-SdchDictionaryFetcher::SdchDictionaryFetcher(
- net::SdchManager* manager,
- net::URLRequestContextGetter* context)
- : manager_(manager),
- weak_factory_(this),
- task_is_pending_(false),
- context_(context) {
- DCHECK(CalledOnValidThread());
- DCHECK(manager);
-}
-
-SdchDictionaryFetcher::~SdchDictionaryFetcher() {
- DCHECK(CalledOnValidThread());
-}
-
-void SdchDictionaryFetcher::Schedule(const GURL& dictionary_url) {
- DCHECK(CalledOnValidThread());
-
- // Avoid pushing duplicate copy onto queue. We may fetch this url again later
- // and get a different dictionary, but there is no reason to have it in the
- // queue twice at one time.
- if (!fetch_queue_.empty() && fetch_queue_.back() == dictionary_url) {
- net::SdchManager::SdchErrorRecovery(
- net::SdchManager::DICTIONARY_ALREADY_SCHEDULED_TO_DOWNLOAD);
- return;
- }
- if (attempted_load_.find(dictionary_url) != attempted_load_.end()) {
- net::SdchManager::SdchErrorRecovery(
- net::SdchManager::DICTIONARY_ALREADY_TRIED_TO_DOWNLOAD);
- return;
- }
- attempted_load_.insert(dictionary_url);
- fetch_queue_.push(dictionary_url);
- ScheduleDelayedRun();
-}
-
-void SdchDictionaryFetcher::Cancel() {
- DCHECK(CalledOnValidThread());
-
- while (!fetch_queue_.empty())
- fetch_queue_.pop();
- attempted_load_.clear();
- weak_factory_.InvalidateWeakPtrs();
- current_fetch_.reset(NULL);
-}
-
-void SdchDictionaryFetcher::ScheduleDelayedRun() {
- if (fetch_queue_.empty() || current_fetch_.get() || task_is_pending_)
- return;
- base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
- base::Bind(&SdchDictionaryFetcher::StartFetching,
- weak_factory_.GetWeakPtr()),
- base::TimeDelta::FromMilliseconds(kMsDelayFromRequestTillDownload));
- task_is_pending_ = true;
-}
-
-void SdchDictionaryFetcher::StartFetching() {
- DCHECK(CalledOnValidThread());
- DCHECK(task_is_pending_);
- task_is_pending_ = false;
-
- // Handle losing the race against Cancel().
- if (fetch_queue_.empty())
- return;
-
- DCHECK(context_.get());
- current_fetch_.reset(net::URLFetcher::Create(
- fetch_queue_.front(), net::URLFetcher::GET, this));
- fetch_queue_.pop();
- current_fetch_->SetRequestContext(context_.get());
- current_fetch_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
- net::LOAD_DO_NOT_SAVE_COOKIES);
- current_fetch_->Start();
-}
-
-void SdchDictionaryFetcher::OnURLFetchComplete(
- const net::URLFetcher* source) {
- DCHECK(CalledOnValidThread());
- if ((200 == source->GetResponseCode()) &&
- (source->GetStatus().status() == net::URLRequestStatus::SUCCESS)) {
- std::string data;
- source->GetResponseAsString(&data);
- manager_->AddSdchDictionary(data, source->GetURL());
- }
- current_fetch_.reset(NULL);
- ScheduleDelayedRun();
-}
« no previous file with comments | « chrome/browser/net/sdch_dictionary_fetcher.h ('k') | chrome/browser/profiles/off_the_record_profile_io_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698