Index: chrome/browser/search/contextual_search_service.cc |
diff --git a/chrome/browser/search/contextual_search_service.cc b/chrome/browser/search/contextual_search_service.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..547c4bc94979e4a98290f68b6f5b680bad707712 |
--- /dev/null |
+++ b/chrome/browser/search/contextual_search_service.cc |
@@ -0,0 +1,55 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/search/contextual_search_service.h" |
+ |
+#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.
|
+#include "content/public/browser/notification_service.h" |
+#include "content/public/browser/notification_types.h" |
+#include "content/public/browser/render_process_host.h" |
+ |
+namespace { |
+ int kInvalidProcessId = -1; |
+} |
+ |
+// static |
+ContextualSearchService* ContextualSearchService::GetInstance() { |
+ return base::Singleton<ContextualSearchService>::get(); |
+} |
+ |
+ContextualSearchService::ContextualSearchService() |
+ : process_id_(kInvalidProcessId) { |
+ registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
+ content::NotificationService::AllSources()); |
+} |
+ |
+ContextualSearchService::~ContextualSearchService() {} |
+ |
+void ContextualSearchService::SetContextualSearchProcess(int process_id) { |
+ process_id_ = process_id; |
+} |
+ |
+bool ContextualSearchService::IsContextualSearchProcess(int process_id) const { |
+ return process_id == process_id_; |
+} |
+ |
+void ContextualSearchService::Observe( |
+ int type, |
+ const content::NotificationSource& source, |
+ const content::NotificationDetails& details) { |
+ switch (type) { |
+ case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: |
+ OnRendererProcessTerminated( |
+ content::Source<content::RenderProcessHost>(source)->GetID()); |
+ break; |
+ default: |
+ NOTREACHED() |
+ << "Unexpected notification type in ContextualSearchService."; |
+ } |
+} |
+ |
+void ContextualSearchService::OnRendererProcessTerminated(int process_id) { |
+ if (process_id == process_id_) |
+ 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.
|
+} |