15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CHROME_BROWSER_NET_CHROME_HTTP_USER_AGENT_SETTINGS_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHROME_BROWSER_NET_CHROME_HTTP_USER_AGENT_SETTINGS_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/compiler_specific.h"
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/prefs/pref_member.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/url_request/http_user_agent_settings.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class PrefService;
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// An implementation of |HttpUserAgentSettings| that provides HTTP header
18a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Accept-Language value that tracks Pref settings.
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ChromeHttpUserAgentSettings : public net::HttpUserAgentSettings {
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Must be called on the UI thread.
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  explicit ChromeHttpUserAgentSettings(PrefService* prefs);
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Must be called on the IO thread.
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~ChromeHttpUserAgentSettings();
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void CleanupOnUIThread();
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // net::HttpUserAgentSettings implementation
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual std::string GetAcceptLanguage() const OVERRIDE;
30a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual std::string GetUserAgent() const OVERRIDE;
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  StringPrefMember pref_accept_language_;
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Avoid re-processing by caching the last value from the preferences and the
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // last result of processing via net::HttpUtil::GenerateAccept*Header().
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  mutable std::string last_pref_accept_language_;
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  mutable std::string last_http_accept_language_;
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(ChromeHttpUserAgentSettings);
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // CHROME_BROWSER_NET_CHROME_HTTP_USER_AGENT_SETTINGS_H_
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
45