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

Side by Side Diff: webkit/glue/webkit_glue.cc

Issue 5682008: Make members of Singleton<T> private and only visible to the singleton type. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 10 years 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "webkit/glue/webkit_glue.h" 5 #include "webkit/glue/webkit_glue.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <objidl.h> 8 #include <objidl.h>
9 #include <mlang.h> 9 #include <mlang.h>
10 #elif defined(OS_POSIX) && !defined(OS_MACOSX) 10 #elif defined(OS_POSIX) && !defined(OS_MACOSX)
11 #include <sys/utsname.h> 11 #include <sys/utsname.h>
12 #endif 12 #endif
13 13
14 #include "base/lazy_instance.h"
14 #include "base/logging.h" 15 #include "base/logging.h"
15 #include "base/scoped_ptr.h" 16 #include "base/scoped_ptr.h"
16 #include "base/singleton.h"
17 #include "base/string_piece.h" 17 #include "base/string_piece.h"
18 #include "base/string_util.h" 18 #include "base/string_util.h"
19 #include "base/stringprintf.h" 19 #include "base/stringprintf.h"
20 #include "base/sys_info.h" 20 #include "base/sys_info.h"
21 #include "base/sys_string_conversions.h" 21 #include "base/sys_string_conversions.h"
22 #include "base/utf_string_conversions.h" 22 #include "base/utf_string_conversions.h"
23 #include "net/base/escape.h" 23 #include "net/base/escape.h"
24 #include "skia/ext/platform_canvas.h" 24 #include "skia/ext/platform_canvas.h"
25 #if defined(OS_MACOSX) 25 #if defined(OS_MACOSX)
26 #include "skia/ext/skia_utils_mac.h" 26 #include "skia/ext/skia_utils_mac.h"
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 349
350 std::string user_agent; 350 std::string user_agent;
351 351
352 // The UA string when we're pretending to be Windows Chrome. 352 // The UA string when we're pretending to be Windows Chrome.
353 std::string mimic_windows_user_agent; 353 std::string mimic_windows_user_agent;
354 354
355 bool user_agent_requested; 355 bool user_agent_requested;
356 bool user_agent_is_overridden; 356 bool user_agent_is_overridden;
357 }; 357 };
358 358
359 Singleton<UserAgentState> g_user_agent; 359 static base::LazyInstance<UserAgentState> g_user_agent(
360 base::LINKER_INITIALIZED);
360 361
361 void SetUserAgentToDefault() { 362 void SetUserAgentToDefault() {
362 BuildUserAgent(false, &g_user_agent->user_agent); 363 BuildUserAgent(false, &g_user_agent.Get().user_agent);
363 } 364 }
364 365
365 } // namespace 366 } // namespace
366 367
367 void SetUserAgent(const std::string& new_user_agent) { 368 void SetUserAgent(const std::string& new_user_agent) {
368 // If you combine this with the previous line, the function only works the 369 // If you combine this with the previous line, the function only works the
369 // first time. 370 // first time.
370 DCHECK(!g_user_agent->user_agent_requested) << 371 DCHECK(!g_user_agent.Get().user_agent_requested) <<
371 "Setting the user agent after someone has " 372 "Setting the user agent after someone has "
372 "already requested it can result in unexpected behavior."; 373 "already requested it can result in unexpected behavior.";
373 g_user_agent->user_agent_is_overridden = true; 374 g_user_agent.Get().user_agent_is_overridden = true;
374 g_user_agent->user_agent = new_user_agent; 375 g_user_agent.Get().user_agent = new_user_agent;
375 } 376 }
376 377
377 const std::string& GetUserAgent(const GURL& url) { 378 const std::string& GetUserAgent(const GURL& url) {
378 if (g_user_agent->user_agent.empty()) 379 if (g_user_agent.Get().user_agent.empty())
379 SetUserAgentToDefault(); 380 SetUserAgentToDefault();
380 g_user_agent->user_agent_requested = true; 381 g_user_agent.Get().user_agent_requested = true;
381 if (!g_user_agent->user_agent_is_overridden) { 382 if (!g_user_agent.Get().user_agent_is_overridden) {
382 // Workarounds for sites that use misguided UA sniffing. 383 // Workarounds for sites that use misguided UA sniffing.
383 #if defined(OS_POSIX) && !defined(OS_MACOSX) 384 #if defined(OS_POSIX) && !defined(OS_MACOSX)
384 if (MatchPattern(url.host(), "*.mail.yahoo.com")) { 385 if (MatchPattern(url.host(), "*.mail.yahoo.com")) {
385 // mail.yahoo.com is ok with Windows Chrome but not Linux Chrome. 386 // mail.yahoo.com is ok with Windows Chrome but not Linux Chrome.
386 // http://bugs.chromium.org/11136 387 // http://bugs.chromium.org/11136
387 // TODO(evanm): remove this if Yahoo fixes their sniffing. 388 // TODO(evanm): remove this if Yahoo fixes their sniffing.
388 if (g_user_agent->mimic_windows_user_agent.empty()) 389 if (g_user_agent.Get().mimic_windows_user_agent.empty())
389 BuildUserAgent(true, &g_user_agent->mimic_windows_user_agent); 390 BuildUserAgent(true, &g_user_agent.Get().mimic_windows_user_agent);
390 return g_user_agent->mimic_windows_user_agent; 391 return g_user_agent.Get().mimic_windows_user_agent;
391 } 392 }
392 #endif 393 #endif
393 } 394 }
394 return g_user_agent->user_agent; 395 return g_user_agent.Get().user_agent;
395 } 396 }
396 397
397 void SetForcefullyTerminatePluginProcess(bool value) { 398 void SetForcefullyTerminatePluginProcess(bool value) {
398 if (IsPluginRunningInRendererProcess()) { 399 if (IsPluginRunningInRendererProcess()) {
399 // Ignore this quirk when the plugins are not running in their own process. 400 // Ignore this quirk when the plugins are not running in their own process.
400 return; 401 return;
401 } 402 }
402 403
403 g_forcefully_terminate_plugin_process = value; 404 g_forcefully_terminate_plugin_process = value;
404 } 405 }
(...skipping 11 matching lines...) Expand all
416 NOTIMPLEMENTED(); 417 NOTIMPLEMENTED();
417 return NULL; 418 return NULL;
418 #endif 419 #endif
419 } 420 }
420 421
421 int GetGlyphPageCount() { 422 int GetGlyphPageCount() {
422 return WebGlyphCache::pageCount(); 423 return WebGlyphCache::pageCount();
423 } 424 }
424 425
425 } // namespace webkit_glue 426 } // namespace webkit_glue
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698