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

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
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 650 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 #endif 691 #endif
689 692
690 #if !defined(OS_ANDROID) 693 #if !defined(OS_ANDROID)
691 TtsExtensionEngine* tts_extension_engine = TtsExtensionEngine::GetInstance(); 694 TtsExtensionEngine* tts_extension_engine = TtsExtensionEngine::GetInstance();
692 TtsController::GetInstance()->SetTtsEngineDelegate(tts_extension_engine); 695 TtsController::GetInstance()->SetTtsEngineDelegate(tts_extension_engine);
693 #endif 696 #endif
694 697
695 #if defined(ENABLE_EXTENSIONS) 698 #if defined(ENABLE_EXTENSIONS)
696 extra_parts_.push_back(new ChromeContentBrowserClientExtensionsPart); 699 extra_parts_.push_back(new ChromeContentBrowserClientExtensionsPart);
697 #endif 700 #endif
701
702 weak_this_ = weak_factory_.GetWeakPtr();
698 } 703 }
699 704
700 ChromeContentBrowserClient::~ChromeContentBrowserClient() { 705 ChromeContentBrowserClient::~ChromeContentBrowserClient() {
701 for (int i = static_cast<int>(extra_parts_.size()) - 1; i >= 0; --i) 706 for (int i = static_cast<int>(extra_parts_.size()) - 1; i >= 0; --i)
702 delete extra_parts_[i]; 707 delete extra_parts_[i];
703 extra_parts_.clear(); 708 extra_parts_.clear();
704 } 709 }
705 710
706 // static 711 // static
707 void ChromeContentBrowserClient::RegisterProfilePrefs( 712 void ChromeContentBrowserClient::RegisterProfilePrefs(
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 784
780 #if defined(USE_X11) 785 #if defined(USE_X11)
781 main_parts->AddParts(new ChromeBrowserMainExtraPartsX11()); 786 main_parts->AddParts(new ChromeBrowserMainExtraPartsX11());
782 #endif 787 #endif
783 788
784 chrome::AddMetricsExtraParts(main_parts); 789 chrome::AddMetricsExtraParts(main_parts);
785 790
786 return main_parts; 791 return main_parts;
787 } 792 }
788 793
794 void ChromeContentBrowserClient::PostAfterStartupTask(
795 const tracked_objects::Location& from_here,
796 const scoped_refptr<base::TaskRunner>& task_runner,
797 const base::Closure& task) {
798 if (IsBrowserStartupComplete()) {
799 task_runner->PostTask(from_here, task);
800 return;
801 }
802
803 if (!BrowserThread:: CurrentlyOn(BrowserThread::UI)) {
804 BrowserThread::PostTask(
805 BrowserThread::UI,
806 FROM_HERE,
807 base::Bind(&ChromeContentBrowserClient::PostAfterStartupTask,
808 weak_this_, from_here, task_runner, task));
809 return;
810 }
811
812 if (after_startup_tasks_.empty()) {
813 BrowserThread::PostDelayedTask(
814 BrowserThread::UI,
815 FROM_HERE,
816 base::Bind(&ChromeContentBrowserClient::OnAfterStartupTasksTimer,
817 weak_this_),
818 base::TimeDelta::FromSeconds(5));
819 }
820
821 // When the time comes, spread their execution over 30 seconds.
822 const int kMinDelay = 0;
823 const int kMaxDelay = 30;
824 after_startup_tasks_.push_back(base::Bind(
825 &base::TaskRunner::PostDelayedTask, task_runner, from_here, task,
826 base::TimeDelta::FromSeconds(base::RandInt(kMinDelay, kMaxDelay))));
827 }
828
789 std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite( 829 std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
790 content::BrowserContext* browser_context, 830 content::BrowserContext* browser_context,
791 const GURL& site) { 831 const GURL& site) {
792 std::string partition_id; 832 std::string partition_id;
793 833
794 // The partition ID for webview guest processes is the string value of its 834 // The partition ID for webview guest processes is the string value of its
795 // SiteInstance URL - "chrome-guest://app_id/persist?partition". 835 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
796 if (site.SchemeIs(content::kGuestScheme)) { 836 if (site.SchemeIs(content::kGuestScheme)) {
797 partition_id = site.spec(); 837 partition_id = site.spec();
798 } else if (site.GetOrigin().spec() == kChromeUIChromeSigninURL) { 838 } else if (site.GetOrigin().spec() == kChromeUIChromeSigninURL) {
(...skipping 1750 matching lines...) Expand 10 before | Expand all | Expand 10 after
2549 Profile* profile = 2589 Profile* profile =
2550 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 2590 Profile::FromBrowserContext(web_contents->GetBrowserContext());
2551 prerender::PrerenderManager* prerender_manager = 2591 prerender::PrerenderManager* prerender_manager =
2552 prerender::PrerenderManagerFactory::GetForProfile(profile); 2592 prerender::PrerenderManagerFactory::GetForProfile(profile);
2553 if (prerender_manager && 2593 if (prerender_manager &&
2554 prerender_manager->IsWebContentsPrerendering(web_contents, nullptr)) { 2594 prerender_manager->IsWebContentsPrerendering(web_contents, nullptr)) {
2555 *visibility_state = blink::WebPageVisibilityStatePrerender; 2595 *visibility_state = blink::WebPageVisibilityStatePrerender;
2556 } 2596 }
2557 } 2597 }
2558 2598
2599 void ChromeContentBrowserClient::OnAfterStartupTasksTimer() {
2600 if (!IsBrowserStartupComplete()) {
2601 BrowserThread::PostDelayedTask(
2602 BrowserThread::UI,
2603 FROM_HERE,
2604 base::Bind(&ChromeContentBrowserClient::OnAfterStartupTasksTimer,
2605 weak_this_),
2606 base::TimeDelta::FromSeconds(5));
2607 return;
2608 }
2609
2610 for (const auto& task : after_startup_tasks_)
2611 task.Run();
2612 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
2613 }
2614
2559 #if defined(ENABLE_WEBRTC) 2615 #if defined(ENABLE_WEBRTC)
2560 void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch( 2616 void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
2561 base::CommandLine* to_command_line, 2617 base::CommandLine* to_command_line,
2562 const base::CommandLine& from_command_line, 2618 const base::CommandLine& from_command_line,
2563 VersionInfo::Channel channel) { 2619 VersionInfo::Channel channel) {
2564 #if defined(OS_ANDROID) 2620 #if defined(OS_ANDROID)
2565 const VersionInfo::Channel kMaxDisableEncryptionChannel = 2621 const VersionInfo::Channel kMaxDisableEncryptionChannel =
2566 VersionInfo::CHANNEL_BETA; 2622 VersionInfo::CHANNEL_BETA;
2567 #else 2623 #else
2568 const VersionInfo::Channel kMaxDisableEncryptionChannel = 2624 const VersionInfo::Channel kMaxDisableEncryptionChannel =
2569 VersionInfo::CHANNEL_DEV; 2625 VersionInfo::CHANNEL_DEV;
2570 #endif 2626 #endif
2571 if (channel <= kMaxDisableEncryptionChannel) { 2627 if (channel <= kMaxDisableEncryptionChannel) {
2572 static const char* const kWebRtcDevSwitchNames[] = { 2628 static const char* const kWebRtcDevSwitchNames[] = {
2573 switches::kDisableWebRtcEncryption, 2629 switches::kDisableWebRtcEncryption,
2574 }; 2630 };
2575 to_command_line->CopySwitchesFrom(from_command_line, 2631 to_command_line->CopySwitchesFrom(from_command_line,
2576 kWebRtcDevSwitchNames, 2632 kWebRtcDevSwitchNames,
2577 arraysize(kWebRtcDevSwitchNames)); 2633 arraysize(kWebRtcDevSwitchNames));
2578 } 2634 }
2579 } 2635 }
2580 #endif // defined(ENABLE_WEBRTC) 2636 #endif // defined(ENABLE_WEBRTC)
2581 2637
2582 } // namespace chrome 2638 } // namespace chrome
OLDNEW
« 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