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

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_blocking_page.cc

Issue 5711001: Add a new GetInstance() method for remaining files with singleton classes under chrome/browser. (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 // Implementation of the SafeBrowsingBlockingPage class. 5 // Implementation of the SafeBrowsingBlockingPage class.
6 6
7 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" 7 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h"
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "app/l10n_util.h" 11 #include "app/l10n_util.h"
12 #include "app/resource_bundle.h" 12 #include "app/resource_bundle.h"
13 #include "base/i18n/rtl.h" 13 #include "base/i18n/rtl.h"
14 #include "base/singleton.h" 14 #include "base/lazy_instance.h"
15 #include "base/string_number_conversions.h" 15 #include "base/string_number_conversions.h"
16 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
17 #include "base/values.h" 17 #include "base/values.h"
18 #include "chrome/browser/browser_thread.h" 18 #include "chrome/browser/browser_thread.h"
19 #include "chrome/browser/dom_operation_notification_details.h" 19 #include "chrome/browser/dom_operation_notification_details.h"
20 #include "chrome/browser/dom_ui/new_tab_ui.h" 20 #include "chrome/browser/dom_ui/new_tab_ui.h"
21 #include "chrome/browser/google/google_util.h" 21 #include "chrome/browser/google/google_util.h"
22 #include "chrome/browser/metrics/user_metrics.h" 22 #include "chrome/browser/metrics/user_metrics.h"
23 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 23 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
24 #include "chrome/browser/tab_contents/navigation_controller.h" 24 #include "chrome/browser/tab_contents/navigation_controller.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 public: 79 public:
80 SafeBrowsingBlockingPage* CreateSafeBrowsingPage( 80 SafeBrowsingBlockingPage* CreateSafeBrowsingPage(
81 SafeBrowsingService* service, 81 SafeBrowsingService* service,
82 TabContents* tab_contents, 82 TabContents* tab_contents,
83 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) { 83 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) {
84 return new SafeBrowsingBlockingPage(service, tab_contents, 84 return new SafeBrowsingBlockingPage(service, tab_contents,
85 unsafe_resources); 85 unsafe_resources);
86 } 86 }
87 87
88 private: 88 private:
89 friend struct DefaultSingletonTraits<SafeBrowsingBlockingPageFactoryImpl>; 89 friend struct base::DefaultLazyInstanceTraits<
90 SafeBrowsingBlockingPageFactoryImpl>;
90 91
91 SafeBrowsingBlockingPageFactoryImpl() { } 92 SafeBrowsingBlockingPageFactoryImpl() { }
92 93
93 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageFactoryImpl); 94 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageFactoryImpl);
94 }; 95 };
95 96
97 static base::LazyInstance<SafeBrowsingBlockingPageFactoryImpl>
98 g_safe_browsing_blocking_page_factory_impl(base::LINKER_INITIALIZED);
99
96 SafeBrowsingBlockingPage::SafeBrowsingBlockingPage( 100 SafeBrowsingBlockingPage::SafeBrowsingBlockingPage(
97 SafeBrowsingService* sb_service, 101 SafeBrowsingService* sb_service,
98 TabContents* tab_contents, 102 TabContents* tab_contents,
99 const UnsafeResourceList& unsafe_resources) 103 const UnsafeResourceList& unsafe_resources)
100 : InterstitialPage(tab_contents, 104 : InterstitialPage(tab_contents,
101 IsMainPage(unsafe_resources), 105 IsMainPage(unsafe_resources),
102 unsafe_resources[0].url), 106 unsafe_resources[0].url),
103 sb_service_(sb_service), 107 sb_service_(sb_service),
104 is_main_frame_(IsMainPage(unsafe_resources)), 108 is_main_frame_(IsMainPage(unsafe_resources)),
105 unsafe_resources_(unsafe_resources) { 109 unsafe_resources_(unsafe_resources) {
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 } 538 }
535 539
536 if (!interstitial) { 540 if (!interstitial) {
537 // There are no interstitial currently showing in that tab, go ahead and 541 // There are no interstitial currently showing in that tab, go ahead and
538 // show this interstitial. 542 // show this interstitial.
539 std::vector<SafeBrowsingService::UnsafeResource> resources; 543 std::vector<SafeBrowsingService::UnsafeResource> resources;
540 resources.push_back(unsafe_resource); 544 resources.push_back(unsafe_resource);
541 // Set up the factory if this has not been done already (tests do that 545 // Set up the factory if this has not been done already (tests do that
542 // before this method is called). 546 // before this method is called).
543 if (!factory_) 547 if (!factory_)
544 factory_ = Singleton<SafeBrowsingBlockingPageFactoryImpl>::get(); 548 factory_ = g_safe_browsing_blocking_page_factory_impl.Pointer();
545 SafeBrowsingBlockingPage* blocking_page = 549 SafeBrowsingBlockingPage* blocking_page =
546 factory_->CreateSafeBrowsingPage(sb_service, tab_contents, resources); 550 factory_->CreateSafeBrowsingPage(sb_service, tab_contents, resources);
547 blocking_page->Show(); 551 blocking_page->Show();
548 return; 552 return;
549 } 553 }
550 554
551 // This is an interstitial for a page's resource, let's queue it. 555 // This is an interstitial for a page's resource, let's queue it.
552 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); 556 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap();
553 (*unsafe_resource_map)[tab_contents].push_back(unsafe_resource); 557 (*unsafe_resource_map)[tab_contents].push_back(unsafe_resource);
554 } 558 }
555 559
556 // static 560 // static
557 bool SafeBrowsingBlockingPage::IsMainPage( 561 bool SafeBrowsingBlockingPage::IsMainPage(
558 const UnsafeResourceList& unsafe_resources) { 562 const UnsafeResourceList& unsafe_resources) {
559 return unsafe_resources.size() == 1 && 563 return unsafe_resources.size() == 1 &&
560 unsafe_resources[0].resource_type == ResourceType::MAIN_FRAME; 564 unsafe_resources[0].resource_type == ResourceType::MAIN_FRAME;
561 } 565 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698