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

Side by Side Diff: ppapi/shared_impl/ppapi_globals.h

Issue 10910099: PPAPI: Make CompletionCallbacks work right on background threads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add ppb_message_loop_shared.cc/.h Created 8 years, 1 month 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 PPAPI_SHARED_IMPL_PPAPI_GLOBALS_H_ 5 #ifndef PPAPI_SHARED_IMPL_PPAPI_GLOBALS_H_
6 #define PPAPI_SHARED_IMPL_PPAPI_GLOBALS_H_ 6 #define PPAPI_SHARED_IMPL_PPAPI_GLOBALS_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/threading/thread_local.h" // For testing purposes only. 12 #include "base/threading/thread_local.h" // For testing purposes only.
13 #include "ppapi/c/dev/ppb_console_dev.h" 13 #include "ppapi/c/dev/ppb_console_dev.h"
14 #include "ppapi/c/pp_instance.h" 14 #include "ppapi/c/pp_instance.h"
15 #include "ppapi/c/pp_module.h" 15 #include "ppapi/c/pp_module.h"
16 #include "ppapi/shared_impl/api_id.h" 16 #include "ppapi/shared_impl/api_id.h"
17 #include "ppapi/shared_impl/ppapi_shared_export.h" 17 #include "ppapi/shared_impl/ppapi_shared_export.h"
18 18
19 namespace base { 19 namespace base {
20 class Lock; 20 class Lock;
21 class MessageLoopProxy; 21 class MessageLoopProxy;
22 } 22 }
23 23
24 namespace ppapi { 24 namespace ppapi {
25 25
26 class CallbackTracker; 26 class CallbackTracker;
27 class MessageLoopShared;
27 class ResourceTracker; 28 class ResourceTracker;
28 class VarTracker; 29 class VarTracker;
29 30
30 namespace thunk { 31 namespace thunk {
31 class PPB_Instance_API; 32 class PPB_Instance_API;
32 class ResourceCreationAPI; 33 class ResourceCreationAPI;
33 } 34 }
34 35
35 // Abstract base class 36 // Abstract base class
36 class PPAPI_SHARED_EXPORT PpapiGlobals { 37 class PPAPI_SHARED_EXPORT PpapiGlobals {
37 public: 38 public:
39 // Must be created on the main thread.
38 PpapiGlobals(); 40 PpapiGlobals();
39 41
40 // This constructor is to be used only for making a PpapiGlobal for testing 42 // This constructor is to be used only for making a PpapiGlobal for testing
41 // purposes. This avoids setting the global static ppapi_globals_. For unit 43 // purposes. This avoids setting the global static ppapi_globals_. For unit
42 // tests that use this feature, the "test" PpapiGlobals should be constructed 44 // tests that use this feature, the "test" PpapiGlobals should be constructed
43 // using this method. See SetPpapiGlobalsOnThreadForTest for more information. 45 // using this method. See SetPpapiGlobalsOnThreadForTest for more information.
44 struct ForTest {}; 46 struct ForTest {};
45 PpapiGlobals(ForTest); 47 explicit PpapiGlobals(ForTest);
46 48
47 virtual ~PpapiGlobals(); 49 virtual ~PpapiGlobals();
48 50
49 // Getter for the global singleton. 51 // Getter for the global singleton.
50 inline static PpapiGlobals* Get() { 52 inline static PpapiGlobals* Get() {
51 if (ppapi_globals_) 53 if (ppapi_globals_)
52 return ppapi_globals_; 54 return ppapi_globals_;
53 // In unit tests, the following might be valid (see 55 // In unit tests, the following might be valid (see
54 // SetPpapiGlobalsOnThreadForTest). Normally, this will just return NULL. 56 // SetPpapiGlobalsOnThreadForTest). Normally, this will just return NULL.
55 return GetThreadLocalPointer(); 57 return GetThreadLocalPointer();
56 } 58 }
57 59
58 // This allows us to set a given PpapiGlobals object as the PpapiGlobals for 60 // This allows us to set a given PpapiGlobals object as the PpapiGlobals for
59 // a given thread. After setting the PpapiGlobals for a thread, Get() will 61 // a given thread. After setting the PpapiGlobals for a thread, Get() will
60 // return that PpapiGlobals when Get() is called on that thread. Other threads 62 // return that PpapiGlobals when Get() is called on that thread. Other threads
61 // are unaffected. This allows us to have tests which use >1 PpapiGlobals in 63 // are unaffected. This allows us to have tests which use >1 PpapiGlobals in
62 // the same process, e.g. for having 1 thread emulate the "host" and 1 thread 64 // the same process, e.g. for having 1 thread emulate the "host" and 1 thread
63 // emulate the "plugin". 65 // emulate the "plugin".
64 // 66 //
65 // PpapiGlobals object must have been constructed using the "ForTest" 67 // PpapiGlobals object must have been constructed using the "ForTest"
66 // parameter. 68 // parameter.
67 static void SetPpapiGlobalsOnThreadForTest(PpapiGlobals* ptr); 69 static void SetPpapiGlobalsOnThreadForTest(PpapiGlobals* ptr);
68 70
69 // Retrieves the corresponding tracker. 71 // Retrieves the corresponding tracker.
70 virtual ResourceTracker* GetResourceTracker() = 0; 72 virtual ResourceTracker* GetResourceTracker() = 0;
71 virtual VarTracker* GetVarTracker() = 0; 73 virtual VarTracker* GetVarTracker() = 0;
72 virtual CallbackTracker* GetCallbackTrackerForInstance( 74 virtual CallbackTracker* GetCallbackTrackerForInstance(
73 PP_Instance instance) = 0; 75 PP_Instance instance) = 0;
76
74 virtual base::Lock* GetProxyLock() = 0; 77 virtual base::Lock* GetProxyLock() = 0;
75 78
76 // Logs the given string to the JS console. If "source" is empty, the name of 79 // Logs the given string to the JS console. If "source" is empty, the name of
77 // the current module will be used, if it can be determined. 80 // the current module will be used, if it can be determined.
78 virtual void LogWithSource(PP_Instance instance, 81 virtual void LogWithSource(PP_Instance instance,
79 PP_LogLevel_Dev level, 82 PP_LogLevel_Dev level,
80 const std::string& source, 83 const std::string& source,
81 const std::string& value) = 0; 84 const std::string& value) = 0;
82 85
83 // Like LogWithSource but broadcasts the log to all instances of the given 86 // Like LogWithSource but broadcasts the log to all instances of the given
(...skipping 12 matching lines...) Expand all
96 // Returns the given API object associated with the given instance, or NULL 99 // Returns the given API object associated with the given instance, or NULL
97 // if the instance is invalid. 100 // if the instance is invalid.
98 virtual thunk::PPB_Instance_API* GetInstanceAPI(PP_Instance instance) = 0; 101 virtual thunk::PPB_Instance_API* GetInstanceAPI(PP_Instance instance) = 0;
99 virtual thunk::ResourceCreationAPI* GetResourceCreationAPI( 102 virtual thunk::ResourceCreationAPI* GetResourceCreationAPI(
100 PP_Instance instance) = 0; 103 PP_Instance instance) = 0;
101 104
102 // Returns the PP_Module associated with the given PP_Instance, or 0 on 105 // Returns the PP_Module associated with the given PP_Instance, or 0 on
103 // failure. 106 // failure.
104 virtual PP_Module GetModuleForInstance(PP_Instance instance) = 0; 107 virtual PP_Module GetModuleForInstance(PP_Instance instance) = 0;
105 108
106 // Returns the base::MessageLoopProxy for the main thread. Note that this must 109 // Returns the base::MessageLoopProxy for the main thread. This is set in the
107 // be called on the main thread the first time so that it can initialize 110 // constructor, so PpapiGlobals must be created on the main thread.
108 // its static data.
109 base::MessageLoopProxy* GetMainThreadMessageLoop(); 111 base::MessageLoopProxy* GetMainThreadMessageLoop();
110 112
113 // Return the MessageLoopShared of the current thread, if any. This will
114 // alwas return NULL on the host side, where PPB_MessageLoop is not supported.
brettw 2012/11/06 23:16:28 "alwas" spelling
dmichael (off chromium) 2012/11/06 23:39:26 Darn, that put me over 80 chars ;-)
115 virtual MessageLoopShared* GetCurrentMessageLoop() = 0;
116
111 // Returns the command line for the process. 117 // Returns the command line for the process.
112 virtual std::string GetCmdLine() = 0; 118 virtual std::string GetCmdLine() = 0;
113 119
114 // Preloads the font on Windows, does nothing on other platforms. 120 // Preloads the font on Windows, does nothing on other platforms.
115 // TODO(brettw) remove this by passing the instance into the API so we don't 121 // TODO(brettw) remove this by passing the instance into the API so we don't
116 // have to have it on the globals. 122 // have to have it on the globals.
117 virtual void PreCacheFontForFlash(const void* logfontw) = 0; 123 virtual void PreCacheFontForFlash(const void* logfontw) = 0;
118 124
119 virtual bool IsHostGlobals() const; 125 virtual bool IsHostGlobals() const;
120 virtual bool IsPluginGlobals() const; 126 virtual bool IsPluginGlobals() const;
121 127
122 private: 128 private:
123 // Return the thread-local pointer which is used only for unit testing. It 129 // Return the thread-local pointer which is used only for unit testing. It
124 // should always be NULL when running in production. It allows separate 130 // should always be NULL when running in production. It allows separate
125 // threads to have distinct "globals". 131 // threads to have distinct "globals".
126 static PpapiGlobals* GetThreadLocalPointer(); 132 static PpapiGlobals* GetThreadLocalPointer();
127 133
128 static PpapiGlobals* ppapi_globals_; 134 static PpapiGlobals* ppapi_globals_;
129 135
130 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; 136 scoped_refptr<base::MessageLoopProxy> main_loop_proxy_;
131 137
132 DISALLOW_COPY_AND_ASSIGN(PpapiGlobals); 138 DISALLOW_COPY_AND_ASSIGN(PpapiGlobals);
133 }; 139 };
134 140
135 } // namespace ppapi 141 } // namespace ppapi
136 142
137 #endif // PPAPI_SHARED_IMPL_PPAPI_GLOBALS_H_ 143 #endif // PPAPI_SHARED_IMPL_PPAPI_GLOBALS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698