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

Unified Diff: chrome/browser/chrome_content_browser_client.cc

Issue 949293002: Implement a poor man's PostAfterStartupTask() function. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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/chrome_content_browser_client.cc
diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc
index e3ae8430cec806a0579d1fb3054a56e0a57932a8..e94dae39d2635487de1210c4ba5c2c22776c65a0 100644
--- a/chrome/browser/chrome_content_browser_client.cc
+++ b/chrome/browser/chrome_content_browser_client.cc
@@ -16,15 +16,18 @@
#include "base/path_service.h"
#include "base/prefs/pref_service.h"
#include "base/prefs/scoped_user_pref_update.h"
+#include "base/rand_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/sequenced_worker_pool.h"
+#include "base/time/time.h"
#include "chrome/browser/browser_about_handler.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_shutdown.h"
#include "chrome/browser/browsing_data/browsing_data_helper.h"
#include "chrome/browser/browsing_data/browsing_data_remover.h"
#include "chrome/browser/character_encoding.h"
+#include "chrome/browser/chrome_browser_main.h"
#include "chrome/browser/chrome_content_browser_client_parts.h"
#include "chrome/browser/chrome_net_benchmarking_message_filter.h"
#include "chrome/browser/chrome_quota_permission_context.h"
@@ -808,6 +811,33 @@ content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
return main_parts;
}
+namespace {
+
+void PostAfterStartupTaskImpl(
+ const tracked_objects::Location& from_here,
+ const scoped_refptr<base::TaskRunner>& task_runner,
+ const base::Closure& task) {
+ if (!IsBrowserStartupComplete()) {
+ const int kMinDelay = 5;
+ const int kMaxDelay = 30;
+ task_runner->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(PostAfterStartupTaskImpl, from_here, task_runner, task),
+ base::TimeDelta::FromSeconds(base::RandInt(kMinDelay, kMaxDelay)));
+ return;
+ }
+ task_runner->PostTask(from_here, task);
+}
+
+} // namespace
+
+void ChromeContentBrowserClient::PostAfterStartupTask(
+ const tracked_objects::Location& from_here,
+ const scoped_refptr<base::TaskRunner>& task_runner,
+ const base::Closure& task) {
+ PostAfterStartupTaskImpl(from_here, task_runner, task);
+}
+
std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
content::BrowserContext* browser_context,
const GURL& site) {

Powered by Google App Engine
This is Rietveld 408576698