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

Side by Side Diff: chrome/browser/chrome_browser_main_win.cc

Issue 1432123002: Switch to direct write font proxy and remove the font cache. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dwfontsplit
Patch Set: Remove some more code, and add code to delete font cache file. Created 5 years 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 | « no previous file | chrome/chrome_utility.gypi » ('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_browser_main_win.h" 5 #include "chrome/browser/chrome_browser_main_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <shellapi.h> 8 #include <shellapi.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 #include "chrome/installer/util/browser_distribution.h" 50 #include "chrome/installer/util/browser_distribution.h"
51 #include "chrome/installer/util/helper.h" 51 #include "chrome/installer/util/helper.h"
52 #include "chrome/installer/util/install_util.h" 52 #include "chrome/installer/util/install_util.h"
53 #include "chrome/installer/util/installer_util_strings.h" 53 #include "chrome/installer/util/installer_util_strings.h"
54 #include "chrome/installer/util/l10n_string_util.h" 54 #include "chrome/installer/util/l10n_string_util.h"
55 #include "chrome/installer/util/shell_util.h" 55 #include "chrome/installer/util/shell_util.h"
56 #include "content/public/browser/browser_thread.h" 56 #include "content/public/browser/browser_thread.h"
57 #include "content/public/browser/utility_process_host.h" 57 #include "content/public/browser/utility_process_host.h"
58 #include "content/public/browser/utility_process_host_client.h" 58 #include "content/public/browser/utility_process_host_client.h"
59 #include "content/public/common/content_switches.h" 59 #include "content/public/common/content_switches.h"
60 #include "content/public/common/dwrite_font_platform_win.h"
61 #include "content/public/common/main_function_params.h" 60 #include "content/public/common/main_function_params.h"
62 #include "ui/base/cursor/cursor_loader_win.h" 61 #include "ui/base/cursor/cursor_loader_win.h"
63 #include "ui/base/l10n/l10n_util.h" 62 #include "ui/base/l10n/l10n_util.h"
64 #include "ui/base/l10n/l10n_util_win.h" 63 #include "ui/base/l10n/l10n_util_win.h"
65 #include "ui/base/ui_base_switches.h" 64 #include "ui/base/ui_base_switches.h"
66 #include "ui/base/win/message_box_win.h" 65 #include "ui/base/win/message_box_win.h"
67 #include "ui/gfx/platform_font_win.h" 66 #include "ui/gfx/platform_font_win.h"
68 #include "ui/gfx/switches.h" 67 #include "ui/gfx/switches.h"
69 #include "ui/gfx/win/direct_write.h" 68 #include "ui/gfx/win/direct_write.h"
70 #include "ui/strings/grit/app_locale_settings.h" 69 #include "ui/strings/grit/app_locale_settings.h"
71 70
72 #if defined(GOOGLE_CHROME_BUILD) 71 #if defined(GOOGLE_CHROME_BUILD)
73 #include "chrome/browser/google/did_run_updater_win.h" 72 #include "chrome/browser/google/did_run_updater_win.h"
74 #endif 73 #endif
75 74
76 #if defined(KASKO) 75 #if defined(KASKO)
77 #include "syzygy/kasko/api/reporter.h" 76 #include "syzygy/kasko/api/reporter.h"
78 #endif 77 #endif
79 78
80 namespace { 79 namespace {
81 80
82 typedef HRESULT (STDAPICALLTYPE* RegisterApplicationRestartProc)( 81 typedef HRESULT (STDAPICALLTYPE* RegisterApplicationRestartProc)(
83 const wchar_t* command_line, 82 const wchar_t* command_line,
84 DWORD flags); 83 DWORD flags);
85 84
85 const char kFontCacheSharedSectionName[] = "ChromeDWriteFontCache";
86
86 void InitializeWindowProcExceptions() { 87 void InitializeWindowProcExceptions() {
87 // Get the breakpad pointer from chrome.exe 88 // Get the breakpad pointer from chrome.exe
88 base::win::WinProcExceptionFilter exception_filter = 89 base::win::WinProcExceptionFilter exception_filter =
89 reinterpret_cast<base::win::WinProcExceptionFilter>( 90 reinterpret_cast<base::win::WinProcExceptionFilter>(
90 ::GetProcAddress(::GetModuleHandle( 91 ::GetProcAddress(::GetModuleHandle(
91 chrome::kBrowserProcessExecutableName), 92 chrome::kBrowserProcessExecutableName),
92 "CrashForException")); 93 "CrashForException"));
93 exception_filter = base::win::SetWinProcExceptionFilter(exception_filter); 94 exception_filter = base::win::SetWinProcExceptionFilter(exception_filter);
94 DCHECK(!exception_filter); 95 DCHECK(!exception_filter);
95 } 96 }
96 97
97 // gfx::Font callbacks 98 // gfx::Font callbacks
98 void AdjustUIFont(LOGFONT* logfont) { 99 void AdjustUIFont(LOGFONT* logfont) {
99 l10n_util::AdjustUIFont(logfont); 100 l10n_util::AdjustUIFont(logfont);
100 } 101 }
101 102
102 int GetMinimumFontSize() { 103 int GetMinimumFontSize() {
103 int min_font_size; 104 int min_font_size;
104 base::StringToInt(l10n_util::GetStringUTF16(IDS_MINIMUM_UI_FONT_SIZE), 105 base::StringToInt(l10n_util::GetStringUTF16(IDS_MINIMUM_UI_FONT_SIZE),
105 &min_font_size); 106 &min_font_size);
106 return min_font_size; 107 return min_font_size;
107 } 108 }
108 109
109 class TranslationDelegate : public installer::TranslationDelegate { 110 class TranslationDelegate : public installer::TranslationDelegate {
110 public: 111 public:
111 base::string16 GetLocalizedString(int installer_string_id) override; 112 base::string16 GetLocalizedString(int installer_string_id) override;
112 }; 113 };
113 114
114 void ExecuteFontCacheBuildTask(const base::FilePath& path) {
115 base::WeakPtr<content::UtilityProcessHost> utility_process_host(
116 content::UtilityProcessHost::Create(NULL, NULL)->AsWeakPtr());
117 utility_process_host->SetName(l10n_util::GetStringUTF16(
118 IDS_UTILITY_PROCESS_FONT_CACHE_BUILDER_NAME));
119 utility_process_host->DisableSandbox();
120 utility_process_host->Send(
121 new ChromeUtilityHostMsg_BuildDirectWriteFontCache(path));
122 }
123
124 #if defined(KASKO) 115 #if defined(KASKO)
125 void ObserveFailedCrashReportDirectory(const base::FilePath& path, bool error) { 116 void ObserveFailedCrashReportDirectory(const base::FilePath& path, bool error) {
126 DCHECK(!error); 117 DCHECK(!error);
127 if (error) 118 if (error)
128 return; 119 return;
129 base::FileEnumerator enumerator(path, true, base::FileEnumerator::FILES); 120 base::FileEnumerator enumerator(path, true, base::FileEnumerator::FILES);
130 for (base::FilePath report_file = enumerator.Next(); !report_file.empty(); 121 for (base::FilePath report_file = enumerator.Next(); !report_file.empty();
131 report_file = enumerator.Next()) { 122 report_file = enumerator.Next()) {
132 if (report_file.Extension() == 123 if (report_file.Extension() ==
133 kasko::api::kPermanentFailureMinidumpExtension) { 124 kasko::api::kPermanentFailureMinidumpExtension) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 199
209 // Look for the DLLs used to implement the FTH and other compat hacks. 200 // Look for the DLLs used to implement the FTH and other compat hacks.
210 if (GetModuleHandleW(L"AcLayers.dll") != NULL) 201 if (GetModuleHandleW(L"AcLayers.dll") != NULL)
211 detected = static_cast<FTHFlags>(detected | FTH_ACLAYERS_LOADED); 202 detected = static_cast<FTHFlags>(detected | FTH_ACLAYERS_LOADED);
212 if (GetModuleHandleW(L"AcXtrnal.dll") != NULL) 203 if (GetModuleHandleW(L"AcXtrnal.dll") != NULL)
213 detected = static_cast<FTHFlags>(detected | FTH_ACXTRNAL_LOADED); 204 detected = static_cast<FTHFlags>(detected | FTH_ACXTRNAL_LOADED);
214 205
215 UMA_HISTOGRAM_ENUMERATION("FaultTolerantHeap", detected, FTH_FLAGS_COUNT); 206 UMA_HISTOGRAM_ENUMERATION("FaultTolerantHeap", detected, FTH_FLAGS_COUNT);
216 } 207 }
217 208
209 void DeleteDirectWriteFontCache(base::FilePath path) {
210 // Attempt to delte the font cache and ignore any errors.
fdoray 2015/12/23 13:45:02 *delete
Ilya Kulshin 2015/12/28 22:47:05 Done.
211 ::DeleteFile(path.AsUTF16Unsafe().c_str());
fdoray 2015/12/23 13:45:02 base::DeleteFile? base/files/file_util.h
Ilya Kulshin 2015/12/28 22:47:05 Done.
212 }
213
218 } // namespace 214 } // namespace
219 215
220 void ShowCloseBrowserFirstMessageBox() { 216 void ShowCloseBrowserFirstMessageBox() {
221 int message_id = IDS_UNINSTALL_CLOSE_APP; 217 int message_id = IDS_UNINSTALL_CLOSE_APP;
222 if (base::win::GetVersion() >= base::win::VERSION_WIN8 && 218 if (base::win::GetVersion() >= base::win::VERSION_WIN8 &&
223 (ShellIntegration::GetDefaultBrowser() == ShellIntegration::IS_DEFAULT)) { 219 (ShellIntegration::GetDefaultBrowser() == ShellIntegration::IS_DEFAULT)) {
224 message_id = IDS_UNINSTALL_CLOSE_APP_IMMERSIVE; 220 message_id = IDS_UNINSTALL_CLOSE_APP_IMMERSIVE;
225 } 221 }
226 chrome::ShowMessageBox(NULL, 222 chrome::ShowMessageBox(NULL,
227 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), 223 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME),
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 void ChromeBrowserMainPartsWin::ShowMissingLocaleMessageBox() { 331 void ChromeBrowserMainPartsWin::ShowMissingLocaleMessageBox() {
336 ui::MessageBox(NULL, 332 ui::MessageBox(NULL,
337 base::ASCIIToUTF16(chrome_browser::kMissingLocaleDataMessage), 333 base::ASCIIToUTF16(chrome_browser::kMissingLocaleDataMessage),
338 base::ASCIIToUTF16(chrome_browser::kMissingLocaleDataTitle), 334 base::ASCIIToUTF16(chrome_browser::kMissingLocaleDataTitle),
339 MB_OK | MB_ICONERROR | MB_TOPMOST); 335 MB_OK | MB_ICONERROR | MB_TOPMOST);
340 } 336 }
341 337
342 void ChromeBrowserMainPartsWin::PostProfileInit() { 338 void ChromeBrowserMainPartsWin::PostProfileInit() {
343 ChromeBrowserMainParts::PostProfileInit(); 339 ChromeBrowserMainParts::PostProfileInit();
344 340
345 // DirectWrite support is mainly available Windows 7 and up.
346 if (gfx::win::ShouldUseDirectWrite()) { 341 if (gfx::win::ShouldUseDirectWrite()) {
342 // Clean up the direct write font cache since we no longer use that
343 // codepath.
344 // TODO(kulshin): remove this code after several releases.
fdoray 2015/12/23 13:45:02 I would have been curious to see the impact of thi
347 base::FilePath path( 345 base::FilePath path(
348 profile()->GetPath().AppendASCII(content::kFontCacheSharedSectionName)); 346 profile()->GetPath().AppendASCII(kFontCacheSharedSectionName));
349 // This function will create a read only section if cache file exists 347 const int kBuildFontCacheDelaySec = 30;
350 // otherwise it will spawn utility process to build cache file, which will 348 content::BrowserThread::PostDelayedTask(
351 // be used during next browser start/postprofileinit. 349 content::BrowserThread::IO, FROM_HERE,
fdoray 2015/12/23 13:45:02 content::BrowserThread::FILE is the right thread f
Ilya Kulshin 2015/12/28 22:47:05 Done.
352 if (!content::LoadFontCache(path)) { 350 base::Bind(DeleteDirectWriteFontCache, path),
353 // We delay building of font cache until first startup page loads. 351 base::TimeDelta::FromSeconds(kBuildFontCacheDelaySec));
354 // During first renderer start there are lot of things happening
355 // simultaneously some of them are:
356 // - Renderer is going through all font files on the system to create
357 // a font collection.
358 // - Renderer loading up startup URL, accessing HTML/JS File cache,
359 // net activity etc.
360 // - Extension initialization.
361 // We delay building of cache mainly to avoid parallel font file
362 // loading along with Renderer. Some systems have significant number of
363 // font files which takes long time to process.
364 // Related information is at http://crbug.com/436195.
365 const int kBuildFontCacheDelaySec = 30;
366 content::BrowserThread::PostDelayedTask(
367 content::BrowserThread::IO,
368 FROM_HERE,
369 base::Bind(ExecuteFontCacheBuildTask, path),
370 base::TimeDelta::FromSeconds(kBuildFontCacheDelaySec));
371 }
372 } 352 }
373 } 353 }
374 354
375 void ChromeBrowserMainPartsWin::PostBrowserStart() { 355 void ChromeBrowserMainPartsWin::PostBrowserStart() {
376 ChromeBrowserMainParts::PostBrowserStart(); 356 ChromeBrowserMainParts::PostBrowserStart();
377 357
378 UMA_HISTOGRAM_BOOLEAN("Windows.Tablet", base::win::IsTabletDevice()); 358 UMA_HISTOGRAM_BOOLEAN("Windows.Tablet", base::win::IsTabletDevice());
379 359
380 // Set up a task to verify installed modules in the current process. 360 // Set up a task to verify installed modules in the current process.
381 content::BrowserThread::PostAfterStartupTask( 361 content::BrowserThread::PostAfterStartupTask(
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 if (resource_id) 566 if (resource_id)
587 return l10n_util::GetStringUTF16(resource_id); 567 return l10n_util::GetStringUTF16(resource_id);
588 return base::string16(); 568 return base::string16();
589 } 569 }
590 570
591 // static 571 // static
592 void ChromeBrowserMainPartsWin::SetupInstallerUtilStrings() { 572 void ChromeBrowserMainPartsWin::SetupInstallerUtilStrings() {
593 CR_DEFINE_STATIC_LOCAL(TranslationDelegate, delegate, ()); 573 CR_DEFINE_STATIC_LOCAL(TranslationDelegate, delegate, ());
594 installer::SetTranslationDelegate(&delegate); 574 installer::SetTranslationDelegate(&delegate);
595 } 575 }
OLDNEW
« no previous file with comments | « no previous file | chrome/chrome_utility.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698