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

Unified Diff: mojo/application/public/cpp/application_connection.h

Issue 1254383016: ApplicationConnection lifetime management changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/application/public/cpp/BUILD.gn ('k') | mojo/application/public/cpp/application_delegate.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/application/public/cpp/application_connection.h
diff --git a/mojo/application/public/cpp/application_connection.h b/mojo/application/public/cpp/application_connection.h
index 5fe14ef84109c2a2978e1ca41de6deaa10db4d13..e4affba14d589e8a25f8da1e9799f1a33a44808d 100644
--- a/mojo/application/public/cpp/application_connection.h
+++ b/mojo/application/public/cpp/application_connection.h
@@ -7,6 +7,7 @@
#include <string>
+#include "base/memory/weak_ptr.h"
#include "mojo/application/public/cpp/lib/interface_factory_connector.h"
#include "mojo/application/public/interfaces/service_provider.mojom.h"
@@ -45,11 +46,20 @@ class ServiceConnector;
// close a connection, call CloseConnection which will destroy this object.
class ApplicationConnection {
public:
- ApplicationConnection();
+ virtual ~ApplicationConnection() {}
- // Closes the connection and destroys this object. This is the only valid way
- // to destroy this object.
- void CloseConnection();
+ class TestApi {
+ public:
+ explicit TestApi(ApplicationConnection* connection)
+ : connection_(connection) {
+ }
+ base::WeakPtr<ApplicationConnection> GetWeakPtr() {
+ return connection_->GetWeakPtr();
+ }
+
+ private:
+ ApplicationConnection* connection_;
+ };
// See class description for details.
virtual void SetServiceConnector(ServiceConnector* connector) = 0;
@@ -107,21 +117,12 @@ class ApplicationConnection {
const Closure& handler) = 0;
protected:
- virtual ~ApplicationConnection();
-
- // Called to give the derived type to perform some cleanup before destruction.
- virtual void OnCloseConnection() = 0;
-
- private:
// Returns true if the connector was set, false if it was not set (e.g. by
// some filtering policy preventing this interface from being exposed).
virtual bool SetServiceConnectorForName(ServiceConnector* service_connector,
const std::string& name) = 0;
- // Ensures that CloseConnection can only be called once and the
- // ApplicationConnection's destructor can only be called after the connection
- // is closed.
- bool connection_closed_;
+ virtual base::WeakPtr<ApplicationConnection> GetWeakPtr() = 0;
};
} // namespace mojo
« no previous file with comments | « mojo/application/public/cpp/BUILD.gn ('k') | mojo/application/public/cpp/application_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698