| 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..949d22190747c2a77369125572f00fcd597d00fb
|
| --- /dev/null
|
| +++ b/chrome/browser/search/contextual_search_service.cc
|
| @@ -0,0 +1,54 @@
|
| +// 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 "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;
|
| +}
|
|
|