#ifndef COMPONENTS_NACL_RENDERER_NEXE_LOAD_MANAGER_H_
#define COMPONENTS_NACL_RENDERER_NEXE_LOAD_MANAGER_H_
#include <string>
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "ppapi/c/private/ppb_nacl_private.h"
namespace content {
class PepperPluginInstance;
}
namespace nacl {
class TrustedPluginChannel;
class NexeLoadManager {
public:
explicit NexeLoadManager(PP_Instance instance);
~NexeLoadManager();
void ReportLoadSuccess(const std::string& url,
uint64_t loaded_bytes,
uint64_t total_bytes);
void ReportLoadError(PP_NaClError error,
const std::string& error_message,
const std::string& console_message);
void ReportLoadAbort();
void NexeDidCrash(const char* crash_log);
struct ProgressEvent {
explicit ProgressEvent(PP_NaClEventType event_type_param)
: event_type(event_type_param),
length_is_computable(false),
loaded_bytes(0),
total_bytes(0) {
}
ProgressEvent(PP_Instance instance, PP_NaClEventType event_type,
const std::string& resource_url, bool length_is_computable,
uint64_t loaded_bytes, uint64_t total_bytes)
: instance(instance),
event_type(event_type),
resource_url(resource_url),
length_is_computable(length_is_computable),
loaded_bytes(loaded_bytes),
total_bytes(total_bytes) {
}
PP_Instance instance;
PP_NaClEventType event_type;
std::string resource_url;
bool length_is_computable;
uint64_t loaded_bytes;
uint64_t total_bytes;
};
void DispatchEvent(const ProgressEvent &event);
void set_trusted_plugin_channel(scoped_ptr<TrustedPluginChannel> channel);
PP_NaClReadyState nacl_ready_state();
void set_nacl_ready_state(PP_NaClReadyState ready_state);
void SetReadOnlyProperty(PP_Var key, PP_Var value);
void SetLastError(const std::string& error);
void LogToConsole(const std::string& message);
bool is_installed() const { return is_installed_; }
void set_is_installed(bool installed) { is_installed_ = installed; }
void set_ready_time() { ready_time_ = base::Time::Now(); }
int32_t exit_status() const { return exit_status_; }
void set_exit_status(int32_t exit_status);
private:
DISALLOW_COPY_AND_ASSIGN(NexeLoadManager);
void ReportDeadNexe();
void CopyCrashLogToJsConsole(const std::string& crash_log);
PP_Instance pp_instance_;
PP_NaClReadyState nacl_ready_state_;
bool nexe_error_reported_;
bool is_installed_;
base::Time ready_time_;
int32_t exit_status_;
content::PepperPluginInstance* plugin_instance_;
scoped_ptr<TrustedPluginChannel> trusted_plugin_channel_;
base::WeakPtrFactory<NexeLoadManager> weak_factory_;
};
}
#endif