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
3 // found in the LICENSE file.
5 #include "chrome/browser/net/chrome_http_user_agent_settings.h"
7 #include "base/prefs/pref_service.h"
8 #include "chrome/common/chrome_content_client.h"
9 #include "chrome/common/pref_names.h"
10 #include "content/public/browser/browser_thread.h"
11 #include "net/http/http_util.h"
13 ChromeHttpUserAgentSettings::ChromeHttpUserAgentSettings(PrefService
* prefs
) {
14 DCHECK_CURRENTLY_ON(content::BrowserThread::UI
);
15 pref_accept_language_
.Init(prefs::kAcceptLanguages
, prefs
);
16 last_pref_accept_language_
= *pref_accept_language_
;
17 last_http_accept_language_
=
18 net::HttpUtil::GenerateAcceptLanguageHeader(last_pref_accept_language_
);
19 pref_accept_language_
.MoveToThread(
20 content::BrowserThread::GetMessageLoopProxyForThread(
21 content::BrowserThread::IO
));
24 ChromeHttpUserAgentSettings::~ChromeHttpUserAgentSettings() {
25 DCHECK_CURRENTLY_ON(content::BrowserThread::IO
);
28 void ChromeHttpUserAgentSettings::CleanupOnUIThread() {
29 DCHECK_CURRENTLY_ON(content::BrowserThread::UI
);
30 pref_accept_language_
.Destroy();
33 std::string
ChromeHttpUserAgentSettings::GetAcceptLanguage() const {
34 DCHECK_CURRENTLY_ON(content::BrowserThread::IO
);
35 std::string new_pref_accept_language
= *pref_accept_language_
;
36 if (new_pref_accept_language
!= last_pref_accept_language_
) {
37 last_http_accept_language_
=
38 net::HttpUtil::GenerateAcceptLanguageHeader(new_pref_accept_language
);
39 last_pref_accept_language_
= new_pref_accept_language
;
41 return last_http_accept_language_
;
44 std::string
ChromeHttpUserAgentSettings::GetUserAgent() const {
45 DCHECK_CURRENTLY_ON(content::BrowserThread::IO
);
46 return ::GetUserAgent();