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

Side by Side Diff: chrome/renderer/render_view.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 "chrome/renderer/render_view.h" 5 #include "chrome/renderer/render_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "app/l10n_util.h" 12 #include "app/l10n_util.h"
13 #include "app/message_box_flags.h" 13 #include "app/message_box_flags.h"
14 #include "app/resource_bundle.h" 14 #include "app/resource_bundle.h"
15 #include "base/callback.h" 15 #include "base/callback.h"
16 #include "base/command_line.h" 16 #include "base/command_line.h"
17 #include "base/compiler_specific.h" 17 #include "base/compiler_specific.h"
18 #include "base/lazy_instance.h"
18 #include "base/metrics/histogram.h" 19 #include "base/metrics/histogram.h"
19 #include "base/path_service.h" 20 #include "base/path_service.h"
20 #include "base/process_util.h" 21 #include "base/process_util.h"
21 #include "base/singleton.h"
22 #include "base/string_piece.h" 22 #include "base/string_piece.h"
23 #include "base/string_util.h" 23 #include "base/string_util.h"
24 #include "base/sys_string_conversions.h" 24 #include "base/sys_string_conversions.h"
25 #include "base/time.h" 25 #include "base/time.h"
26 #include "base/utf_string_conversions.h" 26 #include "base/utf_string_conversions.h"
27 #include "build/build_config.h" 27 #include "build/build_config.h"
28 #include "chrome/common/appcache/appcache_dispatcher.h" 28 #include "chrome/common/appcache/appcache_dispatcher.h"
29 #include "chrome/common/bindings_policy.h" 29 #include "chrome/common/bindings_policy.h"
30 #include "chrome/common/child_process_logging.h" 30 #include "chrome/common/child_process_logging.h"
31 #include "chrome/common/chrome_constants.h" 31 #include "chrome/common/chrome_constants.h"
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 using webkit_glue::ImageResourceFetcher; 270 using webkit_glue::ImageResourceFetcher;
271 using webkit_glue::PasswordForm; 271 using webkit_glue::PasswordForm;
272 using webkit_glue::PasswordFormDomManager; 272 using webkit_glue::PasswordFormDomManager;
273 using webkit_glue::ResourceFetcher; 273 using webkit_glue::ResourceFetcher;
274 using webkit_glue::SiteIsolationMetrics; 274 using webkit_glue::SiteIsolationMetrics;
275 using webkit_glue::WebAccessibility; 275 using webkit_glue::WebAccessibility;
276 276
277 //----------------------------------------------------------------------------- 277 //-----------------------------------------------------------------------------
278 278
279 typedef std::map<WebKit::WebView*, RenderView*> ViewMap; 279 typedef std::map<WebKit::WebView*, RenderView*> ViewMap;
280 static base::LazyInstance<ViewMap> g_view_map(base::LINKER_INITIALIZED);
280 281
281 // define to write the time necessary for thumbnail/DOM text retrieval, 282 // define to write the time necessary for thumbnail/DOM text retrieval,
282 // respectively, into the system debug log 283 // respectively, into the system debug log
283 // #define TIME_TEXT_RETRIEVAL 284 // #define TIME_TEXT_RETRIEVAL
284 285
285 // maximum number of characters in the document to index, any text beyond this 286 // maximum number of characters in the document to index, any text beyond this
286 // point will be clipped 287 // point will be clipped
287 static const size_t kMaxIndexChars = 65535; 288 static const size_t kMaxIndexChars = 65535;
288 289
289 // Size of the thumbnails that we'll generate 290 // Size of the thumbnails that we'll generate
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 #endif 609 #endif
609 610
610 render_thread_->RemoveFilter(audio_message_filter_); 611 render_thread_->RemoveFilter(audio_message_filter_);
611 612
612 // Tell the PhishingClassifierDelegate that the view is going away. 613 // Tell the PhishingClassifierDelegate that the view is going away.
613 if (phishing_delegate_.get()) 614 if (phishing_delegate_.get())
614 phishing_delegate_->CancelPendingClassification(); 615 phishing_delegate_->CancelPendingClassification();
615 616
616 #ifndef NDEBUG 617 #ifndef NDEBUG
617 // Make sure we are no longer referenced by the ViewMap. 618 // Make sure we are no longer referenced by the ViewMap.
618 ViewMap* views = Singleton<ViewMap>::get(); 619 ViewMap* views = g_view_map.Pointer();
619 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) 620 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
620 DCHECK_NE(this, it->second) << "Failed to call Close?"; 621 DCHECK_NE(this, it->second) << "Failed to call Close?";
621 #endif 622 #endif
622 } 623 }
623 624
624 /*static*/ 625 /*static*/
625 void RenderView::ForEach(RenderViewVisitor* visitor) { 626 void RenderView::ForEach(RenderViewVisitor* visitor) {
626 ViewMap* views = Singleton<ViewMap>::get(); 627 ViewMap* views = g_view_map.Pointer();
627 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) { 628 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
628 if (!visitor->Visit(it->second)) 629 if (!visitor->Visit(it->second))
629 return; 630 return;
630 } 631 }
631 } 632 }
632 633
633 /*static*/ 634 /*static*/
634 RenderView* RenderView::FromWebView(WebView* webview) { 635 RenderView* RenderView::FromWebView(WebView* webview) {
635 ViewMap* views = Singleton<ViewMap>::get(); 636 ViewMap* views = g_view_map.Pointer();
636 ViewMap::iterator it = views->find(webview); 637 ViewMap::iterator it = views->find(webview);
637 return it == views->end() ? NULL : it->second; 638 return it == views->end() ? NULL : it->second;
638 } 639 }
639 640
640 /*static*/ 641 /*static*/
641 RenderView* RenderView::Create( 642 RenderView* RenderView::Create(
642 RenderThreadBase* render_thread, 643 RenderThreadBase* render_thread,
643 gfx::NativeViewId parent_hwnd, 644 gfx::NativeViewId parent_hwnd,
644 int32 opener_id, 645 int32 opener_id,
645 const RendererPreferences& renderer_prefs, 646 const RendererPreferences& renderer_prefs,
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 shared_popup_counter_->data++; 889 shared_popup_counter_->data++;
889 decrement_shared_popup_at_destruction_ = true; 890 decrement_shared_popup_at_destruction_ = true;
890 } else { 891 } else {
891 shared_popup_counter_ = new SharedRenderViewCounter(0); 892 shared_popup_counter_ = new SharedRenderViewCounter(0);
892 decrement_shared_popup_at_destruction_ = false; 893 decrement_shared_popup_at_destruction_ = false;
893 } 894 }
894 895
895 devtools_agent_.reset(new DevToolsAgent(routing_id, this)); 896 devtools_agent_.reset(new DevToolsAgent(routing_id, this));
896 897
897 webwidget_ = WebView::create(this, devtools_agent_.get()); 898 webwidget_ = WebView::create(this, devtools_agent_.get());
898 Singleton<ViewMap>::get()->insert(std::make_pair(webview(), this)); 899 g_view_map.Get().insert(std::make_pair(webview(), this));
899 webkit_preferences_.Apply(webview()); 900 webkit_preferences_.Apply(webview());
900 webview()->initializeMainFrame(this); 901 webview()->initializeMainFrame(this);
901 if (!frame_name.empty()) 902 if (!frame_name.empty())
902 webview()->mainFrame()->setName(frame_name); 903 webview()->mainFrame()->setName(frame_name);
903 904
904 OnSetRendererPrefs(renderer_prefs); 905 OnSetRendererPrefs(renderer_prefs);
905 906
906 routing_id_ = routing_id; 907 routing_id_ = routing_id;
907 render_thread_->AddRoute(routing_id_, this); 908 render_thread_->AddRoute(routing_id_, this);
908 // Take a reference on behalf of the RenderThread. This will be balanced 909 // Take a reference on behalf of the RenderThread. This will be balanced
(...skipping 4531 matching lines...) Expand 10 before | Expand all | Expand 10 after
5440 } 5441 }
5441 } 5442 }
5442 5443
5443 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true)); 5444 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
5444 } 5445 }
5445 5446
5446 void RenderView::Close() { 5447 void RenderView::Close() {
5447 // We need to grab a pointer to the doomed WebView before we destroy it. 5448 // We need to grab a pointer to the doomed WebView before we destroy it.
5448 WebView* doomed = webview(); 5449 WebView* doomed = webview();
5449 RenderWidget::Close(); 5450 RenderWidget::Close();
5450 Singleton<ViewMap>::get()->erase(doomed); 5451 g_view_map.Get().erase(doomed);
5451 } 5452 }
5452 5453
5453 void RenderView::DidHandleKeyEvent() { 5454 void RenderView::DidHandleKeyEvent() {
5454 edit_commands_.clear(); 5455 edit_commands_.clear();
5455 } 5456 }
5456 5457
5457 void RenderView::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) { 5458 void RenderView::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {
5458 page_click_tracker_->DidHandleMouseEvent(event); 5459 page_click_tracker_->DidHandleMouseEvent(event);
5459 } 5460 }
5460 5461
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
5731 external_popup_menu_.reset(); 5732 external_popup_menu_.reset();
5732 } 5733 }
5733 #endif 5734 #endif
5734 5735
5735 void RenderView::AddErrorToRootConsole(const string16& message) { 5736 void RenderView::AddErrorToRootConsole(const string16& message) {
5736 if (webview() && webview()->mainFrame()) { 5737 if (webview() && webview()->mainFrame()) {
5737 webview()->mainFrame()->addMessageToConsole( 5738 webview()->mainFrame()->addMessageToConsole(
5738 WebConsoleMessage(WebConsoleMessage::LevelError, message)); 5739 WebConsoleMessage(WebConsoleMessage::LevelError, message));
5739 } 5740 }
5740 } 5741 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698