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

Side by Side Diff: ppapi/cpp/instance_handle.h

Issue 9381010: Convert resources to take an instance key instead of an Instance*. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: USELESS PATCH TITLE Created 8 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « ppapi/cpp/instance.cc ('k') | ppapi/cpp/instance_handle.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 PPAPI_CPP_INSTANCE_HANDLE_H_
6 #define PPAPI_CPP_INSTANCE_HANDLE_H_
7
8 #include "ppapi/c/pp_instance.h"
9
10 namespace pp {
11
12 class Instance;
13
14 /// An instance handle identifies an instance in a constructor for a resource.
15 /// Its existence solves two different problems:
16 ///
17 /// A pp::Instance objects' lifetime is managed by the system on the main thread
18 /// of the plugin. This means that it may get destroyed at any time based on
19 /// something that happens on the web page. This means that it's never OK to
20 /// refer to a pp::Instance object on a background thread. So we need to pass
21 /// some kind of identifier instead to resource constructors so that they may
22 /// safely be used on background threads. If the instance becomes invalid, the
23 /// resource creation will fail on the background thread, but it won't crash.
24 ///
25 /// Background: PP_Instance would be a good identifier to use for this case.
26 /// However, using it in the constructor to resources is problematic.
27 /// PP_Instance is just a typedef for an integer, as is a PP_Resource. Many
28 /// resources have alternate constructors that just take an existing
29 /// PP_Resource, so the constructors would be ambiguous. Having this wrapper
30 /// around a PP_Instance prevents this ambiguity, and also gives us a nice
31 /// place to consolidate an implicit conversion from pp::Instance* for prettier
32 /// code on the main thread (you can just pass "this" to resource constructors
33 /// in your instance objects).
34 ///
35 /// So you should always pass InstanceHandles to background threads instead of
36 /// a pp::Instance, and use them in resource constructors and code that may be
37 /// used from background threads.
38 class InstanceHandle {
39 public:
40 /// Implicit constructor for converting a pp::Instance to an instance handle.
41 InstanceHandle(Instance* instance);
42
43 /// Explicitly convert a PP_Instance to an instance handle. This should not
44 /// be implicit because it can make some resource constructors ambiguous.
45 /// PP_Instance is just a typedef for an integer, as is PP_Resource, so the
46 /// compiler can get confused between the two.
47 explicit InstanceHandle(PP_Instance pp_instance)
48 : pp_instance_(pp_instance) {}
49
50 PP_Instance pp_instance() const { return pp_instance_; }
51
52 private:
53 PP_Instance pp_instance_;
54 };
55
56 } // namespace pp
57
58 #endif // PPAPI_CPP_INSTANCE_HANDLE_H_
OLDNEW
« no previous file with comments | « ppapi/cpp/instance.cc ('k') | ppapi/cpp/instance_handle.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698