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

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
« no previous file with comments | « chrome/browser/chrome_content_browser_client.h ('k') | content/browser/browser_thread_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 f3d767f5790f955d8df52b54a1ce038bf0a7c366..c0c48537803ef3894c8e009d31fe5398c2f77337 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"
@@ -695,6 +698,8 @@ ChromeContentBrowserClient::ChromeContentBrowserClient()
#if defined(ENABLE_EXTENSIONS)
extra_parts_.push_back(new ChromeContentBrowserClientExtensionsPart);
#endif
+
+ weak_this_ = weak_factory_.GetWeakPtr();
}
ChromeContentBrowserClient::~ChromeContentBrowserClient() {
@@ -786,6 +791,41 @@ content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
return main_parts;
}
+void ChromeContentBrowserClient::PostAfterStartupTask(
+ const tracked_objects::Location& from_here,
+ const scoped_refptr<base::TaskRunner>& task_runner,
+ const base::Closure& task) {
+ if (IsBrowserStartupComplete()) {
+ task_runner->PostTask(from_here, task);
+ return;
+ }
+
+ if (!BrowserThread:: CurrentlyOn(BrowserThread::UI)) {
+ BrowserThread::PostTask(
+ BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&ChromeContentBrowserClient::PostAfterStartupTask,
+ weak_this_, from_here, task_runner, task));
+ return;
+ }
+
+ if (after_startup_tasks_.empty()) {
+ BrowserThread::PostDelayedTask(
+ BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&ChromeContentBrowserClient::OnAfterStartupTasksTimer,
+ weak_this_),
+ base::TimeDelta::FromSeconds(5));
+ }
+
+ // When the time comes, spread their execution over 30 seconds.
+ const int kMinDelay = 0;
+ const int kMaxDelay = 30;
+ after_startup_tasks_.push_back(base::Bind(
+ &base::TaskRunner::PostDelayedTask, task_runner, from_here, task,
+ base::TimeDelta::FromSeconds(base::RandInt(kMinDelay, kMaxDelay))));
+}
+
std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
content::BrowserContext* browser_context,
const GURL& site) {
@@ -2556,6 +2596,22 @@ void ChromeContentBrowserClient::OverridePageVisibilityState(
}
}
+void ChromeContentBrowserClient::OnAfterStartupTasksTimer() {
+ if (!IsBrowserStartupComplete()) {
+ BrowserThread::PostDelayedTask(
+ BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&ChromeContentBrowserClient::OnAfterStartupTasksTimer,
+ weak_this_),
+ base::TimeDelta::FromSeconds(5));
+ return;
+ }
+
+ for (const auto& task : after_startup_tasks_)
+ task.Run();
+ after_startup_tasks_.clear();
michaeln 2015/03/25 01:09:32 Oh, I think there's a problem with this? I think i
michaeln 2015/03/25 02:25:18 Done
+}
+
#if defined(ENABLE_WEBRTC)
void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
base::CommandLine* to_command_line,
« no previous file with comments | « chrome/browser/chrome_content_browser_client.h ('k') | content/browser/browser_thread_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698