Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/search/contextual_search_service.h" | |
| 6 | |
| 7 #include "base/memory/singleton.h" | |
|
kmadhusu
2015/10/08 22:05:02
This header file is already included in the .h fil
Donn Denman
2015/10/09 20:46:43
Done.
| |
| 8 #include "content/public/browser/notification_service.h" | |
| 9 #include "content/public/browser/notification_types.h" | |
| 10 #include "content/public/browser/render_process_host.h" | |
| 11 | |
| 12 namespace { | |
| 13 int kInvalidProcessId = -1; | |
| 14 } | |
| 15 | |
| 16 // static | |
| 17 ContextualSearchService* ContextualSearchService::GetInstance() { | |
| 18 return base::Singleton<ContextualSearchService>::get(); | |
| 19 } | |
| 20 | |
| 21 ContextualSearchService::ContextualSearchService() | |
| 22 : process_id_(kInvalidProcessId) { | |
| 23 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | |
| 24 content::NotificationService::AllSources()); | |
| 25 } | |
| 26 | |
| 27 ContextualSearchService::~ContextualSearchService() {} | |
| 28 | |
| 29 void ContextualSearchService::SetContextualSearchProcess(int process_id) { | |
| 30 process_id_ = process_id; | |
| 31 } | |
| 32 | |
| 33 bool ContextualSearchService::IsContextualSearchProcess(int process_id) const { | |
| 34 return process_id == process_id_; | |
| 35 } | |
| 36 | |
| 37 void ContextualSearchService::Observe( | |
| 38 int type, | |
| 39 const content::NotificationSource& source, | |
| 40 const content::NotificationDetails& details) { | |
| 41 switch (type) { | |
| 42 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: | |
| 43 OnRendererProcessTerminated( | |
| 44 content::Source<content::RenderProcessHost>(source)->GetID()); | |
| 45 break; | |
| 46 default: | |
| 47 NOTREACHED() | |
| 48 << "Unexpected notification type in ContextualSearchService."; | |
| 49 } | |
| 50 } | |
| 51 | |
| 52 void ContextualSearchService::OnRendererProcessTerminated(int process_id) { | |
| 53 if (process_id == process_id_) | |
| 54 process_id = kInvalidProcessId; | |
|
kmadhusu
2015/10/08 22:05:01
Did you mean process_id_?
Donn Denman
2015/10/09 20:46:43
Nice catch! Done.
| |
| 55 } | |
| OLD | NEW |