OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/chrome_sdch_policy.h" | 5 #include "chrome/browser/net/chrome_sdch_policy.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "net/base/sdch_manager.h" | 8 #include "net/base/sdch_manager.h" |
| 9 #include "net/base/sdch_net_log_params.h" |
9 | 10 |
10 ChromeSdchPolicy::ChromeSdchPolicy(net::SdchManager* sdch_manager, | 11 ChromeSdchPolicy::ChromeSdchPolicy(net::SdchManager* sdch_manager, |
11 net::URLRequestContext* context) | 12 net::URLRequestContext* context) |
12 : manager_(sdch_manager), | 13 : manager_(sdch_manager), |
13 // Because |fetcher_| is owned by ChromeSdchPolicy, the | 14 // Because |fetcher_| is owned by ChromeSdchPolicy, the |
14 // ChromeSdchPolicy object will be available for the lifetime | 15 // ChromeSdchPolicy object will be available for the lifetime |
15 // of |fetcher_|. | 16 // of |fetcher_|. |
16 fetcher_(context, | 17 fetcher_(context, |
17 base::Bind(&ChromeSdchPolicy::OnDictionaryFetched, | 18 base::Bind(&ChromeSdchPolicy::OnDictionaryFetched, |
18 base::Unretained(this))) { | 19 base::Unretained(this))) { |
19 manager_->AddObserver(this); | 20 manager_->AddObserver(this); |
20 } | 21 } |
21 | 22 |
22 ChromeSdchPolicy::~ChromeSdchPolicy() { | 23 ChromeSdchPolicy::~ChromeSdchPolicy() { |
23 manager_->RemoveObserver(this); | 24 manager_->RemoveObserver(this); |
24 } | 25 } |
25 | 26 |
26 void ChromeSdchPolicy::OnDictionaryFetched(const std::string& dictionary_text, | 27 void ChromeSdchPolicy::OnDictionaryFetched(const std::string& dictionary_text, |
27 const GURL& dictionary_url) { | 28 const GURL& dictionary_url, |
28 manager_->AddSdchDictionary(dictionary_text, 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)); |
| 37 } |
29 } | 38 } |
30 | 39 |
31 void ChromeSdchPolicy::OnGetDictionary(net::SdchManager* manager, | 40 void ChromeSdchPolicy::OnGetDictionary(net::SdchManager* manager, |
32 const GURL& request_url, | 41 const GURL& request_url, |
33 const GURL& dictionary_url) { | 42 const GURL& dictionary_url) { |
34 fetcher_.Schedule(dictionary_url); | 43 fetcher_.Schedule(dictionary_url); |
35 } | 44 } |
36 | 45 |
37 void ChromeSdchPolicy::OnClearDictionaries(net::SdchManager* manager) { | 46 void ChromeSdchPolicy::OnClearDictionaries(net::SdchManager* manager) { |
38 fetcher_.Cancel(); | 47 fetcher_.Cancel(); |
39 } | 48 } |
OLD | NEW |