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

Side by Side Diff: chrome/browser/component_updater/swiftshader_component_installer.cc

Issue 2479633003: Makes the component installers return a Result instead of a bool. (Closed)
Patch Set: rebase Created 4 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
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 #include "chrome/browser/component_updater/swiftshader_component_installer.h" 5 #include "chrome/browser/component_updater/swiftshader_component_installer.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/base_paths.h" 11 #include "base/base_paths.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h"
13 #include "base/files/file_enumerator.h" 14 #include "base/files/file_enumerator.h"
14 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
15 #include "base/files/file_util.h" 16 #include "base/files/file_util.h"
16 #include "base/logging.h" 17 #include "base/logging.h"
17 #include "base/path_service.h" 18 #include "base/path_service.h"
18 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
19 #include "base/values.h" 20 #include "base/values.h"
20 #include "build/build_config.h" 21 #include "build/build_config.h"
21 #include "components/component_updater/component_updater_paths.h" 22 #include "components/component_updater/component_updater_paths.h"
22 #include "components/component_updater/component_updater_service.h" 23 #include "components/component_updater/component_updater_service.h"
23 #include "components/update_client/update_client.h" 24 #include "components/update_client/update_client.h"
25 #include "components/update_client/utils.h"
24 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
25 #include "content/public/browser/gpu_data_manager.h" 27 #include "content/public/browser/gpu_data_manager.h"
26 #include "content/public/browser/gpu_data_manager_observer.h" 28 #include "content/public/browser/gpu_data_manager_observer.h"
27 #include "gpu/config/gpu_feature_type.h" 29 #include "gpu/config/gpu_feature_type.h"
28 #include "ui/gl/gl_features.h" 30 #include "ui/gl/gl_features.h"
29 31
30 using content::BrowserThread; 32 using content::BrowserThread;
31 using content::GpuDataManager; 33 using content::GpuDataManager;
32 34
33 namespace component_updater { 35 namespace component_updater {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 GpuDataManager::GetInstance()->RegisterSwiftShaderPath(path); 99 GpuDataManager::GetInstance()->RegisterSwiftShaderPath(path);
98 } 100 }
99 101
100 class SwiftShaderComponentInstaller : public update_client::CrxInstaller { 102 class SwiftShaderComponentInstaller : public update_client::CrxInstaller {
101 public: 103 public:
102 explicit SwiftShaderComponentInstaller(const base::Version& version); 104 explicit SwiftShaderComponentInstaller(const base::Version& version);
103 105
104 // ComponentInstaller implementation: 106 // ComponentInstaller implementation:
105 void OnUpdateError(int error) override; 107 void OnUpdateError(int error) override;
106 108
107 bool Install(const base::DictionaryValue& manifest, 109 update_client::CrxInstaller::Result Install(
108 const base::FilePath& unpack_path) override; 110 const base::DictionaryValue& manifest,
111 const base::FilePath& unpack_path) override;
109 112
110 bool GetInstalledFile(const std::string& file, 113 bool GetInstalledFile(const std::string& file,
111 base::FilePath* installed_file) override; 114 base::FilePath* installed_file) override;
112 115
113 bool Uninstall() override; 116 bool Uninstall() override;
114 117
115 private: 118 private:
116 ~SwiftShaderComponentInstaller() override {} 119 ~SwiftShaderComponentInstaller() override {}
117 120
121 bool DoInstall(const base::DictionaryValue& manifest,
122 const base::FilePath& unpack_path);
123
118 base::Version current_version_; 124 base::Version current_version_;
119 }; 125 };
120 126
121 SwiftShaderComponentInstaller::SwiftShaderComponentInstaller( 127 SwiftShaderComponentInstaller::SwiftShaderComponentInstaller(
122 const base::Version& version) 128 const base::Version& version)
123 : current_version_(version) { 129 : current_version_(version) {
124 DCHECK(version.IsValid()); 130 DCHECK(version.IsValid());
125 } 131 }
126 132
127 void SwiftShaderComponentInstaller::OnUpdateError(int error) { 133 void SwiftShaderComponentInstaller::OnUpdateError(int error) {
128 NOTREACHED() << "SwiftShader update error: " << error; 134 NOTREACHED() << "SwiftShader update error: " << error;
129 } 135 }
130 136
131 bool SwiftShaderComponentInstaller::Install( 137 update_client::CrxInstaller::Result SwiftShaderComponentInstaller::Install(
138 const base::DictionaryValue& manifest,
139 const base::FilePath& unpack_path) {
140 return update_client::InstallFunctionWrapper(base::Bind(
141 &SwiftShaderComponentInstaller::DoInstall, base::Unretained(this),
142 base::ConstRef(manifest), base::ConstRef(unpack_path)));
143 }
144
145 bool SwiftShaderComponentInstaller::DoInstall(
132 const base::DictionaryValue& manifest, 146 const base::DictionaryValue& manifest,
133 const base::FilePath& unpack_path) { 147 const base::FilePath& unpack_path) {
134 std::string name; 148 std::string name;
135 manifest.GetStringASCII("name", &name); 149 manifest.GetStringASCII("name", &name);
136 if (name != kSwiftShaderManifestName) 150 if (name != kSwiftShaderManifestName)
137 return false; 151 return false;
138 std::string proposed_version; 152 std::string proposed_version;
139 manifest.GetStringASCII("version", &proposed_version); 153 manifest.GetStringASCII("version", &proposed_version);
140 base::Version version(proposed_version.c_str()); 154 base::Version version(proposed_version.c_str());
141 if (!version.IsValid()) 155 if (!version.IsValid())
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 274
261 void RegisterSwiftShaderComponent(ComponentUpdateService* cus) { 275 void RegisterSwiftShaderComponent(ComponentUpdateService* cus) {
262 #if BUILDFLAG(ENABLE_SWIFTSHADER) && defined(ARCH_CPU_X86) 276 #if BUILDFLAG(ENABLE_SWIFTSHADER) && defined(ARCH_CPU_X86)
263 BrowserThread::PostTask(BrowserThread::FILE, 277 BrowserThread::PostTask(BrowserThread::FILE,
264 FROM_HERE, 278 FROM_HERE,
265 base::Bind(&RegisterSwiftShaderPath, cus)); 279 base::Bind(&RegisterSwiftShaderPath, cus));
266 #endif 280 #endif
267 } 281 }
268 282
269 } // namespace component_updater 283 } // namespace component_updater
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698