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

Side by Side Diff: chrome/browser/component_updater/pnacl/pnacl_component_installer.cc

Issue 338403002: Remove pnacl_profile_observer from pnacl's use of component updater. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
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/pnacl/pnacl_component_installer.h" 5 #include "chrome/browser/component_updater/pnacl/pnacl_component_installer.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/atomicops.h" 10 #include "base/atomicops.h"
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/callback.h" 13 #include "base/callback.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/compiler_specific.h" 15 #include "base/compiler_specific.h"
16 #include "base/file_util.h" 16 #include "base/file_util.h"
17 #include "base/files/file_enumerator.h" 17 #include "base/files/file_enumerator.h"
18 #include "base/files/file_path.h" 18 #include "base/files/file_path.h"
19 #include "base/json/json_file_value_serializer.h" 19 #include "base/json/json_file_value_serializer.h"
20 #include "base/logging.h" 20 #include "base/logging.h"
21 #include "base/path_service.h" 21 #include "base/path_service.h"
22 #include "base/strings/string_util.h" 22 #include "base/strings/string_util.h"
23 #include "base/values.h" 23 #include "base/values.h"
24 #include "base/version.h" 24 #include "base/version.h"
25 #include "base/win/windows_version.h" 25 #include "base/win/windows_version.h"
26 #include "build/build_config.h" 26 #include "build/build_config.h"
27 #include "chrome/browser/browser_process.h" 27 #include "chrome/browser/browser_process.h"
28 #include "chrome/browser/component_updater/component_updater_service.h" 28 #include "chrome/browser/component_updater/component_updater_service.h"
29 #include "chrome/browser/omaha_query_params/omaha_query_params.h" 29 #include "chrome/browser/omaha_query_params/omaha_query_params.h"
30 #include "chrome/browser/profiles/profile.h"
31 #include "chrome/browser/profiles/profile_manager.h"
32 #include "chrome/common/chrome_paths.h" 30 #include "chrome/common/chrome_paths.h"
33 #include "components/nacl/common/nacl_switches.h" 31 #include "components/nacl/common/nacl_switches.h"
34 #include "content/public/browser/browser_thread.h" 32 #include "content/public/browser/browser_thread.h"
35 33
36 using chrome::OmahaQueryParams; 34 using chrome::OmahaQueryParams;
37 using content::BrowserThread; 35 using content::BrowserThread;
38 36
39 namespace component_updater { 37 namespace component_updater {
40 38
41 namespace { 39 namespace {
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 return false; 197 return false;
200 } 198 }
201 199
202 *version_out = version; 200 *version_out = version;
203 return true; 201 return true;
204 } 202 }
205 203
206 } // namespace 204 } // namespace
207 205
208 PnaclComponentInstaller::PnaclComponentInstaller() 206 PnaclComponentInstaller::PnaclComponentInstaller()
209 : per_user_(false), updates_disabled_(false), cus_(NULL) { 207 : updates_disabled_(false), cus_(NULL) {
210 #if defined(OS_CHROMEOS)
211 per_user_ = true;
212 #endif
213 } 208 }
214 209
215 PnaclComponentInstaller::~PnaclComponentInstaller() { 210 PnaclComponentInstaller::~PnaclComponentInstaller() {
216 } 211 }
217 212
218 void PnaclComponentInstaller::OnUpdateError(int error) { 213 void PnaclComponentInstaller::OnUpdateError(int error) {
219 NOTREACHED() << "Pnacl update error: " << error; 214 NOTREACHED() << "Pnacl update error: " << error;
220 } 215 }
221 216
222 // Pnacl components have the version encoded in the path itself: 217 // Pnacl components have the version encoded in the path itself:
223 // <profile>\AppData\Local\Google\Chrome\User Data\pnacl\0.1.2.3\. 218 // <profile>\AppData\Local\Google\Chrome\User Data\pnacl\0.1.2.3\.
224 // and the base directory will be: 219 // and the base directory will be:
225 // <profile>\AppData\Local\Google\Chrome\User Data\pnacl\. 220 // <profile>\AppData\Local\Google\Chrome\User Data\pnacl\.
226 base::FilePath PnaclComponentInstaller::GetPnaclBaseDirectory() { 221 base::FilePath PnaclComponentInstaller::GetPnaclBaseDirectory() {
227 // For ChromeOS, temporarily make this user-dependent (for integrity) until 222 base::FilePath result;
228 // we find a better solution. 223 CHECK(PathService::Get(chrome::DIR_PNACL_BASE, &result));
229 // This is not ideal because of the following: 224 return result;
230 // (a) We end up with per-user copies instead of a single copy
231 // (b) The profile can change as users log in to different accounts
232 // so we need to watch for user-login-events (see pnacl_profile_observer.h).
233 if (per_user_) {
234 DCHECK(!current_profile_path_.empty());
235 base::FilePath path =
236 current_profile_path_.Append(FILE_PATH_LITERAL("pnacl"));
237 return path;
238 } else {
239 base::FilePath result;
240 CHECK(PathService::Get(chrome::DIR_PNACL_BASE, &result));
241 return result;
242 }
243 }
244
245 void PnaclComponentInstaller::OnProfileChange() {
246 // On chromeos, we want to find the --login-profile=<foo> dir.
247 // Even though the path does vary between users, the content
248 // changes when logging out and logging in.
249 ProfileManager* pm = g_browser_process->profile_manager();
250 current_profile_path_ =
251 pm->user_data_dir().Append(pm->GetInitialProfileDir());
252 } 225 }
253 226
254 bool PnaclComponentInstaller::Install(const base::DictionaryValue& manifest, 227 bool PnaclComponentInstaller::Install(const base::DictionaryValue& manifest,
255 const base::FilePath& unpack_path) { 228 const base::FilePath& unpack_path) {
256 scoped_ptr<base::DictionaryValue> pnacl_manifest( 229 scoped_ptr<base::DictionaryValue> pnacl_manifest(
257 ReadPnaclManifest(unpack_path)); 230 ReadPnaclManifest(unpack_path));
258 if (pnacl_manifest == NULL) { 231 if (pnacl_manifest == NULL) {
259 LOG(WARNING) << "Failed to read pnacl manifest."; 232 LOG(WARNING) << "Failed to read pnacl manifest.";
260 return false; 233 return false;
261 } 234 }
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 pci)); 360 pci));
388 361
389 // Remove older versions of PNaCl. 362 // Remove older versions of PNaCl.
390 for (std::vector<base::FilePath>::iterator iter = older_dirs.begin(); 363 for (std::vector<base::FilePath>::iterator iter = older_dirs.begin();
391 iter != older_dirs.end(); 364 iter != older_dirs.end();
392 ++iter) { 365 ++iter) {
393 base::DeleteFile(*iter, true); 366 base::DeleteFile(*iter, true);
394 } 367 }
395 } 368 }
396 369
397 // Remove old per-profile copies of PNaCl (was for ChromeOS).
398 // TODO(jvoung): Delete this code once most ChromeOS users have reaped
399 // their old per-profile copies of PNaCl.
400 void ReapOldChromeOSPnaclFiles(PnaclComponentInstaller* pci) {
401 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
402 base::FilePath path = pci->GetPnaclBaseDirectory();
403 if (!base::PathExists(path))
404 return;
405
406 // Do a basic sanity check first.
407 if (pci->per_user() &&
408 path.BaseName().value().compare(FILE_PATH_LITERAL("pnacl")) == 0)
409 base::DeleteFile(path, true);
410 }
411
412 void GetProfileInformation(PnaclComponentInstaller* pci) {
413 // Bail if not logged in yet.
414 if (!g_browser_process->profile_manager()->IsLoggedIn()) {
415 return;
416 }
417
418 pci->OnProfileChange();
419
420 // Do not actually register PNaCl for component updates, for CHROMEOS.
421 // Just get the profile information and delete the per-profile files
422 // if they exist.
423 BrowserThread::PostTask(BrowserThread::FILE,
424 FROM_HERE,
425 base::Bind(&ReapOldChromeOSPnaclFiles, pci));
426 }
427
428 } // namespace 370 } // namespace
429 371
430 void PnaclComponentInstaller::RegisterPnaclComponent( 372 void PnaclComponentInstaller::RegisterPnaclComponent(
431 ComponentUpdateService* cus, 373 ComponentUpdateService* cus,
432 const CommandLine& command_line) { 374 const CommandLine& command_line) {
433 // Register PNaCl by default (can be disabled). 375 // Register PNaCl by default (can be disabled).
434 updates_disabled_ = command_line.HasSwitch(switches::kDisablePnaclInstall); 376 updates_disabled_ = command_line.HasSwitch(switches::kDisablePnaclInstall);
435 cus_ = cus; 377 cus_ = cus;
436 // If per_user, create a profile observer to watch for logins. 378 BrowserThread::PostTask(BrowserThread::FILE,
437 // Only do so after cus_ is set to something non-null. 379 FROM_HERE,
438 if (per_user_ && !profile_observer_) { 380 base::Bind(&StartPnaclUpdateRegistration, this));
439 profile_observer_.reset(new PnaclProfileObserver(this));
440 }
441 if (per_user_) {
442 // Figure out profile information, before proceeding to look for files.
443 BrowserThread::PostTask(
444 BrowserThread::UI, FROM_HERE, base::Bind(&GetProfileInformation, this));
445 } else {
446 BrowserThread::PostTask(BrowserThread::FILE,
447 FROM_HERE,
448 base::Bind(&StartPnaclUpdateRegistration, this));
449 }
450 }
451
452 void PnaclComponentInstaller::ReRegisterPnacl() {
453 DCHECK(per_user_);
454 // Figure out profile information, before proceeding to look for files.
455 BrowserThread::PostTask(
456 BrowserThread::UI, FROM_HERE, base::Bind(&GetProfileInformation, this));
457 } 381 }
458 382
459 } // namespace component_updater 383 } // namespace component_updater
460 384
461 namespace pnacl { 385 namespace pnacl {
462 386
463 bool NeedsOnDemandUpdate() { 387 bool NeedsOnDemandUpdate() {
464 return base::subtle::NoBarrier_Load( 388 return base::subtle::NoBarrier_Load(
465 &component_updater::needs_on_demand_update) != 0; 389 &component_updater::needs_on_demand_update) != 0;
466 } 390 }
467 391
468 } // namespace pnacl 392 } // namespace pnacl
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698