Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / ppapi / native_client / src / trusted / plugin / pnacl_coordinator.h
index d1ab90e..5561be6 100644 (file)
@@ -5,24 +5,21 @@
 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_COORDINATOR_H_
 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_COORDINATOR_H_
 
-#include <set>
-#include <map>
 #include <vector>
 
 #include "native_client/src/include/nacl_macros.h"
-#include "native_client/src/include/nacl_string.h"
 #include "native_client/src/shared/platform/nacl_sync_raii.h"
 #include "native_client/src/shared/srpc/nacl_srpc.h"
 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h"
 
 #include "ppapi/cpp/completion_callback.h"
 
-#include "ppapi/native_client/src/trusted/plugin/callback_source.h"
-#include "ppapi/native_client/src/trusted/plugin/file_downloader.h"
 #include "ppapi/native_client/src/trusted/plugin/nacl_subprocess.h"
 #include "ppapi/native_client/src/trusted/plugin/plugin_error.h"
 #include "ppapi/native_client/src/trusted/plugin/pnacl_resources.h"
 
+#include "ppapi/utility/completion_callback_factory.h"
+
 struct PP_PNaClOptions;
 
 namespace plugin {
@@ -51,7 +48,7 @@ class TempFile;
 // Translation proceeds in two steps:
 // (1) llc translates the bitcode in pexe_url_ to an object in obj_file_.
 // (2) ld links the object code in obj_file_ and produces a nexe in nexe_file_.
-class PnaclCoordinator: public CallbackSource<FileStreamData> {
+class PnaclCoordinator {
  public:
   // Maximum number of object files passable to the translator. Cannot be
   // changed without changing the RPC signatures.
@@ -61,7 +58,7 @@ class PnaclCoordinator: public CallbackSource<FileStreamData> {
   // The factory method for translations.
   static PnaclCoordinator* BitcodeToNative(
       Plugin* plugin,
-      const nacl::string& pexe_url,
+      const std::string& pexe_url,
       const PP_PNaClOptions& pnacl_options,
       const pp::CompletionCallback& translate_notify_callback);
 
@@ -69,12 +66,6 @@ class PnaclCoordinator: public CallbackSource<FileStreamData> {
   // BitcodeToNative has completed (and the finish_callback called).
   PP_FileHandle TakeTranslatedFileHandle();
 
-  // Implement FileDownloader's template of the CallbackSource interface.
-  // This method returns a callback which will be called by the FileDownloader
-  // to stream the bitcode data as it arrives. The callback
-  // (BitcodeStreamGotData) passes it to llc over SRPC.
-  StreamCallback GetCallback();
-
   // Return a callback that should be notified when |bytes_compiled| bytes
   // have been compiled.
   pp::CompletionCallback GetCompileProgressCallback(int64_t bytes_compiled);
@@ -92,36 +83,32 @@ class PnaclCoordinator: public CallbackSource<FileStreamData> {
             expected_pexe_size_) < kProgressEventSlopPct;
   }
 
+
+  void BitcodeStreamCacheHit(PP_FileHandle handle);
+  void BitcodeStreamCacheMiss(int64_t expected_pexe_size,
+                              PP_FileHandle handle);
+
+  // Invoked when a pexe data chunk arrives (when using streaming translation)
+  void BitcodeStreamGotData(const void* data, int32_t length);
+
+  // Invoked when the pexe download finishes (using streaming translation)
+  void BitcodeStreamDidFinish(int32_t pp_error);
+
  private:
   NACL_DISALLOW_COPY_AND_ASSIGN(PnaclCoordinator);
 
   // BitcodeToNative is the factory method for PnaclCoordinators.
   // Therefore the constructor is private.
   PnaclCoordinator(Plugin* plugin,
-                   const nacl::string& pexe_url,
+                   const std::string& pexe_url,
                    const PP_PNaClOptions& pnacl_options,
                    const pp::CompletionCallback& translate_notify_callback);
 
   // Invoke to issue a GET request for bitcode.
   void OpenBitcodeStream();
-  // Invoked when we've started an URL fetch for the pexe to check for
-  // caching metadata.
-  void BitcodeStreamDidOpen(int32_t pp_error);
-
-  // Callback for when the resource info JSON file has been read.
-  void ResourceInfoWasRead(int32_t pp_error);
-
-  // Callback for when llc and ld have been downloaded.
-  void ResourcesDidLoad(int32_t pp_error);
-  // Invoked when we've gotten a temp FD for the nexe, either with the nexe
-  // data, or a writeable fd to save to.
-  void NexeFdDidOpen(int32_t pp_error);
-  // Invoked when a pexe data chunk arrives (when using streaming translation)
-  void BitcodeStreamGotData(int32_t pp_error, FileStreamData data);
+
   // Invoked when a pexe data chunk is compiled.
   void BitcodeGotCompiled(int32_t pp_error, int64_t bytes_compiled);
-  // Invoked when the pexe download finishes (using streaming translation)
-  void BitcodeStreamDidFinish(int32_t pp_error);
   // Once llc and ld nexes have been loaded and the two temporary files have
   // been created, this starts the translation.  Translation starts two
   // subprocesses, one for llc and one for ld.
@@ -139,12 +126,12 @@ class PnaclCoordinator: public CallbackSource<FileStreamData> {
   void ExitWithError();
   // Run |translate_notify_callback_| with an error condition that is not
   // PPAPI specific.  Also set ErrorInfo report.
-  void ReportNonPpapiError(PP_NaClError err, const nacl::string& message);
+  void ReportNonPpapiError(PP_NaClError err, const std::string& message);
   // Run when faced with a PPAPI error condition. Bring control back to the
   // plugin by invoking the |translate_notify_callback_|.
   // Also set ErrorInfo report.
   void ReportPpapiError(PP_NaClError err,
-                        int32_t pp_error, const nacl::string& message);
+                        int32_t pp_error, const std::string& message);
 
 
   // Keeps track of the pp_error upon entry to TranslateFinished,
@@ -169,13 +156,13 @@ class PnaclCoordinator: public CallbackSource<FileStreamData> {
   nacl::scoped_ptr<PnaclResources> resources_;
 
   // The URL for the pexe file.
-  nacl::string pexe_url_;
+  std::string pexe_url_;
   // Options for translation.
   PP_PNaClOptions pnacl_options_;
   // Architecture-specific attributes used for translation. These are
   // supplied by Chrome, not the developer, and are therefore different
   // from PNaCl options.
-  nacl::string architecture_attributes_;
+  std::string architecture_attributes_;
 
   // Object file, produced by the translator and consumed by the linker.
   std::vector<TempFile*> obj_files_;
@@ -185,12 +172,6 @@ class PnaclCoordinator: public CallbackSource<FileStreamData> {
 
   // Translated nexe file, produced by the linker.
   nacl::scoped_ptr<TempFile> temp_nexe_file_;
-  // Passed to the browser, which sets it to true if there is a translation
-  // cache hit.
-  PP_Bool is_cache_hit_;
-
-  // Downloader for streaming translation
-  nacl::scoped_ptr<FileDownloader> streaming_downloader_;
 
   // Used to report information when errors (PPAPI or otherwise) are reported.
   ErrorInfo error_info_;
@@ -200,7 +181,6 @@ class PnaclCoordinator: public CallbackSource<FileStreamData> {
   bool error_already_reported_;
 
   // State for timing and size information for UMA stats.
-  int64_t pnacl_init_time_;
   int64_t pexe_size_;  // Count as we stream -- will converge to pexe size.
   int64_t pexe_bytes_compiled_;  // Count as we compile.
   int64_t expected_pexe_size_;   // Expected download total (-1 if unknown).