1 // Copyright 2015 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 "ios/chrome/browser/net/ios_chrome_http_user_agent_settings.h"
7 #include "base/prefs/pref_service.h"
8 #include "ios/chrome/browser/pref_names.h"
9 #include "ios/web/public/web_client.h"
10 #include "ios/web/public/web_thread.h"
11 #include "net/http/http_util.h"
13 IOSChromeHttpUserAgentSettings::IOSChromeHttpUserAgentSettings(
15 DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI
);
16 pref_accept_language_
.Init(ios::prefs::kAcceptLanguages
, prefs
);
17 last_pref_accept_language_
= *pref_accept_language_
;
18 last_http_accept_language_
=
19 net::HttpUtil::GenerateAcceptLanguageHeader(last_pref_accept_language_
);
20 pref_accept_language_
.MoveToThread(
21 web::WebThread::GetTaskRunnerForThread(web::WebThread::IO
));
24 IOSChromeHttpUserAgentSettings::~IOSChromeHttpUserAgentSettings() {
25 DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::IO
);
28 void IOSChromeHttpUserAgentSettings::CleanupOnUIThread() {
29 DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI
);
30 pref_accept_language_
.Destroy();
33 std::string
IOSChromeHttpUserAgentSettings::GetAcceptLanguage() const {
34 DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::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
IOSChromeHttpUserAgentSettings::GetUserAgent() const {
45 DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::IO
);
46 return web::GetWebClient()->GetUserAgent(false);