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

Side by Side Diff: chrome/browser/profiles/profile_destroyer.cc

Issue 10824020: Move PROFILE_DESTROYED notification to ProfileDestroyer and observe it in ExtensionProcessManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/browser/profiles/profile_destroyer.h" 5 #include "chrome/browser/profiles/profile_destroyer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/common/chrome_notification_types.h"
12 #include "content/public/browser/notification_service.h"
11 #include "content/public/browser/notification_source.h" 13 #include "content/public/browser/notification_source.h"
12 #include "content/public/browser/notification_types.h" 14 #include "content/public/browser/notification_types.h"
13 #include "content/public/browser/render_process_host.h" 15 #include "content/public/browser/render_process_host.h"
14 16
15 17
16 namespace { 18 namespace {
17 19
18 const int64 kTimerDelaySeconds = 1; 20 const int64 kTimerDelaySeconds = 1;
19 21
20 } // namespace 22 } // namespace
21 23
22 std::vector<ProfileDestroyer*>* ProfileDestroyer::pending_destroyers_ = NULL; 24 std::vector<ProfileDestroyer*>* ProfileDestroyer::pending_destroyers_ = NULL;
23 25
24 // static 26 // static
25 void ProfileDestroyer::DestroyProfileWhenAppropriate(Profile* const profile) { 27 void ProfileDestroyer::DestroyProfileWhenAppropriate(Profile* const profile) {
26 DCHECK(profile); 28 DCHECK(profile);
29 content::NotificationService::current()->Notify(
Yoyo Zhou 2012/07/25 18:13:00 I wanted to put this in the ProfileDestroyer initi
30 chrome::NOTIFICATION_PROFILE_DESTROYED,
31 content::Source<Profile>(profile),
32 content::NotificationService::NoDetails());
33
27 std::vector<content::RenderProcessHost*> hosts; 34 std::vector<content::RenderProcessHost*> hosts;
28 // Testing profiles can simply be deleted directly. Some tests don't setup 35 // Testing profiles can simply be deleted directly. Some tests don't setup
29 // RenderProcessHost correctly and don't necessary run on the UI thread 36 // RenderProcessHost correctly and don't necessary run on the UI thread
30 // anyway, so we can't use the AllHostIterator. 37 // anyway, so we can't use the AllHostIterator.
31 if (profile->AsTestingProfile() == NULL) { 38 if (profile->AsTestingProfile() == NULL) {
32 GetHostsForProfile(profile, &hosts); 39 GetHostsForProfile(profile, &hosts);
33 if (!profile->IsOffTheRecord() && profile->HasOffTheRecordProfile()) 40 if (!profile->IsOffTheRecord() && profile->HasOffTheRecordProfile())
34 GetHostsForProfile(profile->GetOffTheRecordProfile(), &hosts); 41 GetHostsForProfile(profile->GetOffTheRecordProfile(), &hosts);
35 } 42 }
36 // This should never happen for non Off the record profile, this means that 43 // This should never happen for non Off the record profile, this means that
37 // there is a leak in a render process host that MUST BE FIXED!!! 44 // there is a leak in a render process host that MUST BE FIXED!!!
38 DCHECK(hosts.empty() || profile->IsOffTheRecord()); 45 DCHECK(hosts.empty() || profile->IsOffTheRecord());
Matt Perry 2012/07/25 19:32:08 you should change the DCHECK now that it works for
39 // Note that we still test for !profile->IsOffTheRecord here even though we 46 // Note that we still test for !profile->IsOffTheRecord here even though we
40 // DCHECK'd above because we want to protect Release builds against this even 47 // DCHECK'd above because we want to protect Release builds against this even
41 // we need to identify if there are leaks when we run Debug builds. 48 // we need to identify if there are leaks when we run Debug builds.
42 if (hosts.empty() || !profile->IsOffTheRecord()) { 49 if (hosts.empty() || !profile->IsOffTheRecord()) {
43 if (profile->IsOffTheRecord()) 50 if (profile->IsOffTheRecord())
44 profile->GetOriginalProfile()->DestroyOffTheRecordProfile(); 51 profile->GetOriginalProfile()->DestroyOffTheRecordProfile();
45 else 52 else
46 delete profile; 53 delete profile;
47 } else { 54 } else {
48 // The instance will destroy itself once all render process hosts referring 55 // The instance will destroy itself once all render process hosts referring
(...skipping 29 matching lines...) Expand all
78 Profile* const profile, 85 Profile* const profile,
79 const std::vector<content::RenderProcessHost*>& hosts) 86 const std::vector<content::RenderProcessHost*>& hosts)
80 : timer_(false, false), 87 : timer_(false, false),
81 num_hosts_(0), 88 num_hosts_(0),
82 profile_(profile) { 89 profile_(profile) {
83 if (pending_destroyers_ == NULL) 90 if (pending_destroyers_ == NULL)
84 pending_destroyers_ = new std::vector<ProfileDestroyer*>; 91 pending_destroyers_ = new std::vector<ProfileDestroyer*>;
85 pending_destroyers_->push_back(this); 92 pending_destroyers_->push_back(this);
86 for (size_t i = 0; i < hosts.size(); ++i) { 93 for (size_t i = 0; i < hosts.size(); ++i) {
87 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, 94 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
88 content::Source<content::RenderProcessHost>(hosts[i])); 95 content::Source<content::RenderProcessHost>(hosts[i]));
89 // For each of the notifications, we bump up our reference count. 96 // For each of the notifications, we bump up our reference count.
90 // It will go back to 0 and free us when all hosts are terminated. 97 // It will go back to 0 and free us when all hosts are terminated.
91 ++num_hosts_; 98 ++num_hosts_;
92 } 99 }
93 // If we are going to wait for render process hosts, we don't want to do it 100 // If we are going to wait for render process hosts, we don't want to do it
94 // for longer than kTimerDelaySeconds. 101 // for longer than kTimerDelaySeconds.
95 if (num_hosts_) { 102 if (num_hosts_) {
96 timer_.Start(FROM_HERE, 103 timer_.Start(FROM_HERE,
97 base::TimeDelta::FromSeconds(kTimerDelaySeconds), 104 base::TimeDelta::FromSeconds(kTimerDelaySeconds),
98 base::Bind(&ProfileDestroyer::DestroyProfile, this)); 105 base::Bind(&ProfileDestroyer::DestroyProfile, this));
(...skipping 20 matching lines...) Expand all
119 if (pending_destroyers_->empty()) { 126 if (pending_destroyers_->empty()) {
120 delete pending_destroyers_; 127 delete pending_destroyers_;
121 pending_destroyers_ = NULL; 128 pending_destroyers_ = NULL;
122 } 129 }
123 } 130 }
124 131
125 void ProfileDestroyer::Observe(int type, 132 void ProfileDestroyer::Observe(int type,
126 const content::NotificationSource& source, 133 const content::NotificationSource& source,
127 const content::NotificationDetails& details) { 134 const content::NotificationDetails& details) {
128 DCHECK(type == content::NOTIFICATION_RENDERER_PROCESS_TERMINATED); 135 DCHECK(type == content::NOTIFICATION_RENDERER_PROCESS_TERMINATED);
136 registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
Yoyo Zhou 2012/07/25 18:13:00 It turns out the current implementation doesn't re
137 source);
129 DCHECK(num_hosts_ > 0); 138 DCHECK(num_hosts_ > 0);
130 --num_hosts_; 139 --num_hosts_;
131 if (num_hosts_ == 0) { 140 if (num_hosts_ == 0) {
132 // Delay the destruction one step further in case other observers of this 141 // Delay the destruction one step further in case other observers of this
133 // notification need to look at the profile attached to the host. 142 // notification need to look at the profile attached to the host.
134 MessageLoop::current()->PostTask( 143 MessageLoop::current()->PostTask(
135 FROM_HERE, base::Bind(&ProfileDestroyer::DestroyProfile, this)); 144 FROM_HERE, base::Bind(&ProfileDestroyer::DestroyProfile, this));
136 } 145 }
137 } 146 }
138 147
(...skipping 22 matching lines...) Expand all
161 content::RenderProcessHost::AllHostsIterator()); 170 content::RenderProcessHost::AllHostsIterator());
162 !iter.IsAtEnd(); iter.Advance()) { 171 !iter.IsAtEnd(); iter.Advance()) {
163 content::RenderProcessHost* render_process_host = iter.GetCurrentValue(); 172 content::RenderProcessHost* render_process_host = iter.GetCurrentValue();
164 if (render_process_host && Profile::FromBrowserContext( 173 if (render_process_host && Profile::FromBrowserContext(
165 render_process_host->GetBrowserContext()) == profile) { 174 render_process_host->GetBrowserContext()) == profile) {
166 hosts->push_back(render_process_host); 175 hosts->push_back(render_process_host);
167 } 176 }
168 } 177 }
169 return !hosts->empty(); 178 return !hosts->empty();
170 } 179 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/off_the_record_profile_impl.cc ('k') | chrome/browser/profiles/profile_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698