Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1264)

Side by Side Diff: mojo/public/cpp/application/lazy_interface_ptr.h

Issue 814543006: Move //mojo/{public, edk} underneath //third_party (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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 #ifndef MOJO_PUBLIC_CPP_APPLICATION_LAZY_INTERFACE_PTR_H_
6 #define MOJO_PUBLIC_CPP_APPLICATION_LAZY_INTERFACE_PTR_H_
7
8 #include "mojo/public/cpp/application/connect.h"
9 #include "mojo/public/interfaces/application/service_provider.mojom.h"
10
11 namespace mojo {
12
13 template <typename Interface>
14 class LazyInterfacePtr : public InterfacePtr<Interface> {
15 public:
16 LazyInterfacePtr() : service_provider_(nullptr) {}
17
18 LazyInterfacePtr(ServiceProvider* service_provider)
19 : service_provider_(service_provider) {}
20
21 void set_service_provider(ServiceProvider* service_provider) {
22 if (service_provider != service_provider_) {
23 InterfacePtr<Interface>::reset();
24 }
25 service_provider_ = service_provider;
26 }
27
28 Interface* get() const {
29 if (!InterfacePtr<Interface>::get() && service_provider_) {
30 mojo::ConnectToService<Interface>(
31 service_provider_, const_cast<LazyInterfacePtr<Interface>*>(this));
32 }
33 return InterfacePtr<Interface>::get();
34 }
35 Interface* operator->() const { return get(); }
36 Interface& operator*() const { return *get(); }
37
38 private:
39 ServiceProvider* service_provider_;
40 };
41
42 } // namespace mojo
43
44 #endif // MOJO_PUBLIC_CPP_APPLICATION_LAZY_INTERFACE_PTR_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/application/interface_factory_impl.h ('k') | mojo/public/cpp/application/lib/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698