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