Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / component_updater / swiftshader_component_installer.cc
index 5991bdf..e92fd0f 100644 (file)
@@ -4,19 +4,22 @@
 
 #include "chrome/browser/component_updater/swiftshader_component_installer.h"
 
+#include <stdint.h>
+#include <string>
+#include <vector>
+
 #include "base/base_paths.h"
 #include "base/bind.h"
 #include "base/compiler_specific.h"
-#include "base/cpu.h"
-#include "base/file_util.h"
 #include "base/files/file_enumerator.h"
 #include "base/files/file_path.h"
+#include "base/files/file_util.h"
 #include "base/logging.h"
 #include "base/path_service.h"
 #include "base/strings/string_util.h"
 #include "base/values.h"
-#include "chrome/browser/component_updater/component_updater_service.h"
-#include "chrome/common/chrome_paths.h"
+#include "components/component_updater/component_updater_paths.h"
+#include "components/component_updater/component_updater_service.h"
 #include "content/public/browser/browser_thread.h"
 #include "content/public/browser/gpu_data_manager.h"
 #include "content/public/browser/gpu_data_manager_observer.h"
@@ -30,10 +33,10 @@ namespace component_updater {
 namespace {
 
 // CRX hash. The extension id is: nhfgdggnnopgbfdlpeoalgcjdgfafocg.
-const uint8 kSha2Hash[] = {0xd7, 0x56, 0x36, 0x6d, 0xde, 0xf6, 0x15, 0x3b,
-                           0xf4, 0xe0, 0xb6, 0x29, 0x36, 0x50, 0x5e, 0x26,
-                           0xbd, 0x77, 0x8b, 0x8e, 0x35, 0xc2, 0x7e, 0x43,
-                           0x52, 0x47, 0x62, 0xed, 0x12, 0xca, 0xcc, 0x6a};
+const uint8_t kSha2Hash[] = {0xd7, 0x56, 0x36, 0x6d, 0xde, 0xf6, 0x15, 0x3b,
+                             0xf4, 0xe0, 0xb6, 0x29, 0x36, 0x50, 0x5e, 0x26,
+                             0xbd, 0x77, 0x8b, 0x8e, 0x35, 0xc2, 0x7e, 0x43,
+                             0x52, 0x47, 0x62, 0xed, 0x12, 0xca, 0xcc, 0x6a};
 
 // File name of the internal SwiftShader plugin on different platforms.
 const base::FilePath::CharType kSwiftShaderEglName[] =
@@ -43,9 +46,6 @@ const base::FilePath::CharType kSwiftShaderGlesName[] =
 
 const char kSwiftShaderManifestName[] = "SwiftShader";
 
-const base::FilePath::CharType kSwiftShaderBaseDirectory[] =
-    FILE_PATH_LITERAL("SwiftShader");
-
 // If we don't have a SwiftShader component, this is the version we claim.
 const char kNullVersion[] = "0.0.0.0";
 
@@ -53,8 +53,9 @@ const char kNullVersion[] = "0.0.0.0";
 // <profile>\AppData\Local\Google\Chrome\User Data\SwiftShader\.
 base::FilePath GetSwiftShaderBaseDirectory() {
   base::FilePath result;
-  PathService::Get(chrome::DIR_USER_DATA, &result);
-  return result.Append(kSwiftShaderBaseDirectory);
+  if (!PathService::Get(DIR_SWIFT_SHADER, &result))
+    NOTREACHED() << "Couldn't get SwiftShader directory.";
+  return result;
 }
 
 // SwiftShader has version encoded in the path itself
@@ -66,8 +67,8 @@ bool GetLatestSwiftShaderDirectory(base::FilePath* result,
                                    std::vector<base::FilePath>* older_dirs) {
   base::FilePath base_dir = GetSwiftShaderBaseDirectory();
   bool found = false;
-  base::FileEnumerator
-      file_enumerator(base_dir, false, base::FileEnumerator::DIRECTORIES);
+  base::FileEnumerator file_enumerator(
+      base_dir, false, base::FileEnumerator::DIRECTORIES);
   for (base::FilePath path = file_enumerator.Next(); !path.value().empty();
        path = file_enumerator.Next()) {
     Version version(path.BaseName().MaybeAsASCII());
@@ -77,7 +78,7 @@ bool GetLatestSwiftShaderDirectory(base::FilePath* result,
         base::PathExists(path.Append(kSwiftShaderEglName)) &&
         base::PathExists(path.Append(kSwiftShaderGlesName))) {
       if (found && older_dirs)
-          older_dirs->push_back(*result);
+        older_dirs->push_back(*result);
       *latest = version;
       *result = path;
       found = true;
@@ -98,22 +99,23 @@ class SwiftShaderComponentInstaller : public ComponentInstaller {
  public:
   explicit SwiftShaderComponentInstaller(const Version& version);
 
-  virtual ~SwiftShaderComponentInstaller() {}
+  ~SwiftShaderComponentInstaller() override {}
 
-  virtual void OnUpdateError(int error) OVERRIDE;
+  void OnUpdateError(int error) override;
 
-  virtual bool Install(const base::DictionaryValue& manifest,
-                       const base::FilePath& unpack_path) OVERRIDE;
+  bool Install(const base::DictionaryValue& manifest,
+               const base::FilePath& unpack_path) override;
 
-  virtual bool GetInstalledFile(const std::string& file,
-                                base::FilePath* installed_file) OVERRIDE;
+  bool GetInstalledFile(const std::string& file,
+                        base::FilePath* installed_file) override;
 
  private:
   Version current_version_;
 };
 
 SwiftShaderComponentInstaller::SwiftShaderComponentInstaller(
-    const Version& version) : current_version_(version) {
+    const Version& version)
+    : current_version_(version) {
   DCHECK(version.IsValid());
 }
 
@@ -147,13 +149,15 @@ bool SwiftShaderComponentInstaller::Install(
     return false;
   // Installation is done. Now tell the rest of chrome.
   current_version_ = version;
-  BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
-      base::Bind(&RegisterSwiftShaderWithChrome, path));
+  BrowserThread::PostTask(BrowserThread::UI,
+                          FROM_HERE,
+                          base::Bind(&RegisterSwiftShaderWithChrome, path));
   return true;
 }
 
 bool SwiftShaderComponentInstaller::GetInstalledFile(
-    const std::string& file, base::FilePath* installed_file) {
+    const std::string& file,
+    base::FilePath* installed_file) {
   return false;
 }
 
@@ -175,18 +179,17 @@ class UpdateChecker : public content::GpuDataManagerObserver {
  public:
   explicit UpdateChecker(ComponentUpdateService* cus);
 
-  virtual void OnGpuInfoUpdate() OVERRIDE;
+  void OnGpuInfoUpdate() override;
 
  private:
   ComponentUpdateService* cus_;
 };
 
-UpdateChecker::UpdateChecker(ComponentUpdateService* cus)
-  : cus_(cus) {
+UpdateChecker::UpdateChecker(ComponentUpdateService* cus) : cus_(cus) {
 }
 
 void UpdateChecker::OnGpuInfoUpdate() {
-  GpuDataManager *gpu_data_manager = GpuDataManager::GetInstance();
+  GpuDataManagergpu_data_manager = GpuDataManager::GetInstance();
 
   if (!gpu_data_manager->GpuAccessAllowed(NULL) ||
       gpu_data_manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL) ||
@@ -198,7 +201,9 @@ void UpdateChecker::OnGpuInfoUpdate() {
     Version version(kNullVersion);
     GetLatestSwiftShaderDirectory(&path, &version, NULL);
 
-    BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+    BrowserThread::PostTask(
+        BrowserThread::UI,
+        FROM_HERE,
         base::Bind(&FinishSwiftShaderUpdateRegistration, cus_, version));
   }
 }
@@ -220,10 +225,11 @@ void RegisterSwiftShaderPath(ComponentUpdateService* cus) {
   Version version(kNullVersion);
   std::vector<base::FilePath> older_dirs;
   if (GetLatestSwiftShaderDirectory(&path, &version, &older_dirs))
-    BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
-        base::Bind(&RegisterSwiftShaderWithChrome, path));
+    BrowserThread::PostTask(BrowserThread::UI,
+                            FROM_HERE,
+                            base::Bind(&RegisterSwiftShaderWithChrome, path));
 
-  UpdateChecker *update_checker = new UpdateChecker(cus);
+  UpdateCheckerupdate_checker = new UpdateChecker(cus);
   GpuDataManager::GetInstance()->AddObserver(update_checker);
   update_checker->OnGpuInfoUpdate();
   // We leak update_checker here, because it has to stick around for the life
@@ -231,7 +237,8 @@ void RegisterSwiftShaderPath(ComponentUpdateService* cus) {
 
   // Remove older versions of SwiftShader.
   for (std::vector<base::FilePath>::iterator iter = older_dirs.begin();
-       iter != older_dirs.end(); ++iter) {
+       iter != older_dirs.end();
+       ++iter) {
     base::DeleteFile(*iter, true);
   }
 }
@@ -242,14 +249,10 @@ void RegisterSwiftShaderPath(ComponentUpdateService* cus) {
 
 void RegisterSwiftShaderComponent(ComponentUpdateService* cus) {
 #if defined(ENABLE_SWIFTSHADER)
-  base::CPU cpu;
-
-  if (!cpu.has_sse2())
-    return;
-  BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
-      base::Bind(&RegisterSwiftShaderPath, cus));
+  BrowserThread::PostTask(BrowserThread::FILE,
+                          FROM_HERE,
+                          base::Bind(&RegisterSwiftShaderPath, cus));
 #endif
 }
 
 }  // namespace component_updater
-