Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / components / nacl / renderer / nexe_load_manager.h
blob2470199940fc2b386ba03a3386342284742c0104
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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_NACL_RENDERER_NEXE_LOAD_MANAGER_H_
6 #define COMPONENTS_NACL_RENDERER_NEXE_LOAD_MANAGER_H_
8 #include <map>
9 #include <string>
11 #include "base/files/file.h"
12 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/shared_memory.h"
15 #include "base/memory/weak_ptr.h"
16 #include "base/time/time.h"
17 #include "components/nacl/renderer/ppb_nacl_private.h"
18 #include "url/gurl.h"
20 namespace content {
21 class PepperPluginInstance;
24 namespace nacl {
26 class ManifestServiceChannel;
27 class TrustedPluginChannel;
29 // NexeLoadManager provides methods for reporting the progress of loading a
30 // nexe.
31 class NexeLoadManager {
32 public:
33 explicit NexeLoadManager(PP_Instance instance);
34 ~NexeLoadManager();
36 void NexeFileDidOpen(int32_t pp_error,
37 const base::File& file,
38 int32_t http_status,
39 int64_t nexe_bytes_read,
40 const std::string& url,
41 base::TimeDelta time_since_open);
42 void ReportLoadSuccess(const std::string& url,
43 uint64_t loaded_bytes,
44 uint64_t total_bytes);
45 void ReportLoadError(PP_NaClError error,
46 const std::string& error_message);
48 // console_message is a part of the error that is logged to
49 // the JavaScript console but is not reported to JavaScript via
50 // the lastError property. This is used to report internal errors which
51 // may easily change in new versions of the browser and we don't want apps
52 // to come to depend on the details of these errors.
53 void ReportLoadError(PP_NaClError error,
54 const std::string& error_message,
55 const std::string& console_message);
56 void ReportLoadAbort();
57 void NexeDidCrash();
59 // TODO(dmichael): Everything below this comment should eventually be made
60 // private, when ppb_nacl_private_impl.cc is no longer using them directly.
61 // The intent is for this class to only expose functions for reporting a
62 // load state transition (e.g., ReportLoadError, ReportProgress,
63 // ReportLoadAbort, etc.)
64 void set_trusted_plugin_channel(scoped_ptr<TrustedPluginChannel> channel);
65 void set_manifest_service_channel(
66 scoped_ptr<ManifestServiceChannel> channel);
68 PP_NaClReadyState nacl_ready_state();
69 void set_nacl_ready_state(PP_NaClReadyState ready_state);
71 void SetReadOnlyProperty(PP_Var key, PP_Var value);
72 void SetLastError(const std::string& error);
73 void LogToConsole(const std::string& message);
75 bool is_installed() const { return is_installed_; }
77 int32_t exit_status() const { return exit_status_; }
78 void set_exit_status(int32_t exit_status);
80 void InitializePlugin(uint32_t argc, const char* argn[], const char* argv[]);
82 void ReportStartupOverhead() const;
84 int64_t nexe_size() const { return nexe_size_; }
86 bool RequestNaClManifest(const std::string& url);
87 void ProcessNaClManifest(const std::string& program_url);
89 // URL resolution support.
90 // plugin_base_url is the URL used for resolving relative URLs used in
91 // src="...".
92 const GURL& plugin_base_url() const { return plugin_base_url_; }
94 // manifest_base_url is the URL used for resolving relative URLs mentioned
95 // in manifest files. If the manifest is a data URI, this is an empty string
96 const GURL& manifest_base_url() const { return manifest_base_url_; }
98 // Returns the manifest URL passed as an argument for this plugin instance.
99 std::string GetManifestURLArgument() const;
101 // Returns true if the MIME type for this plugin matches the type for PNaCl,
102 // false otherwise.
103 bool IsPNaCl() const;
105 // Returns true if dev interfaces are enabled for this plugin.
106 bool DevInterfacesEnabled() const;
108 // Returns the time that the work for PNaCl translation began.
109 base::Time pnacl_start_time() const { return pnacl_start_time_; }
110 void set_pnacl_start_time(base::Time time) {
111 pnacl_start_time_ = time;
114 const std::string& program_url() const { return program_url_; }
116 void set_crash_info_shmem_handle(base::SharedMemoryHandle h) {
117 crash_info_shmem_handle_ = h;
120 bool nonsfi() const { return nonsfi_; }
121 void set_nonsfi(bool nonsfi) { nonsfi_ = nonsfi; }
123 private:
124 DISALLOW_COPY_AND_ASSIGN(NexeLoadManager);
126 void ReportDeadNexe();
128 // Copies a crash log to the console, one line at a time.
129 void CopyCrashLogToJsConsole(const std::string& crash_log);
131 PP_Instance pp_instance_;
132 PP_NaClReadyState nacl_ready_state_;
133 bool nexe_error_reported_;
135 std::string program_url_;
137 // A flag indicating if the NaCl executable is being loaded from an installed
138 // application. This flag is used to bucket UMA statistics more precisely to
139 // help determine whether nexe loading problems are caused by networking
140 // issues. (Installed applications will be loaded from disk.)
141 // Unfortunately, the definition of what it means to be part of an installed
142 // application is a little murky - for example an installed application can
143 // register a mime handler that loads NaCl executables into an arbitrary web
144 // page. As such, the flag actually means "our best guess, based on the URLs
145 // for NaCl resources that we have seen so far".
146 bool is_installed_;
148 // Time of a successful nexe load.
149 base::Time ready_time_;
151 // Time of plugin initialization.
152 base::Time init_time_;
154 // Time of the start of loading a NaCl module.
155 base::Time load_start_;
157 // The exit status of the plugin process.
158 // This will have a value in the range (0x00-0xff) if the exit status is set,
159 // or -1 if set_exit_status() has never been called.
160 int32_t exit_status_;
162 // Size of the downloaded nexe, in bytes.
163 int64_t nexe_size_;
165 // Non-owning.
166 content::PepperPluginInstance* plugin_instance_;
168 // The URL for the document corresponding to this plugin instance.
169 GURL plugin_base_url_;
171 GURL manifest_base_url_;
173 // Arguments passed to this plugin instance from the DOM.
174 std::map<std::string, std::string> args_;
176 // We store mime_type_ outside of args_ explicitly because we change it to be
177 // lowercase.
178 std::string mime_type_;
180 base::Time pnacl_start_time_;
182 // A flag that indicates if the plugin is using Non-SFI mode.
183 bool nonsfi_;
185 base::SharedMemoryHandle crash_info_shmem_handle_;
187 scoped_ptr<TrustedPluginChannel> trusted_plugin_channel_;
188 scoped_ptr<ManifestServiceChannel> manifest_service_channel_;
189 base::WeakPtrFactory<NexeLoadManager> weak_factory_;
192 } // namespace nacl
194 #endif // COMPONENTS_NACL_RENDERER_NEXE_LOAD_MANAGER_H_