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

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

Issue 1281313003: base: Remove using:: declaration from version.h header. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ninja -C out/Debug all Created 5 years, 4 months 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 <stdint.h> 5 #include <stdint.h>
6 #include <string.h> 6 #include <string.h>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/base_paths.h" 9 #include "base/base_paths.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 } 64 }
65 65
66 #if defined(GOOGLE_CHROME_BUILD) && !defined(OS_LINUX) 66 #if defined(GOOGLE_CHROME_BUILD) && !defined(OS_LINUX)
67 // Pepper Flash plugins have the version encoded in the path itself 67 // Pepper Flash plugins have the version encoded in the path itself
68 // so we need to enumerate the directories to find the full path. 68 // so we need to enumerate the directories to find the full path.
69 // On success, |latest_dir| returns something like: 69 // On success, |latest_dir| returns something like:
70 // <profile>\AppData\Local\Google\Chrome\User Data\PepperFlash\10.3.44.555\. 70 // <profile>\AppData\Local\Google\Chrome\User Data\PepperFlash\10.3.44.555\.
71 // |latest_version| returns the corresponding version number. |older_dirs| 71 // |latest_version| returns the corresponding version number. |older_dirs|
72 // returns directories of all older versions. 72 // returns directories of all older versions.
73 bool GetPepperFlashDirectory(base::FilePath* latest_dir, 73 bool GetPepperFlashDirectory(base::FilePath* latest_dir,
74 Version* latest_version, 74 base::Version* latest_version,
75 std::vector<base::FilePath>* older_dirs) { 75 std::vector<base::FilePath>* older_dirs) {
76 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 76 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
77 base::FilePath base_dir = GetPepperFlashBaseDirectory(); 77 base::FilePath base_dir = GetPepperFlashBaseDirectory();
78 bool found = false; 78 bool found = false;
79 base::FileEnumerator file_enumerator( 79 base::FileEnumerator file_enumerator(
80 base_dir, false, base::FileEnumerator::DIRECTORIES); 80 base_dir, false, base::FileEnumerator::DIRECTORIES);
81 for (base::FilePath path = file_enumerator.Next(); !path.value().empty(); 81 for (base::FilePath path = file_enumerator.Next(); !path.value().empty();
82 path = file_enumerator.Next()) { 82 path = file_enumerator.Next()) {
83 Version version(path.BaseName().MaybeAsASCII()); 83 base::Version version(path.BaseName().MaybeAsASCII());
84 if (!version.IsValid()) 84 if (!version.IsValid())
85 continue; 85 continue;
86 if (found) { 86 if (found) {
87 if (version.CompareTo(*latest_version) > 0) { 87 if (version.CompareTo(*latest_version) > 0) {
88 older_dirs->push_back(*latest_dir); 88 older_dirs->push_back(*latest_dir);
89 *latest_dir = path; 89 *latest_dir = path;
90 *latest_version = version; 90 *latest_version = version;
91 } else { 91 } else {
92 older_dirs->push_back(path); 92 older_dirs->push_back(path);
93 } 93 }
94 } else { 94 } else {
95 *latest_dir = path; 95 *latest_dir = path;
96 *latest_version = version; 96 *latest_version = version;
97 found = true; 97 found = true;
98 } 98 }
99 } 99 }
100 return found; 100 return found;
101 } 101 }
102 #endif // defined(GOOGLE_CHROME_BUILD) && !defined(OS_LINUX) 102 #endif // defined(GOOGLE_CHROME_BUILD) && !defined(OS_LINUX)
103 103
104 bool MakePepperFlashPluginInfo(const base::FilePath& flash_path, 104 bool MakePepperFlashPluginInfo(const base::FilePath& flash_path,
105 const Version& flash_version, 105 const base::Version& flash_version,
106 bool out_of_process, 106 bool out_of_process,
107 content::PepperPluginInfo* plugin_info) { 107 content::PepperPluginInfo* plugin_info) {
108 if (!flash_version.IsValid()) 108 if (!flash_version.IsValid())
109 return false; 109 return false;
110 const std::vector<uint32_t> ver_nums = flash_version.components(); 110 const std::vector<uint32_t> ver_nums = flash_version.components();
111 if (ver_nums.size() < 3) 111 if (ver_nums.size() < 3)
112 return false; 112 return false;
113 113
114 plugin_info->is_internal = false; 114 plugin_info->is_internal = false;
115 plugin_info->is_out_of_process = out_of_process; 115 plugin_info->is_out_of_process = out_of_process;
(...skipping 23 matching lines...) Expand all
139 139
140 bool IsPepperFlash(const content::WebPluginInfo& plugin) { 140 bool IsPepperFlash(const content::WebPluginInfo& plugin) {
141 // We try to recognize Pepper Flash by the following criteria: 141 // We try to recognize Pepper Flash by the following criteria:
142 // * It is a Pepper plugin. 142 // * It is a Pepper plugin.
143 // * It has the special Flash permissions. 143 // * It has the special Flash permissions.
144 return plugin.is_pepper_plugin() && 144 return plugin.is_pepper_plugin() &&
145 (plugin.pepper_permissions & ppapi::PERMISSION_FLASH); 145 (plugin.pepper_permissions & ppapi::PERMISSION_FLASH);
146 } 146 }
147 147
148 void RegisterPepperFlashWithChrome(const base::FilePath& path, 148 void RegisterPepperFlashWithChrome(const base::FilePath& path,
149 const Version& version) { 149 const base::Version& version) {
150 DCHECK_CURRENTLY_ON(BrowserThread::UI); 150 DCHECK_CURRENTLY_ON(BrowserThread::UI);
151 content::PepperPluginInfo plugin_info; 151 content::PepperPluginInfo plugin_info;
152 if (!MakePepperFlashPluginInfo(path, version, true, &plugin_info)) 152 if (!MakePepperFlashPluginInfo(path, version, true, &plugin_info))
153 return; 153 return;
154 154
155 std::vector<content::WebPluginInfo> plugins; 155 std::vector<content::WebPluginInfo> plugins;
156 PluginService::GetInstance()->GetInternalPlugins(&plugins); 156 PluginService::GetInstance()->GetInternalPlugins(&plugins);
157 for (std::vector<content::WebPluginInfo>::const_iterator it = 157 for (std::vector<content::WebPluginInfo>::const_iterator it =
158 plugins.begin(); 158 plugins.begin();
159 it != plugins.end(); 159 it != plugins.end();
160 ++it) { 160 ++it) {
161 if (!IsPepperFlash(*it)) 161 if (!IsPepperFlash(*it))
162 continue; 162 continue;
163 163
164 // Do it only if the version we're trying to register is newer. 164 // Do it only if the version we're trying to register is newer.
165 Version registered_version(base::UTF16ToUTF8(it->version)); 165 base::Version registered_version(base::UTF16ToUTF8(it->version));
166 if (registered_version.IsValid() && 166 if (registered_version.IsValid() &&
167 version.CompareTo(registered_version) <= 0) { 167 version.CompareTo(registered_version) <= 0) {
168 return; 168 return;
169 } 169 }
170 170
171 // If the version is newer, remove the old one first. 171 // If the version is newer, remove the old one first.
172 PluginService::GetInstance()->UnregisterInternalPlugin(it->path); 172 PluginService::GetInstance()->UnregisterInternalPlugin(it->path);
173 break; 173 break;
174 } 174 }
175 175
176 PluginService::GetInstance()->RegisterInternalPlugin( 176 PluginService::GetInstance()->RegisterInternalPlugin(
177 plugin_info.ToWebPluginInfo(), true); 177 plugin_info.ToWebPluginInfo(), true);
178 PluginService::GetInstance()->RefreshPlugins(); 178 PluginService::GetInstance()->RefreshPlugins();
179 } 179 }
180 180
181 } // namespace 181 } // namespace
182 182
183 class PepperFlashComponentInstaller : public update_client::CrxInstaller { 183 class PepperFlashComponentInstaller : public update_client::CrxInstaller {
184 public: 184 public:
185 explicit PepperFlashComponentInstaller(const Version& version); 185 explicit PepperFlashComponentInstaller(const base::Version& version);
186 186
187 // ComponentInstaller implementation: 187 // ComponentInstaller implementation:
188 void OnUpdateError(int error) override; 188 void OnUpdateError(int error) override;
189 189
190 bool Install(const base::DictionaryValue& manifest, 190 bool Install(const base::DictionaryValue& manifest,
191 const base::FilePath& unpack_path) override; 191 const base::FilePath& unpack_path) override;
192 192
193 bool GetInstalledFile(const std::string& file, 193 bool GetInstalledFile(const std::string& file,
194 base::FilePath* installed_file) override; 194 base::FilePath* installed_file) override;
195 195
196 bool Uninstall() override; 196 bool Uninstall() override;
197 197
198 private: 198 private:
199 ~PepperFlashComponentInstaller() override {} 199 ~PepperFlashComponentInstaller() override {}
200 200
201 Version current_version_; 201 base::Version current_version_;
202 }; 202 };
203 203
204 PepperFlashComponentInstaller::PepperFlashComponentInstaller( 204 PepperFlashComponentInstaller::PepperFlashComponentInstaller(
205 const Version& version) 205 const base::Version& version)
206 : current_version_(version) { 206 : current_version_(version) {
207 DCHECK(version.IsValid()); 207 DCHECK(version.IsValid());
208 } 208 }
209 209
210 void PepperFlashComponentInstaller::OnUpdateError(int error) { 210 void PepperFlashComponentInstaller::OnUpdateError(int error) {
211 NOTREACHED() << "Pepper Flash update error: " << error; 211 NOTREACHED() << "Pepper Flash update error: " << error;
212 } 212 }
213 213
214 bool PepperFlashComponentInstaller::Install( 214 bool PepperFlashComponentInstaller::Install(
215 const base::DictionaryValue& manifest, 215 const base::DictionaryValue& manifest,
216 const base::FilePath& unpack_path) { 216 const base::FilePath& unpack_path) {
217 Version version; 217 base::Version version;
218 if (!chrome::CheckPepperFlashManifest(manifest, &version)) 218 if (!chrome::CheckPepperFlashManifest(manifest, &version))
219 return false; 219 return false;
220 if (current_version_.CompareTo(version) > 0) 220 if (current_version_.CompareTo(version) > 0)
221 return false; 221 return false;
222 if (!base::PathExists(unpack_path.Append(chrome::kPepperFlashPluginFilename))) 222 if (!base::PathExists(unpack_path.Append(chrome::kPepperFlashPluginFilename)))
223 return false; 223 return false;
224 // Passed the basic tests. Time to install it. 224 // Passed the basic tests. Time to install it.
225 base::FilePath path = 225 base::FilePath path =
226 GetPepperFlashBaseDirectory().AppendASCII(version.GetString()); 226 GetPepperFlashBaseDirectory().AppendASCII(version.GetString());
227 if (base::PathExists(path)) 227 if (base::PathExists(path))
(...skipping 21 matching lines...) Expand all
249 bool PepperFlashComponentInstaller::Uninstall() { 249 bool PepperFlashComponentInstaller::Uninstall() {
250 return false; 250 return false;
251 } 251 }
252 252
253 253
254 254
255 namespace { 255 namespace {
256 256
257 #if defined(GOOGLE_CHROME_BUILD) && !defined(OS_LINUX) 257 #if defined(GOOGLE_CHROME_BUILD) && !defined(OS_LINUX)
258 void FinishPepperFlashUpdateRegistration(ComponentUpdateService* cus, 258 void FinishPepperFlashUpdateRegistration(ComponentUpdateService* cus,
259 const Version& version) { 259 const base::Version& version) {
260 DCHECK_CURRENTLY_ON(BrowserThread::UI); 260 DCHECK_CURRENTLY_ON(BrowserThread::UI);
261 update_client::CrxComponent pepflash; 261 update_client::CrxComponent pepflash;
262 pepflash.name = "pepper_flash"; 262 pepflash.name = "pepper_flash";
263 pepflash.installer = new PepperFlashComponentInstaller(version); 263 pepflash.installer = new PepperFlashComponentInstaller(version);
264 pepflash.version = version; 264 pepflash.version = version;
265 pepflash.pk_hash.assign(kSha2Hash, &kSha2Hash[sizeof(kSha2Hash)]); 265 pepflash.pk_hash.assign(kSha2Hash, &kSha2Hash[sizeof(kSha2Hash)]);
266 if (!cus->RegisterComponent(pepflash)) 266 if (!cus->RegisterComponent(pepflash))
267 NOTREACHED() << "Pepper Flash component registration failed."; 267 NOTREACHED() << "Pepper Flash component registration failed.";
268 } 268 }
269 269
270 void StartPepperFlashUpdateRegistration(ComponentUpdateService* cus) { 270 void StartPepperFlashUpdateRegistration(ComponentUpdateService* cus) {
271 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 271 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
272 base::FilePath path = GetPepperFlashBaseDirectory(); 272 base::FilePath path = GetPepperFlashBaseDirectory();
273 if (!base::PathExists(path)) { 273 if (!base::PathExists(path)) {
274 if (!base::CreateDirectory(path)) { 274 if (!base::CreateDirectory(path)) {
275 NOTREACHED() << "Could not create Pepper Flash directory."; 275 NOTREACHED() << "Could not create Pepper Flash directory.";
276 return; 276 return;
277 } 277 }
278 } 278 }
279 279
280 Version version(kNullVersion); 280 base::Version version(kNullVersion);
281 std::vector<base::FilePath> older_dirs; 281 std::vector<base::FilePath> older_dirs;
282 if (GetPepperFlashDirectory(&path, &version, &older_dirs)) { 282 if (GetPepperFlashDirectory(&path, &version, &older_dirs)) {
283 path = path.Append(chrome::kPepperFlashPluginFilename); 283 path = path.Append(chrome::kPepperFlashPluginFilename);
284 if (base::PathExists(path)) { 284 if (base::PathExists(path)) {
285 BrowserThread::PostTask( 285 BrowserThread::PostTask(
286 BrowserThread::UI, 286 BrowserThread::UI,
287 FROM_HERE, 287 FROM_HERE,
288 base::Bind(&RegisterPepperFlashWithChrome, path, version)); 288 base::Bind(&RegisterPepperFlashWithChrome, path, version));
289 } else { 289 } else {
290 version = Version(kNullVersion); 290 version = base::Version(kNullVersion);
291 } 291 }
292 } 292 }
293 293
294 #if defined(FLAPPER_AVAILABLE) 294 #if defined(FLAPPER_AVAILABLE)
295 // If a version of Flash is bundled with Chrome, and it's a higher version 295 // If a version of Flash is bundled with Chrome, and it's a higher version
296 // than the version of the component, or the component has never been updated, 296 // than the version of the component, or the component has never been updated,
297 // then set the bundled version as the current version. 297 // then set the bundled version as the current version.
298 if (version.CompareTo(Version(FLAPPER_VERSION_STRING)) < 0) 298 if (version.CompareTo(Version(FLAPPER_VERSION_STRING)) < 0)
299 version = Version(FLAPPER_VERSION_STRING); 299 version = base::Version(FLAPPER_VERSION_STRING);
300 #endif 300 #endif
301 301
302 BrowserThread::PostTask( 302 BrowserThread::PostTask(
303 BrowserThread::UI, 303 BrowserThread::UI,
304 FROM_HERE, 304 FROM_HERE,
305 base::Bind(&FinishPepperFlashUpdateRegistration, cus, version)); 305 base::Bind(&FinishPepperFlashUpdateRegistration, cus, version));
306 306
307 // Remove older versions of Pepper Flash. 307 // Remove older versions of Pepper Flash.
308 for (std::vector<base::FilePath>::iterator iter = older_dirs.begin(); 308 for (std::vector<base::FilePath>::iterator iter = older_dirs.begin();
309 iter != older_dirs.end(); 309 iter != older_dirs.end();
(...skipping 12 matching lines...) Expand all
322 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); 322 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
323 if (cmd_line->HasSwitch(switches::kDisableBundledPpapiFlash)) 323 if (cmd_line->HasSwitch(switches::kDisableBundledPpapiFlash))
324 return; 324 return;
325 BrowserThread::PostTask(BrowserThread::FILE, 325 BrowserThread::PostTask(BrowserThread::FILE,
326 FROM_HERE, 326 FROM_HERE,
327 base::Bind(&StartPepperFlashUpdateRegistration, cus)); 327 base::Bind(&StartPepperFlashUpdateRegistration, cus));
328 #endif 328 #endif
329 } 329 }
330 330
331 } // namespace component_updater 331 } // namespace component_updater
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698