1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/net/chrome_sdch_policy.h"
8 #include "net/base/sdch_manager.h"
9 #include "net/base/sdch_net_log_params.h"
11 ChromeSdchPolicy::ChromeSdchPolicy(net::SdchManager
* sdch_manager
,
12 net::URLRequestContext
* context
)
13 : manager_(sdch_manager
),
14 // Because |fetcher_| is owned by ChromeSdchPolicy, the
15 // ChromeSdchPolicy object will be available for the lifetime
18 base::Bind(&ChromeSdchPolicy::OnDictionaryFetched
,
19 base::Unretained(this))) {
20 manager_
->AddObserver(this);
23 ChromeSdchPolicy::~ChromeSdchPolicy() {
24 manager_
->RemoveObserver(this);
27 void ChromeSdchPolicy::OnDictionaryFetched(const std::string
& dictionary_text
,
28 const GURL
& dictionary_url
,
29 const net::BoundNetLog
& net_log
) {
30 net::SdchProblemCode rv
=
31 manager_
->AddSdchDictionary(dictionary_text
, dictionary_url
);
32 if (rv
!= net::SDCH_OK
) {
33 net::SdchManager::SdchErrorRecovery(rv
);
34 net_log
.AddEvent(net::NetLog::TYPE_SDCH_DICTIONARY_ERROR
,
35 base::Bind(&net::NetLogSdchDictionaryFetchProblemCallback
,
36 rv
, dictionary_url
, true));
40 void ChromeSdchPolicy::OnGetDictionary(net::SdchManager
* manager
,
41 const GURL
& request_url
,
42 const GURL
& dictionary_url
) {
43 fetcher_
.Schedule(dictionary_url
);
46 void ChromeSdchPolicy::OnClearDictionaries(net::SdchManager
* manager
) {