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

Side by Side Diff: chrome/browser/net/sdch_dictionary_fetcher.cc

Issue 321283002: Clear SDCH information on "Clear browsing data" path. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: New patch vs. master rather than dependent branch. 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/net/sdch_dictionary_fetcher.h ('k') | net/base/sdch_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 if (attempted_load_.find(dictionary_url) != attempted_load_.end()) { 42 if (attempted_load_.find(dictionary_url) != attempted_load_.end()) {
43 net::SdchManager::SdchErrorRecovery( 43 net::SdchManager::SdchErrorRecovery(
44 net::SdchManager::DICTIONARY_ALREADY_TRIED_TO_DOWNLOAD); 44 net::SdchManager::DICTIONARY_ALREADY_TRIED_TO_DOWNLOAD);
45 return; 45 return;
46 } 46 }
47 attempted_load_.insert(dictionary_url); 47 attempted_load_.insert(dictionary_url);
48 fetch_queue_.push(dictionary_url); 48 fetch_queue_.push(dictionary_url);
49 ScheduleDelayedRun(); 49 ScheduleDelayedRun();
50 } 50 }
51 51
52 void SdchDictionaryFetcher::Cancel() {
53 DCHECK(CalledOnValidThread());
54
55 while (!fetch_queue_.empty())
56 fetch_queue_.pop();
57 attempted_load_.clear();
58 weak_factory_.InvalidateWeakPtrs();
59 current_fetch_.reset(NULL);
60 }
61
52 void SdchDictionaryFetcher::ScheduleDelayedRun() { 62 void SdchDictionaryFetcher::ScheduleDelayedRun() {
53 if (fetch_queue_.empty() || current_fetch_.get() || task_is_pending_) 63 if (fetch_queue_.empty() || current_fetch_.get() || task_is_pending_)
54 return; 64 return;
55 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, 65 base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
56 base::Bind(&SdchDictionaryFetcher::StartFetching, 66 base::Bind(&SdchDictionaryFetcher::StartFetching,
57 weak_factory_.GetWeakPtr()), 67 weak_factory_.GetWeakPtr()),
58 base::TimeDelta::FromMilliseconds(kMsDelayFromRequestTillDownload)); 68 base::TimeDelta::FromMilliseconds(kMsDelayFromRequestTillDownload));
59 task_is_pending_ = true; 69 task_is_pending_ = true;
60 } 70 }
61 71
62 void SdchDictionaryFetcher::StartFetching() { 72 void SdchDictionaryFetcher::StartFetching() {
63 DCHECK(CalledOnValidThread()); 73 DCHECK(CalledOnValidThread());
64 DCHECK(task_is_pending_); 74 DCHECK(task_is_pending_);
65 task_is_pending_ = false; 75 task_is_pending_ = false;
jar (doing other things) 2014/06/16 18:55:04 Now that there is a Cancel() method, there seems t
Randy Smith (Not in Mondays) 2014/06/16 19:46:25 Whoops. Thanks for catching that. Done.
66 76
67 DCHECK(context_.get()); 77 DCHECK(context_.get());
68 current_fetch_.reset(net::URLFetcher::Create( 78 current_fetch_.reset(net::URLFetcher::Create(
69 fetch_queue_.front(), net::URLFetcher::GET, this)); 79 fetch_queue_.front(), net::URLFetcher::GET, this));
70 fetch_queue_.pop(); 80 fetch_queue_.pop();
71 current_fetch_->SetRequestContext(context_.get()); 81 current_fetch_->SetRequestContext(context_.get());
72 current_fetch_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | 82 current_fetch_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
73 net::LOAD_DO_NOT_SAVE_COOKIES); 83 net::LOAD_DO_NOT_SAVE_COOKIES);
74 current_fetch_->Start(); 84 current_fetch_->Start();
75 } 85 }
76 86
77 void SdchDictionaryFetcher::OnURLFetchComplete( 87 void SdchDictionaryFetcher::OnURLFetchComplete(
78 const net::URLFetcher* source) { 88 const net::URLFetcher* source) {
79 DCHECK(CalledOnValidThread()); 89 DCHECK(CalledOnValidThread());
80 if ((200 == source->GetResponseCode()) && 90 if ((200 == source->GetResponseCode()) &&
81 (source->GetStatus().status() == net::URLRequestStatus::SUCCESS)) { 91 (source->GetStatus().status() == net::URLRequestStatus::SUCCESS)) {
82 std::string data; 92 std::string data;
83 source->GetResponseAsString(&data); 93 source->GetResponseAsString(&data);
84 manager_->AddSdchDictionary(data, source->GetURL()); 94 manager_->AddSdchDictionary(data, source->GetURL());
85 } 95 }
86 current_fetch_.reset(NULL); 96 current_fetch_.reset(NULL);
87 ScheduleDelayedRun(); 97 ScheduleDelayedRun();
88 } 98 }
OLDNEW
« no previous file with comments | « chrome/browser/net/sdch_dictionary_fetcher.h ('k') | net/base/sdch_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698