Commit ee07658e authored by Yafei Duan's avatar Yafei Duan Committed by Commit Bot

[Offline Pages] Fix objects on UI thread being used in background thread

As dewittj@ pointed out, in StartupMaintenanceTask some raw pointers to
the objects on UI thread are being used in background thread, which is
unsafe. This CL fixes the issue by making copy of objects on UI thread
and bind them before hopping to background thread.

Fortunately other tasks didn't have the wrong implementation.

Bug: 832232
Change-Id: Ia8913ba6036b9c2ce357d53857f968fe1629c03d
Reviewed-on: https://chromium-review.googlesource.com/1027130
Commit-Queue: Yafei Duan <romax@chromium.org>
Reviewed-by: default avatarJustin DeWitt <dewittj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#553743}
parent e4d34985
...@@ -225,8 +225,7 @@ SyncOperationResult CheckTemporaryPageConsistencySync( ...@@ -225,8 +225,7 @@ SyncOperationResult CheckTemporaryPageConsistencySync(
} }
void ReportStorageUsageSync(sql::Connection* db, void ReportStorageUsageSync(sql::Connection* db,
const std::vector<std::string>& namespaces, const std::vector<std::string>& namespaces) {
ArchiveManager* archive_manager) {
static const char kSql[] = static const char kSql[] =
"SELECT sum(file_size) FROM " OFFLINE_PAGES_TABLE_NAME "SELECT sum(file_size) FROM " OFFLINE_PAGES_TABLE_NAME
" WHERE client_namespace = ?"; " WHERE client_namespace = ?";
...@@ -243,33 +242,31 @@ void ReportStorageUsageSync(sql::Connection* db, ...@@ -243,33 +242,31 @@ void ReportStorageUsageSync(sql::Connection* db,
} }
} }
bool StartupMaintenanceSync(OfflinePageMetadataStoreSQL* store, bool StartupMaintenanceSync(
ArchiveManager* archive_manager, const std::vector<std::string>& persistent_namespaces,
ClientPolicyController* policy_controller, const std::vector<std::string>& temporary_namespaces,
sql::Connection* db) { const base::FilePath& temporary_archives_dir,
const base::FilePath& private_archives_dir,
sql::Connection* db) {
if (!db) if (!db)
return false; return false;
std::vector<std::string> temporary_namespaces =
policy_controller->GetNamespacesRemovedOnCacheReset();
std::vector<std::string> persistent_namespaces =
policy_controller->GetNamespacesForUserRequestedDownload();
// Clear temporary pages that are in legacy directory, which is also the // Clear temporary pages that are in legacy directory, which is also the
// directory that serves as the 'private' directory. // directory that serves as the 'private' directory.
SyncOperationResult result = ClearLegacyPagesInPrivateDirSync( SyncOperationResult result = ClearLegacyPagesInPrivateDirSync(
db, temporary_namespaces, persistent_namespaces, db, temporary_namespaces, persistent_namespaces, private_archives_dir);
archive_manager->GetPrivateArchivesDir());
// Clear temporary pages in cache directory. // Clear temporary pages in cache directory.
result = CheckTemporaryPageConsistencySync( result = CheckTemporaryPageConsistencySync(db, temporary_namespaces,
db, temporary_namespaces, archive_manager->GetTemporaryArchivesDir()); temporary_archives_dir);
UMA_HISTOGRAM_ENUMERATION("OfflinePages.ConsistencyCheck.Temporary.Result", UMA_HISTOGRAM_ENUMERATION("OfflinePages.ConsistencyCheck.Temporary.Result",
result, SyncOperationResult::RESULT_COUNT); result, SyncOperationResult::RESULT_COUNT);
// Report storage usage UMA. // Report storage usage UMA, |temporary_namespaces| + |persistent_namespaces|
std::vector<std::string> namespaces = policy_controller->GetAllNamespaces(); // should be all namespaces. This is implicitly checked by the
ReportStorageUsageSync(db, namespaces, archive_manager); // TestReportStorageUsage unit test.
ReportStorageUsageSync(db, temporary_namespaces);
ReportStorageUsageSync(db, persistent_namespaces);
return true; return true;
} }
...@@ -294,9 +291,18 @@ StartupMaintenanceTask::~StartupMaintenanceTask() = default; ...@@ -294,9 +291,18 @@ StartupMaintenanceTask::~StartupMaintenanceTask() = default;
void StartupMaintenanceTask::Run() { void StartupMaintenanceTask::Run() {
TRACE_EVENT_ASYNC_BEGIN0("offline_pages", "StartupMaintenanceTask running", TRACE_EVENT_ASYNC_BEGIN0("offline_pages", "StartupMaintenanceTask running",
this); this);
std::vector<std::string> all_namespaces =
policy_controller_->GetAllNamespaces();
std::vector<std::string> temporary_namespaces =
policy_controller_->GetNamespacesRemovedOnCacheReset();
std::vector<std::string> persistent_namespaces =
policy_controller_->GetNamespacesForUserRequestedDownload();
store_->Execute( store_->Execute(
base::BindOnce(&StartupMaintenanceSync, store_, archive_manager_, base::BindOnce(&StartupMaintenanceSync, persistent_namespaces,
policy_controller_), temporary_namespaces,
archive_manager_->GetTemporaryArchivesDir(),
archive_manager_->GetPrivateArchivesDir()),
base::BindOnce(&StartupMaintenanceTask::OnStartupMaintenanceDone, base::BindOnce(&StartupMaintenanceTask::OnStartupMaintenanceDone,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
} }
......
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