Skip to content

Commit

Permalink
Merge to M48: "kiosk: Flush installed app files and cached crx"
Browse files Browse the repository at this point in the history
> So that they don't get corrupted after unclean shutdown.
> - Update UseSafeInstallation to enable flush in kiosk mode;
> - Added a |flush_on_put_| bool to ExternalCache and make it
>   flush cached crx when the bool is set;
> - Update KioskAppManager to set the bool flag when
>   initializing its ExternalCache;
>
> BUG=555220
>
> Review URL: https://codereview.chromium.org/1448723002
>
> Cr-Commit-Position: refs/heads/master@{#360142}
> (cherry picked from commit 8ed1dda)
>
> Review URL: https://codereview.chromium.org/1462463003
>
> Cr-Commit-Position: refs/heads/master@{#360420}
> (cherry picked from commit 2dcf0d1)

[email protected]

Review URL: https://codereview.chromium.org/1461753002 .

Cr-Commit-Position: refs/branch-heads/2564@{crosswalk-project#42}
Cr-Branched-From: 1283eca-refs/heads/master@{#359700}
  • Loading branch information
Xiyuan Xia committed Nov 18, 2015
1 parent 716e2e1 commit b7d6504
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 3 deletions.
1 change: 1 addition & 0 deletions chrome/browser/chromeos/app_mode/kiosk_app_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ KioskAppManager::KioskAppManager()
this,
true /* always_check_updates */,
false /* wait_for_cache_initialization */));
external_cache_->set_flush_on_put(true);
UpdateAppData();
local_accounts_subscription_ =
CrosSettings::Get()->AddSettingsObserver(
Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/chromeos/app_mode/startup_app_launcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "extensions/browser/extension_system.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension.h"
#include "extensions/common/file_util.h"
#include "extensions/common/manifest_handlers/kiosk_mode_info.h"
#include "extensions/common/manifest_handlers/offline_enabled_info.h"
#include "extensions/common/manifest_url_handlers.h"
Expand Down Expand Up @@ -435,6 +436,7 @@ void StartupAppLauncher::OnLaunchFailure(KioskAppLaunchError::Error error) {
}

void StartupAppLauncher::BeginInstall() {
extensions::file_util::SetUseSafeInstallation(true);
KioskAppManager::Get()->InstallFromCache(app_id_);
if (extensions::ExtensionSystem::Get(profile_)
->extension_service()
Expand Down
15 changes: 15 additions & 0 deletions chrome/browser/chromeos/extensions/external_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@

namespace chromeos {

namespace {

void FlushFile(const base::FilePath& path) {
base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_WRITE);
file.Flush();
file.Close();
}

} // namespace

ExternalCache::ExternalCache(const base::FilePath& cache_dir,
net::URLRequestContextGetter* request_context,
const scoped_refptr<base::SequencedTaskRunner>&
Expand Down Expand Up @@ -320,6 +330,11 @@ void ExternalCache::OnPutExtension(const std::string& id,
return;
}

if (flush_on_put_) {
backend_task_runner_->PostTask(FROM_HERE,
base::Bind(&FlushFile, file_path));
}

std::string update_url;
if (entry->GetString(extensions::ExternalProviderImpl::kExternalUpdateUrl,
&update_url) &&
Expand Down
5 changes: 5 additions & 0 deletions chrome/browser/chromeos/extensions/external_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ class ExternalCache : public content::NotificationObserver,
const std::string& version,
const PutExternalExtensionCallback& callback);

void set_flush_on_put(bool flush_on_put) { flush_on_put_ = flush_on_put; }

private:
// Notifies the that the cache has been updated, providing
// extensions loader with an updated list of extensions.
Expand Down Expand Up @@ -171,6 +173,9 @@ class ExternalCache : public content::NotificationObserver,
// Set to true if cache should wait for initialization flag file.
bool wait_for_cache_initialization_;

// Whether to flush the crx file after putting into |local_cache_|.
bool flush_on_put_ = false;

// This is the list of extensions currently configured.
scoped_ptr<base::DictionaryValue> extensions_;

Expand Down
21 changes: 18 additions & 3 deletions extensions/common/file_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ namespace extensions {
namespace file_util {
namespace {

enum SafeInstallationFlag {
DEFAULT, // Default case, controlled by a field trial.
DISABLED, // Safe installation is disabled.
ENABLED, // Safe installation is enabled.
};
SafeInstallationFlag g_use_safe_installation = DEFAULT;

// Returns true if the given file path exists and is not zero-length.
bool ValidateFilePath(const base::FilePath& path) {
int64 size = 0;
Expand All @@ -60,9 +67,13 @@ bool ValidateFilePath(const base::FilePath& path) {
// Returns true if the extension installation should flush all files and the
// directory.
bool UseSafeInstallation() {
const char kFieldTrialName[] = "ExtensionUseSafeInstallation";
const char kEnable[] = "Enable";
return base::FieldTrialList::FindFullName(kFieldTrialName) == kEnable;
if (g_use_safe_installation == DEFAULT) {
const char kFieldTrialName[] = "ExtensionUseSafeInstallation";
const char kEnable[] = "Enable";
return base::FieldTrialList::FindFullName(kFieldTrialName) == kEnable;
}

return g_use_safe_installation == ENABLED;
}

enum FlushOneOrAllFiles {
Expand Down Expand Up @@ -97,6 +108,10 @@ void FlushFilesInDir(const base::FilePath& path,

const base::FilePath::CharType kTempDirectoryName[] = FILE_PATH_LITERAL("Temp");

void SetUseSafeInstallation(bool use_safe_installation) {
g_use_safe_installation = use_safe_installation ? ENABLED : DISABLED;
}

base::FilePath InstallExtension(const base::FilePath& unpacked_source_dir,
const std::string& id,
const std::string& version,
Expand Down
3 changes: 3 additions & 0 deletions extensions/common/file_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ namespace file_util {

extern const base::FilePath::CharType kTempDirectoryName[];

// Sets the flag to enable safe installation (i.e. flush all installed files).
void SetUseSafeInstallation(bool use_safe_installation);

// Copies |unpacked_source_dir| into the right location under |extensions_dir|.
// The destination directory is returned on success, or empty path is returned
// on failure.
Expand Down

0 comments on commit b7d6504

Please sign in to comment.