Read services customization manifest on FILE thread

BUG=chromium-os:11103
TEST=none

Review URL: http://codereview.chromium.org/6377003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72318 0039d316-1c4b-4281-b951-d872f2087c98
parent 779dae65
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_thread.h"
#include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/cros/network_library.h" #include "chrome/browser/chromeos/cros/network_library.h"
#include "chrome/browser/chromeos/customization_document.h" #include "chrome/browser/chromeos/customization_document.h"
...@@ -36,8 +37,9 @@ const int kRetriesDelayInSec = 2; ...@@ -36,8 +37,9 @@ const int kRetriesDelayInSec = 2;
} // namespace } // namespace
namespace chromeos { DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::ApplyServicesCustomization);
namespace chromeos {
// static // static
void ApplyServicesCustomization::StartIfNeeded() { void ApplyServicesCustomization::StartIfNeeded() {
...@@ -79,18 +81,14 @@ bool ApplyServicesCustomization::Init() { ...@@ -79,18 +81,14 @@ bool ApplyServicesCustomization::Init() {
} }
if (url_.SchemeIsFile()) { if (url_.SchemeIsFile()) {
std::string manifest; BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
if (file_util::ReadFileToString(FilePath(url_.path()), &manifest)) { NewRunnableMethod(this,
Apply(manifest); &ApplyServicesCustomization::ReadFileInBackground,
FilePath(url_.path())));
} else { } else {
LOG(ERROR) << "Failed to load services customization manifest from: " StartFileFetch();
<< url_.path();
}
return false;
} }
StartFileFetch();
return true; return true;
} }
...@@ -125,7 +123,29 @@ void ApplyServicesCustomization::OnURLFetchComplete( ...@@ -125,7 +123,29 @@ void ApplyServicesCustomization::OnURLFetchComplete(
MessageLoop::current()->DeleteSoon(FROM_HERE, this); MessageLoop::current()->DeleteSoon(FROM_HERE, this);
} }
void ApplyServicesCustomization::ReadFileInBackground(const FilePath& file) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
std::string manifest;
if (file_util::ReadFileToString(file, &manifest)) {
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
NewRunnableMethod(
this, &ApplyServicesCustomization::ApplyAndDelete, manifest));
} else {
VLOG(1) << "Failed to load services customization manifest from: "
<< file.value();
BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this);
}
}
void ApplyServicesCustomization::ApplyAndDelete(const std::string& manifest) {
Apply(manifest);
MessageLoop::current()->DeleteSoon(FROM_HERE, this);
}
void ApplyServicesCustomization::Apply(const std::string& manifest) { void ApplyServicesCustomization::Apply(const std::string& manifest) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
chromeos::ServicesCustomizationDocument customization; chromeos::ServicesCustomizationDocument customization;
if (!customization.LoadManifestFromString(manifest)) { if (!customization.LoadManifestFromString(manifest)) {
LOG(ERROR) << "Failed to partner parse services customizations manifest"; LOG(ERROR) << "Failed to partner parse services customizations manifest";
...@@ -146,4 +166,4 @@ void ApplyServicesCustomization::Apply(const std::string& manifest) { ...@@ -146,4 +166,4 @@ void ApplyServicesCustomization::Apply(const std::string& manifest) {
SetApplied(true); SetApplied(true);
} }
} } // namespace chromeos
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "chrome/common/net/url_fetcher.h" #include "chrome/common/net/url_fetcher.h"
#include "googleurl/src/gurl.h" #include "googleurl/src/gurl.h"
class FilePath;
class PrefService; class PrefService;
namespace chromeos { namespace chromeos {
...@@ -51,6 +52,12 @@ class ApplyServicesCustomization : public URLFetcher::Delegate { ...@@ -51,6 +52,12 @@ class ApplyServicesCustomization : public URLFetcher::Delegate {
// Applies given |manifest|. // Applies given |manifest|.
void Apply(const std::string& manifest); void Apply(const std::string& manifest);
// Applies given |manifest| and delete this object.
void ApplyAndDelete(const std::string& manifest);
// Executes on FILE thread and reads file to string.
void ReadFileInBackground(const FilePath& file);
// Remember in local state status of kServicesCustomizationAppliedPref. // Remember in local state status of kServicesCustomizationAppliedPref.
static void SetApplied(bool val); static void SetApplied(bool val);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment