| 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 "content/public/browser/notification_service.h" |
| 8 #include "content/public/browser/notification_types.h" |
| 9 #include "content/public/browser/render_process_host.h" |
| 10 |
| 7 InstantService::InstantService() { | 11 InstantService::InstantService() { |
| 12 registrar_.Add(this, |
| 13 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
| 14 content::NotificationService::AllSources()); |
| 8 } | 15 } |
| 9 | 16 |
| 10 InstantService::~InstantService() { | 17 InstantService::~InstantService() { |
| 11 } | 18 } |
| 12 | 19 |
| 13 void InstantService::AddInstantProcess(int process_id) { | 20 void InstantService::AddInstantProcess(int process_id) { |
| 14 process_ids_.insert(process_id); | 21 process_ids_.insert(process_id); |
| 15 } | 22 } |
| 16 | 23 |
| 17 void InstantService::RemoveInstantProcess(int process_id) { | |
| 18 process_ids_.erase(process_id); | |
| 19 } | |
| 20 | |
| 21 bool InstantService::IsInstantProcess(int process_id) const { | 24 bool InstantService::IsInstantProcess(int process_id) const { |
| 22 return process_ids_.count(process_id) != 0; | 25 return process_ids_.count(process_id) != 0; |
| 23 } | 26 } |
| 24 | 27 |
| 25 int InstantService::GetInstantProcessCount() const { | 28 int InstantService::GetInstantProcessCount() const { |
| 26 return process_ids_.size(); | 29 return process_ids_.size(); |
| 27 } | 30 } |
| 28 | 31 |
| 29 void InstantService::Shutdown() { | 32 void InstantService::Shutdown() { |
| 30 process_ids_.clear(); | 33 process_ids_.clear(); |
| 31 } | 34 } |
| 35 |
| 36 void InstantService::Observe(int type, |
| 37 const content::NotificationSource& source, |
| 38 const content::NotificationDetails& details) { |
| 39 int process_id = content::Source<content::RenderProcessHost>(source)->GetID(); |
| 40 process_ids_.erase(process_id); |
| 41 } |
| OLD | NEW |