weak_service_provider.cc revision 6e8cce623b6e4fe0c9e4af605d675dd9d0338c38
1// Copyright 2014 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 "mojo/public/cpp/application/lib/weak_service_provider.h"
6
7#include "mojo/public/cpp/application/service_provider_impl.h"
8#include "mojo/public/interfaces/application/service_provider.mojom.h"
9
10namespace mojo {
11namespace internal {
12
13WeakServiceProvider::WeakServiceProvider(ServiceProviderImpl* creator,
14                                         ServiceProvider* service_provider)
15      : creator_(creator),
16        service_provider_(service_provider) {}
17
18WeakServiceProvider::~WeakServiceProvider() {
19  if (creator_)
20    creator_->ClearRemote();
21}
22
23void WeakServiceProvider::Clear() {
24  creator_ = NULL;
25  service_provider_ = NULL;
26}
27
28void WeakServiceProvider::ConnectToService(
29    const String& service_name,
30    ScopedMessagePipeHandle client_handle) {
31  if (service_provider_)
32    service_provider_->ConnectToService(service_name, client_handle.Pass());
33}
34
35}  // namespace internal
36}  // namespace mojo
37