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

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

Issue 835253002: Update mojo sdk to rev e3719475d5971283d1d2250533d53066b2ff9797 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « mojo/public/VERSION ('k') | mojo/public/cpp/system/handle.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MOJO_PUBLIC_CPP_APPLICATION_LAZY_INTERFACE_PTR_H_ 5 #ifndef MOJO_PUBLIC_CPP_APPLICATION_LAZY_INTERFACE_PTR_H_
6 #define MOJO_PUBLIC_CPP_APPLICATION_LAZY_INTERFACE_PTR_H_ 6 #define MOJO_PUBLIC_CPP_APPLICATION_LAZY_INTERFACE_PTR_H_
7 7
8 #include "mojo/public/cpp/application/connect.h" 8 #include "mojo/public/cpp/application/connect.h"
9 #include "mojo/public/interfaces/application/service_provider.mojom.h" 9 #include "mojo/public/interfaces/application/service_provider.mojom.h"
10 10
11 namespace mojo { 11 namespace mojo {
12 12
13 template <typename Interface> 13 template <typename Interface>
14 class LazyInterfacePtr : public InterfacePtr<Interface> { 14 class LazyInterfacePtr : public InterfacePtr<Interface> {
15 public: 15 public:
16 LazyInterfacePtr() : service_provider_(nullptr) {} 16 LazyInterfacePtr() : service_provider_(nullptr) {}
17 17
18 LazyInterfacePtr(ServiceProvider* service_provider) 18 LazyInterfacePtr(ServiceProvider* service_provider)
19 : service_provider_(service_provider) {} 19 : service_provider_(service_provider) {}
20 20
21 void set_service_provider(ServiceProvider* service_provider) { 21 void set_service_provider(ServiceProvider* service_provider) {
22 if (service_provider != service_provider_) { 22 if (service_provider != service_provider_) {
23 InterfacePtr<Interface>::reset(); 23 InterfacePtr<Interface>::reset();
24 } 24 }
25 service_provider_ = service_provider; 25 service_provider_ = service_provider;
26 } 26 }
27 27
28 Interface* get() const { 28 Interface* get() const {
29 if (!InterfacePtr<Interface>::get()) { 29 if (!InterfacePtr<Interface>::get() && service_provider_) {
30 mojo::ConnectToService<Interface>( 30 mojo::ConnectToService<Interface>(
31 service_provider_, const_cast<LazyInterfacePtr<Interface>*>(this)); 31 service_provider_, const_cast<LazyInterfacePtr<Interface>*>(this));
32 } 32 }
33 return InterfacePtr<Interface>::get(); 33 return InterfacePtr<Interface>::get();
34 } 34 }
35 Interface* operator->() const { return get(); } 35 Interface* operator->() const { return get(); }
36 Interface& operator*() const { return *get(); } 36 Interface& operator*() const { return *get(); }
37 37
38 private: 38 private:
39 ServiceProvider* service_provider_; 39 ServiceProvider* service_provider_;
40 }; 40 };
41 41
42 } // namespace mojo 42 } // namespace mojo
43 43
44 #endif // MOJO_PUBLIC_CPP_APPLICATION_LAZY_INTERFACE_PTR_H_ 44 #endif // MOJO_PUBLIC_CPP_APPLICATION_LAZY_INTERFACE_PTR_H_
OLDNEW
« no previous file with comments | « mojo/public/VERSION ('k') | mojo/public/cpp/system/handle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698