From 493845a6522853c824e417add4f9c6d927f40983 Mon Sep 17 00:00:00 2001 From: "dpolukhin@chromium.org" Date: Fri, 20 Sep 2013 15:57:05 +0000 Subject: [PATCH] Delay app cache check until flag file indicates that it is ready Default apps cache will be prepopulated on factory and async imported from unencrypted stateful to encrypted one. So cache should wait for import completion. This CL depends on https://codereview.chromium.org/23609056/ BUG=293493 TEST=manual R=joaodasilva@chromium.org Review URL: https://codereview.chromium.org/23510012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@224392 0039d316-1c4b-4281-b951-d872f2087c98 --- .../browser/chromeos/extensions/external_cache.cc | 39 ++++++++++++++++++++-- .../browser/chromeos/extensions/external_cache.h | 11 ++++-- .../extensions/external_pref_cache_loader.cc | 3 +- chrome/browser/chromeos/policy/app_pack_updater.cc | 2 +- 4 files changed, 48 insertions(+), 7 deletions(-) diff --git a/chrome/browser/chromeos/extensions/external_cache.cc b/chrome/browser/chromeos/extensions/external_cache.cc index 817477219806..edda31223866 100644 --- a/chrome/browser/chromeos/extensions/external_cache.cc +++ b/chrome/browser/chromeos/extensions/external_cache.cc @@ -30,16 +30,24 @@ namespace { // File name extension for CRX files (not case sensitive). const char kCRXFileExtension[] = ".crx"; +// Name of flag file that indicates that cache is ready (import finished). +const char kCacheReadyFlagFileName[] = ".initialized"; + +// Delay between checking cache ready flag file. +const int64_t kCacheReadyDelayMs = 1000; + } // namespace ExternalCache::ExternalCache(const std::string& cache_dir, net::URLRequestContextGetter* request_context, Delegate* delegate, - bool always_check_updates) + bool always_check_updates, + bool wait_cache_initialization) : cache_dir_(cache_dir), request_context_(request_context), delegate_(delegate), always_check_updates_(always_check_updates), + wait_cache_initialization_(wait_cache_initialization), cached_extensions_(new base::DictionaryValue()), weak_ptr_factory_(this), worker_pool_token_( @@ -185,8 +193,10 @@ void ExternalCache::CheckCacheNow() { PostBlockingTask(FROM_HERE, base::Bind(&ExternalCache::BlockingCheckCache, weak_ptr_factory_.GetWeakPtr(), + worker_pool_token_, std::string(cache_dir_), - base::Passed(&prefs))); + base::Passed(&prefs), + wait_cache_initialization_)); } void ExternalCache::UpdateExtensionLoader() { @@ -198,8 +208,27 @@ void ExternalCache::UpdateExtensionLoader() { // static void ExternalCache::BlockingCheckCache( base::WeakPtr external_cache, + base::SequencedWorkerPool::SequenceToken sequence_token, const std::string& cache_dir, - scoped_ptr prefs) { + scoped_ptr prefs, + bool wait_cache_initialization) { + + base::FilePath dir(cache_dir); + if (wait_cache_initialization && + !base::PathExists(dir.AppendASCII(kCacheReadyFlagFileName))) { + content::BrowserThread::GetBlockingPool()->PostDelayedSequencedWorkerTask( + sequence_token, + FROM_HERE, + base::Bind(&ExternalCache::BlockingCheckCache, + external_cache, + sequence_token, + std::string(cache_dir), + base::Passed(&prefs), + wait_cache_initialization), + base::TimeDelta::FromMilliseconds(kCacheReadyDelayMs)); + return; + } + BlockingCheckCacheInternal(cache_dir, prefs.get()); content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, base::Bind(&ExternalCache::OnCacheUpdated, @@ -239,6 +268,10 @@ void ExternalCache::BlockingCheckCacheInternal(const std::string& cache_dir, continue; } + // Skip flag file that indicates that cache is ready. + if (basename == kCacheReadyFlagFileName) + continue; + // crx files in the cache are named -.crx. std::string id; std::string version; diff --git a/chrome/browser/chromeos/extensions/external_cache.h b/chrome/browser/chromeos/extensions/external_cache.h index 07f22529f075..8f42c42b00df 100644 --- a/chrome/browser/chromeos/extensions/external_cache.h +++ b/chrome/browser/chromeos/extensions/external_cache.h @@ -49,10 +49,12 @@ class ExternalCache : public content::NotificationObserver, // The |request_context| is used for the update checks. // By default updates are checked for the extensions with external_update_url. // If |always_check_webstore| set, updates will be check for external_crx too. + // If |wait_cache_initialization|, cache will wait for flag file in cache dir. ExternalCache(const std::string& cache_dir, net::URLRequestContextGetter* request_context, Delegate* delegate, - bool always_check_updates); + bool always_check_updates, + bool wait_cache_initialization); virtual ~ExternalCache(); // Returns already cached extensions. @@ -115,8 +117,10 @@ class ExternalCache : public content::NotificationObserver, // Ownership of |prefs| is transferred to this function. static void BlockingCheckCache( base::WeakPtr external_cache, + base::SequencedWorkerPool::SequenceToken token, const std::string& app_cache_dir, - scoped_ptr prefs); + scoped_ptr prefs, + bool wait_cache_initialization); // Helper for BlockingCheckCache(), updates |prefs|. static void BlockingCheckCacheInternal( @@ -156,6 +160,9 @@ class ExternalCache : public content::NotificationObserver, // Updates needs to be check for the extensions with external_crx too. bool always_check_updates_; + // Set to true if cache should wait for initialization flag file. + bool wait_cache_initialization_; + // This is the list of extensions currently configured. scoped_ptr extensions_; diff --git a/chrome/browser/chromeos/extensions/external_pref_cache_loader.cc b/chrome/browser/chromeos/extensions/external_pref_cache_loader.cc index 74811ccebd6e..d05a2690cee3 100644 --- a/chrome/browser/chromeos/extensions/external_pref_cache_loader.cc +++ b/chrome/browser/chromeos/extensions/external_pref_cache_loader.cc @@ -72,7 +72,8 @@ class ExternalCacheDispatcher : public ExternalCache::Delegate { ExternalCacheDispatcher() : external_cache_(kPreinstalledAppsCacheDir, - g_browser_process->system_request_context(), this, true), + g_browser_process->system_request_context(), + this, true, true), base_path_id_(0), is_extensions_list_ready_(false) { } diff --git a/chrome/browser/chromeos/policy/app_pack_updater.cc b/chrome/browser/chromeos/policy/app_pack_updater.cc index b66fa29980b4..59a6baae384f 100644 --- a/chrome/browser/chromeos/policy/app_pack_updater.cc +++ b/chrome/browser/chromeos/policy/app_pack_updater.cc @@ -62,7 +62,7 @@ AppPackUpdater::AppPackUpdater(net::URLRequestContextGetter* request_context, : weak_ptr_factory_(this), created_extension_loader_(false), install_attributes_(install_attributes), - external_cache_(kAppPackCacheDir, request_context, this, false) { + external_cache_(kAppPackCacheDir, request_context, this, false, false) { app_pack_subscription_ = chromeos::CrosSettings::Get()->AddSettingsObserver( chromeos::kAppPack, base::Bind(&AppPackUpdater::AppPackChanged, base::Unretained(this))); -- 2.11.4.GIT