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

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 f7c3c618d8c8ecbcf10cbc566c92548eba06dde1..3a0eaba19eb98c4cec9bb414afe00afe2861ab6d 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"
@@ -809,6 +812,32 @@ 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 (!chrome::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);
jam 2015/03/10 23:04:34 It seems simpler that the code below would pass al
michaeln 2015/03/10 23:54:54 Is it? We'd need a thread safe collection somewher
jam 2015/03/23 23:19:44 sure, but given that only a few places should/will
michaeln 2015/03/24 23:01:11 Done. There is still a polling timer but only one
+}
+}
+
+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);
gab 2015/03/10 15:00:32 Why does this need an explicit impl? i.e. why not
michaeln 2015/03/10 19:46:26 good question, this method can be called on anythr
gab 2015/03/10 19:55:27 ChromeContentBrowserClient has a weak_factory_, ca
michaeln 2015/03/10 23:54:54 nope, weakptrs have thread affinity https://code.g
michaeln 2015/03/24 23:01:11 initialized a weak_this_ ptr in the constructor
+}
+
std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
content::BrowserContext* browser_context,
const GURL& site) {

Powered by Google App Engine
This is Rietveld 408576698