| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/instant/instant_service.h" | 5 #include "chrome/browser/instant/instant_service.h" |
| 6 | 6 |
| 7 #include "chrome/browser/instant/instant_io_context.h" |
| 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" |
| 10 #include "chrome/common/chrome_notification_types.h" |
| 11 #include "content/public/browser/browser_thread.h" |
| 7 #include "content/public/browser/notification_service.h" | 12 #include "content/public/browser/notification_service.h" |
| 8 #include "content/public/browser/notification_types.h" | 13 #include "content/public/browser/notification_types.h" |
| 9 #include "content/public/browser/render_process_host.h" | 14 #include "content/public/browser/render_process_host.h" |
| 15 #include "content/public/browser/url_data_source.h" |
| 10 | 16 |
| 11 InstantService::InstantService() { | 17 using content::BrowserThread; |
| 18 |
| 19 InstantService::InstantService(Profile* profile) |
| 20 : profile_(profile) { |
| 12 registrar_.Add(this, | 21 registrar_.Add(this, |
| 13 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | 22 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
| 14 content::NotificationService::AllSources()); | 23 content::NotificationService::AllSources()); |
| 24 content::URLDataSource::Add(profile, new ThumbnailSource(profile)); |
| 15 } | 25 } |
| 16 | 26 |
| 17 InstantService::~InstantService() { | 27 InstantService::~InstantService() { |
| 18 } | 28 } |
| 19 | 29 |
| 20 void InstantService::AddInstantProcess(int process_id) { | 30 void InstantService::AddInstantProcess(int process_id) { |
| 21 process_ids_.insert(process_id); | 31 process_ids_.insert(process_id); |
| 32 |
| 33 if (profile_ && profile_->GetResourceContext()) { |
| 34 BrowserThread::PostTask( |
| 35 BrowserThread::IO, FROM_HERE, |
| 36 base::Bind(&InstantIOContext::AddInstantProcessOnIO, |
| 37 profile_->GetResourceContext(), process_id)); |
| 38 } |
| 22 } | 39 } |
| 23 | 40 |
| 24 bool InstantService::IsInstantProcess(int process_id) const { | 41 bool InstantService::IsInstantProcess(int process_id) const { |
| 25 return process_ids_.find(process_id) != process_ids_.end(); | 42 return process_ids_.find(process_id) != process_ids_.end(); |
| 26 } | 43 } |
| 27 | 44 |
| 28 void InstantService::Shutdown() { | 45 void InstantService::Shutdown() { |
| 29 process_ids_.clear(); | 46 process_ids_.clear(); |
| 47 |
| 48 if (profile_ && profile_->GetResourceContext()) { |
| 49 BrowserThread::PostTask( |
| 50 BrowserThread::IO, FROM_HERE, |
| 51 base::Bind(&InstantIOContext::ClearInstantProcessesOnIO, |
| 52 profile_->GetResourceContext())); |
| 53 } |
| 30 } | 54 } |
| 31 | 55 |
| 32 void InstantService::Observe(int type, | 56 void InstantService::Observe(int type, |
| 33 const content::NotificationSource& source, | 57 const content::NotificationSource& source, |
| 34 const content::NotificationDetails& details) { | 58 const content::NotificationDetails& details) { |
| 59 DCHECK_EQ(type, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED); |
| 35 int process_id = content::Source<content::RenderProcessHost>(source)->GetID(); | 60 int process_id = content::Source<content::RenderProcessHost>(source)->GetID(); |
| 36 process_ids_.erase(process_id); | 61 process_ids_.erase(process_id); |
| 62 |
| 63 if (profile_ && profile_->GetResourceContext()) { |
| 64 BrowserThread::PostTask( |
| 65 BrowserThread::IO, FROM_HERE, |
| 66 base::Bind(&InstantIOContext::RemoveInstantProcessOnIO, |
| 67 profile_->GetResourceContext(), process_id)); |
| 68 } |
| 37 } | 69 } |
| OLD | NEW |