Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1336)

Unified Diff: webkit/common/user_agent/user_agent.cc

Issue 191093002: Simplify the user agent code some more since after r255534 it's not affected by the site's URL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: patchset 15 which works Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webkit/common/user_agent/user_agent.h ('k') | webkit/common/user_agent/webkit_user_agent.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/common/user_agent/user_agent.cc
===================================================================
--- webkit/common/user_agent/user_agent.cc (revision 255867)
+++ webkit/common/user_agent/user_agent.cc (working copy)
@@ -1,75 +0,0 @@
-// Copyright 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "webkit/common/user_agent/user_agent.h"
-
-#include "base/lazy_instance.h"
-#include "base/logging.h"
-#include "base/synchronization/lock.h"
-
-namespace webkit_glue {
-
-namespace {
-
-class UserAgentState {
- public:
- UserAgentState();
- ~UserAgentState();
-
- void Set(const std::string& user_agent);
- const std::string& Get() const;
-
- private:
- mutable std::string user_agent_;
-
- mutable bool user_agent_requested_;
-
- // This object can be accessed from multiple threads, so use a lock around
- // accesses to the data members.
- mutable base::Lock lock_;
-};
-
-UserAgentState::UserAgentState()
- : user_agent_requested_(false) {
-}
-
-UserAgentState::~UserAgentState() {
-}
-
-void UserAgentState::Set(const std::string& user_agent) {
- base::AutoLock auto_lock(lock_);
- if (user_agent == user_agent_) {
- // We allow the user agent to be set multiple times as long as it
- // is set to the same value, in order to simplify unit testing
- // given g_user_agent is a global.
- return;
- }
- DCHECK(!user_agent.empty());
- DCHECK(!user_agent_requested_) << "Setting the user agent after someone has "
- "already requested it can result in unexpected behavior.";
- user_agent_ = user_agent;
-}
-
-const std::string& UserAgentState::Get() const {
- base::AutoLock auto_lock(lock_);
- user_agent_requested_ = true;
-
- DCHECK(!user_agent_.empty());
-
- return user_agent_;
-}
-
-base::LazyInstance<UserAgentState> g_user_agent = LAZY_INSTANCE_INITIALIZER;
-
-} // namespace
-
-void SetUserAgent(const std::string& user_agent) {
- g_user_agent.Get().Set(user_agent);
-}
-
-const std::string& GetUserAgent(const GURL& url) {
- return g_user_agent.Get().Get();
-}
-
-} // namespace webkit_glue
« no previous file with comments | « webkit/common/user_agent/user_agent.h ('k') | webkit/common/user_agent/webkit_user_agent.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698