Commit ee619053 authored by mohan.reddy's avatar mohan.reddy Committed by Commit bot

Fix WeakPtrFactory member ordering in chrome/browser/safe_browsing

Changing in the intialization order of WeakPtrFactory such that all
member variables should appear before the WeakPtrFactory to ensure
that any WeakPtrs to Controller are invalidated before its members
variable's destructors are executed, rendering them invalid.

BUG=303818

Review URL: https://codereview.chromium.org/570713007

Cr-Commit-Position: refs/heads/master@{#295240}
parent 7cb4e598
......@@ -323,8 +323,8 @@ ClientSideDetectionHost::ClientSideDetectionHost(WebContents* tab)
should_extract_malware_features_(true),
should_classify_for_malware_(false),
pageload_complete_(false),
weak_factory_(this),
unsafe_unique_page_id_(-1) {
unsafe_unique_page_id_(-1),
weak_factory_(this) {
DCHECK(tab);
// Note: csd_service_ and sb_service will be NULL here in testing.
csd_service_ = g_browser_process->safe_browsing_detection_service();
......
......@@ -172,13 +172,13 @@ class ClientSideDetectionHost : public content::WebContentsObserver,
bool should_classify_for_malware_;
bool pageload_complete_;
base::WeakPtrFactory<ClientSideDetectionHost> weak_factory_;
// Unique page ID of the most recent unsafe site that was loaded in this tab
// as well as the UnsafeResource.
int unsafe_unique_page_id_;
scoped_ptr<SafeBrowsingUIManager::UnsafeResource> unsafe_resource_;
base::WeakPtrFactory<ClientSideDetectionHost> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(ClientSideDetectionHost);
};
......
......@@ -100,8 +100,8 @@ ClientSideDetectionService::CacheState::CacheState(bool phish, base::Time time)
ClientSideDetectionService::ClientSideDetectionService(
net::URLRequestContextGetter* request_context_getter)
: enabled_(false),
weak_factory_(this),
request_context_getter_(request_context_getter) {
request_context_getter_(request_context_getter),
weak_factory_(this) {
registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED,
content::NotificationService::AllBrowserContextsAndSources());
}
......
......@@ -316,10 +316,6 @@ class ClientSideDetectionService : public net::URLFetcherDelegate,
// of malware requests that we send in a day.
std::queue<base::Time> malware_report_times_;
// Used to asynchronously call the callbacks for
// SendClientReportPhishingRequest.
base::WeakPtrFactory<ClientSideDetectionService> weak_factory_;
// The context we use to issue network requests.
scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
......@@ -329,6 +325,10 @@ class ClientSideDetectionService : public net::URLFetcherDelegate,
content::NotificationRegistrar registrar_;
// Used to asynchronously call the callbacks for
// SendClientReportPhishingRequest.
base::WeakPtrFactory<ClientSideDetectionService> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(ClientSideDetectionService);
};
} // namespace safe_browsing
......
......@@ -448,9 +448,9 @@ void SafeBrowsingDatabase::RecordFailure(FailureType failure_type) {
SafeBrowsingDatabaseNew::SafeBrowsingDatabaseNew()
: creation_loop_(base::MessageLoop::current()),
browse_store_(new SafeBrowsingStoreFile),
reset_factory_(this),
corruption_detected_(false),
change_detected_(false) {
change_detected_(false),
reset_factory_(this) {
DCHECK(browse_store_.get());
DCHECK(!download_store_.get());
DCHECK(!csd_whitelist_store_.get());
......@@ -476,8 +476,8 @@ SafeBrowsingDatabaseNew::SafeBrowsingDatabaseNew(
extension_blacklist_store_(extension_blacklist_store),
side_effect_free_whitelist_store_(side_effect_free_whitelist_store),
ip_blacklist_store_(ip_blacklist_store),
reset_factory_(this),
corruption_detected_(false) {
corruption_detected_(false),
reset_factory_(this) {
DCHECK(browse_store_.get());
}
......
......@@ -456,9 +456,6 @@ class SafeBrowsingDatabaseNew : public SafeBrowsingDatabase {
// empty full_hashes field. Cleared on each update.
std::map<SBPrefix, SBCachedFullHashResult> browse_gethash_cache_;
// Used to schedule resetting the database because of corruption.
base::WeakPtrFactory<SafeBrowsingDatabaseNew> reset_factory_;
// Set if corruption is detected during the course of an update.
// Causes the update functions to fail with no side effects, until
// the next call to |UpdateStarted()|.
......@@ -473,6 +470,9 @@ class SafeBrowsingDatabaseNew : public SafeBrowsingDatabase {
// Used to check if a prefix was in the browse database.
scoped_ptr<safe_browsing::PrefixSet> side_effect_free_whitelist_prefix_set_;
// Used to schedule resetting the database because of corruption.
base::WeakPtrFactory<SafeBrowsingDatabaseNew> reset_factory_;
};
#endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment