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

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

Issue 298063006: Make SdchManager per-profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove whitespace before asterix. 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
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"
11 #include "net/base/load_flags.h" 11 #include "net/base/load_flags.h"
12 #include "net/url_request/url_fetcher.h" 12 #include "net/url_request/url_fetcher.h"
13 #include "net/url_request/url_request_context_getter.h" 13 #include "net/url_request/url_request_context_getter.h"
14 #include "net/url_request/url_request_status.h" 14 #include "net/url_request/url_request_status.h"
15 15
16 SdchDictionaryFetcher::SdchDictionaryFetcher( 16 SdchDictionaryFetcher::SdchDictionaryFetcher(
17 net::SdchManager* manager,
17 net::URLRequestContextGetter* context) 18 net::URLRequestContextGetter* context)
18 : weak_factory_(this), 19 : manager_(manager),
20 weak_factory_(this),
19 task_is_pending_(false), 21 task_is_pending_(false),
20 context_(context) { 22 context_(context) {
21 DCHECK(CalledOnValidThread()); 23 DCHECK(CalledOnValidThread());
24 DCHECK(manager);
22 } 25 }
23 26
24 SdchDictionaryFetcher::~SdchDictionaryFetcher() { 27 SdchDictionaryFetcher::~SdchDictionaryFetcher() {
25 DCHECK(CalledOnValidThread()); 28 DCHECK(CalledOnValidThread());
26 } 29 }
27 30
28 // static
29 void SdchDictionaryFetcher::Shutdown() {
30 net::SdchManager::Shutdown();
31 }
32
33 void SdchDictionaryFetcher::Schedule(const GURL& dictionary_url) { 31 void SdchDictionaryFetcher::Schedule(const GURL& dictionary_url) {
34 DCHECK(CalledOnValidThread()); 32 DCHECK(CalledOnValidThread());
35 33
36 // Avoid pushing duplicate copy onto queue. We may fetch this url again later 34 // Avoid pushing duplicate copy onto queue. We may fetch this url again later
37 // and get a different dictionary, but there is no reason to have it in the 35 // and get a different dictionary, but there is no reason to have it in the
38 // queue twice at one time. 36 // queue twice at one time.
39 if (!fetch_queue_.empty() && fetch_queue_.back() == dictionary_url) { 37 if (!fetch_queue_.empty() && fetch_queue_.back() == dictionary_url) {
40 net::SdchManager::SdchErrorRecovery( 38 net::SdchManager::SdchErrorRecovery(
41 net::SdchManager::DICTIONARY_ALREADY_SCHEDULED_TO_DOWNLOAD); 39 net::SdchManager::DICTIONARY_ALREADY_SCHEDULED_TO_DOWNLOAD);
42 return; 40 return;
(...skipping 12 matching lines...) Expand all
55 if (fetch_queue_.empty() || current_fetch_.get() || task_is_pending_) 53 if (fetch_queue_.empty() || current_fetch_.get() || task_is_pending_)
56 return; 54 return;
57 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, 55 base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
58 base::Bind(&SdchDictionaryFetcher::StartFetching, 56 base::Bind(&SdchDictionaryFetcher::StartFetching,
59 weak_factory_.GetWeakPtr()), 57 weak_factory_.GetWeakPtr()),
60 base::TimeDelta::FromMilliseconds(kMsDelayFromRequestTillDownload)); 58 base::TimeDelta::FromMilliseconds(kMsDelayFromRequestTillDownload));
61 task_is_pending_ = true; 59 task_is_pending_ = true;
62 } 60 }
63 61
64 void SdchDictionaryFetcher::StartFetching() { 62 void SdchDictionaryFetcher::StartFetching() {
63 DCHECK(CalledOnValidThread());
65 DCHECK(task_is_pending_); 64 DCHECK(task_is_pending_);
66 task_is_pending_ = false; 65 task_is_pending_ = false;
67 66
68 DCHECK(context_.get()); 67 DCHECK(context_.get());
69 current_fetch_.reset(net::URLFetcher::Create( 68 current_fetch_.reset(net::URLFetcher::Create(
70 fetch_queue_.front(), net::URLFetcher::GET, this)); 69 fetch_queue_.front(), net::URLFetcher::GET, this));
71 fetch_queue_.pop(); 70 fetch_queue_.pop();
72 current_fetch_->SetRequestContext(context_.get()); 71 current_fetch_->SetRequestContext(context_.get());
73 current_fetch_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | 72 current_fetch_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
74 net::LOAD_DO_NOT_SAVE_COOKIES); 73 net::LOAD_DO_NOT_SAVE_COOKIES);
75 current_fetch_->Start(); 74 current_fetch_->Start();
76 } 75 }
77 76
78 void SdchDictionaryFetcher::OnURLFetchComplete( 77 void SdchDictionaryFetcher::OnURLFetchComplete(
79 const net::URLFetcher* source) { 78 const net::URLFetcher* source) {
79 DCHECK(CalledOnValidThread());
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 manager_->AddSdchDictionary(data, source->GetURL());
85 } 85 }
86 current_fetch_.reset(NULL); 86 current_fetch_.reset(NULL);
87 ScheduleDelayedRun(); 87 ScheduleDelayedRun();
88 } 88 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698