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 "content/public/browser/notification_service.h" |
| 8 #include "content/public/browser/notification_types.h" |
| 9 #include "content/public/browser/render_process_host.h" |
| 10 |
| 11 namespace { |
| 12 int kInvalidProcessId = -1; |
| 13 } |
| 14 |
| 15 // static |
| 16 ContextualSearchService* ContextualSearchService::GetInstance() { |
| 17 return base::Singleton<ContextualSearchService>::get(); |
| 18 } |
| 19 |
| 20 ContextualSearchService::ContextualSearchService() |
| 21 : process_id_(kInvalidProcessId) { |
| 22 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
| 23 content::NotificationService::AllSources()); |
| 24 } |
| 25 |
| 26 ContextualSearchService::~ContextualSearchService() {} |
| 27 |
| 28 void ContextualSearchService::SetContextualSearchProcess(int process_id) { |
| 29 process_id_ = process_id; |
| 30 } |
| 31 |
| 32 bool ContextualSearchService::IsContextualSearchProcess(int process_id) const { |
| 33 return process_id == process_id_; |
| 34 } |
| 35 |
| 36 void ContextualSearchService::Observe( |
| 37 int type, |
| 38 const content::NotificationSource& source, |
| 39 const content::NotificationDetails& details) { |
| 40 switch (type) { |
| 41 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: |
| 42 OnRendererProcessTerminated( |
| 43 content::Source<content::RenderProcessHost>(source)->GetID()); |
| 44 break; |
| 45 default: |
| 46 NOTREACHED() |
| 47 << "Unexpected notification type in ContextualSearchService."; |
| 48 } |
| 49 } |
| 50 |
| 51 void ContextualSearchService::OnRendererProcessTerminated(int process_id) { |
| 52 if (process_id == process_id_) |
| 53 process_id_ = kInvalidProcessId; |
| 54 } |
OLD | NEW |