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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chrome_content_browser_client.h" 5 #include "chrome/browser/chrome_content_browser_client.h"
6 6
7 #include <set> 7 #include <set>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/files/scoped_file.h" 13 #include "base/files/scoped_file.h"
14 #include "base/i18n/icu_util.h" 14 #include "base/i18n/icu_util.h"
15 #include "base/lazy_instance.h" 15 #include "base/lazy_instance.h"
16 #include "base/path_service.h" 16 #include "base/path_service.h"
17 #include "base/prefs/pref_service.h" 17 #include "base/prefs/pref_service.h"
18 #include "base/prefs/scoped_user_pref_update.h" 18 #include "base/prefs/scoped_user_pref_update.h"
19 #include "base/rand_util.h"
19 #include "base/strings/string_number_conversions.h" 20 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
21 #include "base/threading/sequenced_worker_pool.h" 22 #include "base/threading/sequenced_worker_pool.h"
23 #include "base/time/time.h"
22 #include "chrome/browser/browser_about_handler.h" 24 #include "chrome/browser/browser_about_handler.h"
23 #include "chrome/browser/browser_process.h" 25 #include "chrome/browser/browser_process.h"
24 #include "chrome/browser/browser_shutdown.h" 26 #include "chrome/browser/browser_shutdown.h"
25 #include "chrome/browser/browsing_data/browsing_data_helper.h" 27 #include "chrome/browser/browsing_data/browsing_data_helper.h"
26 #include "chrome/browser/browsing_data/browsing_data_remover.h" 28 #include "chrome/browser/browsing_data/browsing_data_remover.h"
27 #include "chrome/browser/character_encoding.h" 29 #include "chrome/browser/character_encoding.h"
30 #include "chrome/browser/chrome_browser_main.h"
28 #include "chrome/browser/chrome_content_browser_client_parts.h" 31 #include "chrome/browser/chrome_content_browser_client_parts.h"
29 #include "chrome/browser/chrome_net_benchmarking_message_filter.h" 32 #include "chrome/browser/chrome_net_benchmarking_message_filter.h"
30 #include "chrome/browser/chrome_quota_permission_context.h" 33 #include "chrome/browser/chrome_quota_permission_context.h"
31 #include "chrome/browser/content_settings/cookie_settings.h" 34 #include "chrome/browser/content_settings/cookie_settings.h"
32 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 35 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
33 #include "chrome/browser/defaults.h" 36 #include "chrome/browser/defaults.h"
34 #include "chrome/browser/download/download_prefs.h" 37 #include "chrome/browser/download/download_prefs.h"
35 #include "chrome/browser/font_family_cache.h" 38 #include "chrome/browser/font_family_cache.h"
36 #include "chrome/browser/geolocation/chrome_access_token_store.h" 39 #include "chrome/browser/geolocation/chrome_access_token_store.h"
37 #include "chrome/browser/geolocation/geolocation_permission_context.h" 40 #include "chrome/browser/geolocation/geolocation_permission_context.h"
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 805
803 #if defined(USE_X11) 806 #if defined(USE_X11)
804 main_parts->AddParts(new ChromeBrowserMainExtraPartsX11()); 807 main_parts->AddParts(new ChromeBrowserMainExtraPartsX11());
805 #endif 808 #endif
806 809
807 chrome::AddMetricsExtraParts(main_parts); 810 chrome::AddMetricsExtraParts(main_parts);
808 811
809 return main_parts; 812 return main_parts;
810 } 813 }
811 814
815 namespace {
816 void PostAfterStartupTaskImpl(
817 const tracked_objects::Location& from_here,
818 const scoped_refptr<base::TaskRunner>& task_runner,
819 const base::Closure& task) {
820 if (!chrome::IsBrowserStartupComplete()) {
821 const int kMinDelay = 5;
822 const int kMaxDelay = 30;
823 task_runner->PostDelayedTask(
824 FROM_HERE,
825 base::Bind(PostAfterStartupTaskImpl,
826 from_here, task_runner, task),
827 base::TimeDelta::FromSeconds(base::RandInt(kMinDelay, kMaxDelay)));
828 return;
829 }
830 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
831 }
832 }
833
834 void ChromeContentBrowserClient::PostAfterStartupTask(
835 const tracked_objects::Location& from_here,
836 const scoped_refptr<base::TaskRunner>& task_runner,
837 const base::Closure& task) {
838 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
839 }
840
812 std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite( 841 std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
813 content::BrowserContext* browser_context, 842 content::BrowserContext* browser_context,
814 const GURL& site) { 843 const GURL& site) {
815 std::string partition_id; 844 std::string partition_id;
816 845
817 // The partition ID for webview guest processes is the string value of its 846 // The partition ID for webview guest processes is the string value of its
818 // SiteInstance URL - "chrome-guest://app_id/persist?partition". 847 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
819 if (site.SchemeIs(content::kGuestScheme)) { 848 if (site.SchemeIs(content::kGuestScheme)) {
820 partition_id = site.spec(); 849 partition_id = site.spec();
821 } else if (site.GetOrigin().spec() == kChromeUIChromeSigninURL) { 850 } else if (site.GetOrigin().spec() == kChromeUIChromeSigninURL) {
(...skipping 1819 matching lines...) Expand 10 before | Expand all | Expand 10 after
2641 switches::kDisableWebRtcEncryption, 2670 switches::kDisableWebRtcEncryption,
2642 }; 2671 };
2643 to_command_line->CopySwitchesFrom(from_command_line, 2672 to_command_line->CopySwitchesFrom(from_command_line,
2644 kWebRtcDevSwitchNames, 2673 kWebRtcDevSwitchNames,
2645 arraysize(kWebRtcDevSwitchNames)); 2674 arraysize(kWebRtcDevSwitchNames));
2646 } 2675 }
2647 } 2676 }
2648 #endif // defined(ENABLE_WEBRTC) 2677 #endif // defined(ENABLE_WEBRTC)
2649 2678
2650 } // namespace chrome 2679 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698