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

Side by Side Diff: services/shell/public/cpp/shell_connection_ref.h

Issue 2131493002: ShellConnection -> ServiceContext (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@st
Patch Set: . Created 4 years, 5 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 2016 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 SERVICES_SHELL_PUBLIC_CPP_SHELL_CONNECTION_REF_H_
6 #define SERVICES_SHELL_PUBLIC_CPP_SHELL_CONNECTION_REF_H_
7
8 #include <memory>
9
10 #include "base/callback.h"
11 #include "base/macros.h"
12 #include "base/memory/weak_ptr.h"
13
14 namespace shell {
15
16 class ShellConnectionRefImpl;
17
18 // An interface implementation can keep this object as a member variable to
19 // hold a reference to the ShellConnection, keeping it alive as long as the
20 // bound implementation exists.
21 //
22 // This class is safe to use on any thread and instances may be passed to other
23 // threads. However, each instance should only be used on one thread at a time,
24 // otherwise there'll be races between the AddRef resulting from cloning and
25 // destruction.
26 class ShellConnectionRef {
27 public:
28 virtual ~ShellConnectionRef() {}
29
30 virtual std::unique_ptr<ShellConnectionRef> Clone() = 0;
31 };
32
33 class ShellConnectionRefFactory {
34 public:
35 // |quit_closure| is called whenever the last ref is destroyed.
36 explicit ShellConnectionRefFactory(const base::Closure& quit_closure);
37 ~ShellConnectionRefFactory();
38
39 std::unique_ptr<ShellConnectionRef> CreateRef();
40
41 bool HasNoRefs() const { return !ref_count_; }
42
43 private:
44 friend ShellConnectionRefImpl;
45
46 // Called from ShellConnectionRefImpl.
47 void AddRef();
48 void Release();
49
50 const base::Closure quit_closure_;
51 int ref_count_ = 0;
52 base::WeakPtrFactory<ShellConnectionRefFactory> weak_factory_;
53
54 DISALLOW_COPY_AND_ASSIGN(ShellConnectionRefFactory);
55 };
56
57 } // namespace shell
58
59 #endif // SERVICES_SHELL_PUBLIC_CPP_SHELL_CONNECTION_REF_H_
OLDNEW
« no previous file with comments | « services/shell/public/cpp/shell_connection.h ('k') | services/shell/runner/child/test_native_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698