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

Unified Diff: chrome/browser/component_updater/pnacl/pnacl_component_installer.cc

Issue 13071002: Turn on component updater on chromeos, only for the pnacl component. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: check if logged in first to not waste early ping on the OTR profile Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/component_updater/pnacl/pnacl_component_installer.cc
diff --git a/chrome/browser/component_updater/pnacl/pnacl_component_installer.cc b/chrome/browser/component_updater/pnacl/pnacl_component_installer.cc
index aa78dfd3d18c5d3a23d52604360ac2b6aaab3c6b..9976e197c40f6f6a714bea3d4ad4f3efb10b3c6a 100644
--- a/chrome/browser/component_updater/pnacl/pnacl_component_installer.cc
+++ b/chrome/browser/component_updater/pnacl/pnacl_component_installer.cc
@@ -18,7 +18,10 @@
#include "base/version.h"
#include "base/win/windows_version.h"
#include "build/build_config.h"
+#include "chrome/browser/browser_process.h"
#include "chrome/browser/component_updater/component_updater_service.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "content/public/browser/browser_thread.h"
@@ -141,9 +144,22 @@ const char kNullVersion[] = "0.0.0.0";
// and the base directory will be:
// <profile>\AppData\Local\Google\Chrome\User Data\Pnacl\.
base::FilePath GetPnaclBaseDirectory() {
+#if defined(OS_CHROMEOS)
+ // For ChromeOS, temporarily make this user-dependent (for integrity) until
+ // we find a better solution.
+ // This is not ideal because of the following:
+ // (a) We end up with per-user copies instead of a single copy
+ // (b) The profile can change as users log in to different accounts
+ // so we need to watch for user-login-events (see pnacl_profile_observer.h).
+ Profile* profile = ProfileManager::GetLastUsedProfile();
+ base::FilePath path = profile->GetPath().AppendASCII(
+ FILE_PATH_LITERAL("pnacl"));
Dmitry Polukhin 2013/03/26 11:59:56 Nit, 2 idents.
jvoung - send to chromium... 2013/03/26 15:46:53 Done.
+ return path;
+#else
base::FilePath result;
CHECK(PathService::Get(chrome::DIR_PNACL_BASE, &result));
return result;
+#endif
}
bool GetLatestPnaclDirectory(base::FilePath* latest_dir,
@@ -230,24 +246,20 @@ bool CheckPnaclComponentManifest(base::DictionaryValue* manifest,
return true;
}
-class PnaclComponentInstaller : public ComponentInstaller {
- public:
- explicit PnaclComponentInstaller(const Version& version);
-
- virtual ~PnaclComponentInstaller() {}
-
- virtual void OnUpdateError(int error) OVERRIDE;
-
- virtual bool Install(base::DictionaryValue* manifest,
- const base::FilePath& unpack_path) OVERRIDE;
+PnaclComponentInstaller::PnaclComponentInstaller() : cus_(NULL) {
+ // Fill in most of the information. The version will be discovered later.
+ Version null_version(kNullVersion);
+ pnacl_component_.version = null_version;
+ pnacl_component_.name = "pnacl";
+ pnacl_component_.installer = this;
+ SetPnaclHash(&pnacl_component_);
- private:
- Version current_version_;
-};
+#if defined(OS_CHROMEOS)
+ profile_observer_.reset(new PnaclProfileObserver(this));
+#endif
+}
-PnaclComponentInstaller::PnaclComponentInstaller(
- const Version& version) : current_version_(version) {
- DCHECK(version.IsValid());
+PnaclComponentInstaller::~PnaclComponentInstaller() {
}
void PnaclComponentInstaller::OnUpdateError(int error) {
@@ -285,7 +297,7 @@ bool PnaclComponentInstaller::Install(base::DictionaryValue* manifest,
}
// Don't install if the current version is actually newer.
- if (current_version_.CompareTo(version) > 0)
+ if (get_current_version().CompareTo(version) > 0)
return false;
if (!PathContainsPnacl(unpack_path)) {
@@ -310,7 +322,7 @@ bool PnaclComponentInstaller::Install(base::DictionaryValue* manifest,
// Pnacl webpage and Pnacl was just installed at this time. They should
// then be able to reload the page and retry (or something).
// See: http://code.google.com/p/chromium/issues/detail?id=107438
- current_version_ = version;
+ set_current_version(version);
PathService::Override(chrome::DIR_PNACL_COMPONENT, path);
return true;
@@ -327,16 +339,13 @@ void DoCheckForUpdate(ComponentUpdateService* cus,
// Finally, do the registration with the right version number.
void FinishPnaclUpdateRegistration(ComponentUpdateService* cus,
- const Version& current_version) {
+ PnaclComponentInstaller* pci) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- // Note: the source is the default of BANDAID, even though the
- // crxes are hosted from CWS.
- CrxComponent pnacl;
- pnacl.name = "pnacl";
- pnacl.installer = new PnaclComponentInstaller(current_version);
- pnacl.version = current_version;
- SetPnaclHash(&pnacl);
- if (cus->RegisterComponent(pnacl) != ComponentUpdateService::kOk) {
+ CrxComponent pnacl_component = pci->get_component();
+ ComponentUpdateService::Status status =
+ cus->RegisterComponent(pnacl_component);
+ if (status != ComponentUpdateService::kOk
+ && status != ComponentUpdateService::kReplaced) {
NOTREACHED() << "Pnacl component registration failed.";
}
@@ -344,18 +353,25 @@ void FinishPnaclUpdateRegistration(ComponentUpdateService* cus,
// we want it to be available "soon", so kick off an update check
// earlier than usual.
Version null_version(kNullVersion);
- if (current_version.Equals(null_version)) {
+ if (pci->get_current_version().Equals(null_version)) {
BrowserThread::PostDelayedTask(
BrowserThread::UI, FROM_HERE,
- base::Bind(DoCheckForUpdate, cus, pnacl),
+ base::Bind(DoCheckForUpdate, cus, pnacl_component),
base::TimeDelta::FromSeconds(kInitialDelaySeconds));
}
}
// Check if there is an existing version on disk first to know when
// a hosted version is actually newer.
-void StartPnaclUpdateRegistration(ComponentUpdateService* cus) {
+void StartPnaclUpdateRegistration(ComponentUpdateService* cus,
+ PnaclComponentInstaller* pci) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+#if defined(OS_CHROMEOS)
+ // For ChromeOS don't start registration until the user has logged in,
+ // since the files are installed per user. See GetPnaclBaseDirectory().
+ if (!g_browser_process->profile_manager()->IsLoggedIn())
+ return;
+#endif
base::FilePath path = GetPnaclBaseDirectory();
if (!file_util::PathExists(path)) {
if (!file_util::CreateDirectory(path)) {
@@ -374,9 +390,11 @@ void StartPnaclUpdateRegistration(ComponentUpdateService* cus) {
}
}
+ pci->set_current_version(version);
+
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
- base::Bind(&FinishPnaclUpdateRegistration, cus, version));
+ base::Bind(&FinishPnaclUpdateRegistration, cus, pci));
// Remove older versions of PNaCl.
for (std::vector<base::FilePath>::iterator iter = older_dirs.begin();
@@ -387,13 +405,26 @@ void StartPnaclUpdateRegistration(ComponentUpdateService* cus) {
} // namespace
-void RegisterPnaclComponent(ComponentUpdateService* cus,
+void PnaclComponentInstaller::RegisterPnaclComponent(
+ ComponentUpdateService* cus,
const CommandLine& command_line) {
// Only register when given the right flag. This is important since
// we do an early component updater check above (in DoCheckForUpdate).
if (command_line.HasSwitch(switches::kEnablePnacl)) {
+ cus_ = cus;
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
- base::Bind(&StartPnaclUpdateRegistration, cus));
+ base::Bind(&StartPnaclUpdateRegistration, cus_, this));
}
}
+
+#if defined(OS_CHROMEOS)
+void PnaclComponentInstaller::ReRegisterPnacl() {
+ // We only create the profile observer, which can trigger a
+ // call to ReRegisterPnacl, if kEnablePnacl is given on the commandline.
+ // Thus, we don't check the commandline flags again here.
+ BrowserThread::PostTask(
+ BrowserThread::FILE, FROM_HERE,
+ base::Bind(&StartPnaclUpdateRegistration, cus_, this));
+}
+#endif

Powered by Google App Engine
This is Rietveld 408576698