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/browser_main.cc

Issue 3073008: BrowserMain() refactoring, part 2.1. (Closed)
Patch Set: build fix Created 10 years, 4 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/browser_main.h ('k') | chrome/browser/browser_main_mac.mm » ('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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/browser_main.h" 5 #include "chrome/browser/browser_main.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 #include "chrome/browser/rlz/rlz.h" 114 #include "chrome/browser/rlz/rlz.h"
115 #include "chrome/browser/views/user_data_dir_dialog.h" 115 #include "chrome/browser/views/user_data_dir_dialog.h"
116 #include "chrome/common/env_vars.h" 116 #include "chrome/common/env_vars.h"
117 #include "chrome/common/sandbox_policy.h" 117 #include "chrome/common/sandbox_policy.h"
118 #include "chrome/installer/util/helper.h" 118 #include "chrome/installer/util/helper.h"
119 #include "chrome/installer/util/install_util.h" 119 #include "chrome/installer/util/install_util.h"
120 #include "chrome/installer/util/shell_util.h" 120 #include "chrome/installer/util/shell_util.h"
121 #include "chrome/installer/util/version.h" 121 #include "chrome/installer/util/version.h"
122 #include "net/base/net_util.h" 122 #include "net/base/net_util.h"
123 #include "net/base/sdch_manager.h" 123 #include "net/base/sdch_manager.h"
124 #include "net/socket/ssl_client_socket_nss_factory.h"
125 #include "printing/printed_document.h" 124 #include "printing/printed_document.h"
126 #include "sandbox/src/sandbox.h" 125 #include "sandbox/src/sandbox.h"
127 #endif // defined(OS_WIN) 126 #endif // defined(OS_WIN)
128 127
129 #if defined(OS_MACOSX) 128 #if defined(OS_MACOSX)
130 #include <Security/Security.h> 129 #include <Security/Security.h>
131 #include "chrome/browser/cocoa/install_from_dmg.h" 130 #include "chrome/browser/cocoa/install_from_dmg.h"
132 #include "net/socket/ssl_client_socket_mac_factory.h"
133 #endif
134
135 #if defined(OS_MACOSX) || defined(OS_WIN)
136 #include "base/nss_util.h"
137 #endif 131 #endif
138 132
139 #if defined(TOOLKIT_VIEWS) 133 #if defined(TOOLKIT_VIEWS)
140 #include "chrome/browser/views/chrome_views_delegate.h" 134 #include "chrome/browser/views/chrome_views_delegate.h"
141 #include "views/focus/accelerator_handler.h" 135 #include "views/focus/accelerator_handler.h"
142 #endif 136 #endif
143 137
144 #if defined(OS_CHROMEOS) 138 #if defined(OS_CHROMEOS)
145 #include "chrome/browser/chromeos/cros/cros_library.h" 139 #include "chrome/browser/chromeos/cros/cros_library.h"
146 #include "chrome/browser/chromeos/cros/screen_lock_library.h" 140 #include "chrome/browser/chromeos/cros/screen_lock_library.h"
(...skipping 15 matching lines...) Expand all
162 } 156 }
163 157
164 // BrowserMainParts: |EarlyInitialization()| and related ----------------------- 158 // BrowserMainParts: |EarlyInitialization()| and related -----------------------
165 159
166 void BrowserMainParts::EarlyInitialization() { 160 void BrowserMainParts::EarlyInitialization() {
167 PreEarlyInitialization(); 161 PreEarlyInitialization();
168 162
169 ConnectionFieldTrial(); 163 ConnectionFieldTrial();
170 SocketTimeoutFieldTrial(); 164 SocketTimeoutFieldTrial();
171 SpdyFieldTrial(); 165 SpdyFieldTrial();
172 InitializeSSL(); // TODO(viettrungluu): move to platform-specific method(s) 166 InitializeSSL();
173 167
174 PostEarlyInitialization(); 168 PostEarlyInitialization();
175 } 169 }
176 170
177 // This is an A/B test for the maximum number of persistent connections per 171 // This is an A/B test for the maximum number of persistent connections per
178 // host. Currently Chrome, Firefox, and IE8 have this value set at 6. Safari 172 // host. Currently Chrome, Firefox, and IE8 have this value set at 6. Safari
179 // uses 4, and Fasterfox (a plugin for Firefox that supposedly configures it to 173 // uses 4, and Fasterfox (a plugin for Firefox that supposedly configures it to
180 // run faster) uses 8. We would like to see how much of an effect this value has 174 // run faster) uses 8. We would like to see how much of an effect this value has
181 // on browsing. Too large a value might cause us to run into SYN flood detection 175 // on browsing. Too large a value might cause us to run into SYN flood detection
182 // mechanisms. 176 // mechanisms.
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 net::HttpNetworkLayer::EnableSpdy("npn-http"); 299 net::HttpNetworkLayer::EnableSpdy("npn-http");
306 } else if (trial_grp == npn_spdy_grp) { 300 } else if (trial_grp == npn_spdy_grp) {
307 is_spdy_trial = true; 301 is_spdy_trial = true;
308 net::HttpNetworkLayer::EnableSpdy("npn"); 302 net::HttpNetworkLayer::EnableSpdy("npn");
309 } else { 303 } else {
310 CHECK(!is_spdy_trial); 304 CHECK(!is_spdy_trial);
311 } 305 }
312 } 306 }
313 } 307 }
314 308
315 // TODO(viettrungluu): move to platform-specific methods
316 void BrowserMainParts::InitializeSSL() {
317 // Use NSS for SSL by default.
318 #if defined(OS_MACOSX)
319 // The default client socket factory uses NSS for SSL by default on Mac.
320 if (parsed_command_line().HasSwitch(switches::kUseSystemSSL)) {
321 net::ClientSocketFactory::SetSSLClientSocketFactory(
322 net::SSLClientSocketMacFactory);
323 } else {
324 // We want to be sure to init NSPR on the main thread.
325 base::EnsureNSPRInit();
326 }
327 #elif defined(OS_WIN)
328 // Because of a build system issue (http://crbug.com/43461), the default
329 // client socket factory uses SChannel (the system SSL library) for SSL by
330 // default on Windows.
331 if (!parsed_command_line().HasSwitch(switches::kUseSystemSSL)) {
332 net::ClientSocketFactory::SetSSLClientSocketFactory(
333 net::SSLClientSocketNSSFactory);
334 // We want to be sure to init NSPR on the main thread.
335 base::EnsureNSPRInit();
336 }
337 #endif
338 }
339
340 // BrowserMainParts: |MainMessageLoopStart()| and related ---------------------- 309 // BrowserMainParts: |MainMessageLoopStart()| and related ----------------------
341 310
342 void BrowserMainParts::MainMessageLoopStart() { 311 void BrowserMainParts::MainMessageLoopStart() {
343 PreMainMessageLoopStart(); 312 PreMainMessageLoopStart();
344 313
345 main_message_loop_.reset(new MessageLoop(MessageLoop::TYPE_UI)); 314 main_message_loop_.reset(new MessageLoop(MessageLoop::TYPE_UI));
346 315
347 // TODO(viettrungluu): should these really go before setting the thread name? 316 // TODO(viettrungluu): should these really go before setting the thread name?
348 system_monitor_.reset(new SystemMonitor); 317 system_monitor_.reset(new SystemMonitor);
349 hi_res_timer_manager_.reset(new HighResolutionTimerManager); 318 hi_res_timer_manager_.reset(new HighResolutionTimerManager);
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 scoped_ptr<BrowserMainParts> 685 scoped_ptr<BrowserMainParts>
717 parts(BrowserMainParts::CreateBrowserMainParts(parameters)); 686 parts(BrowserMainParts::CreateBrowserMainParts(parameters));
718 687
719 parts->EarlyInitialization(); 688 parts->EarlyInitialization();
720 parts->MainMessageLoopStart(); 689 parts->MainMessageLoopStart();
721 690
722 // WARNING: If we get a WM_ENDSESSION, objects created on the stack here 691 // WARNING: If we get a WM_ENDSESSION, objects created on the stack here
723 // are NOT deleted. If you need something to run during WM_ENDSESSION add it 692 // are NOT deleted. If you need something to run during WM_ENDSESSION add it
724 // to browser_shutdown::Shutdown or BrowserProcess::EndSession. 693 // to browser_shutdown::Shutdown or BrowserProcess::EndSession.
725 694
726 // TODO(beng, brettw): someday, break this out into sub functions with well 695 // !!!!!!!!!! READ ME !!!!!!!!!!
727 // defined roles (e.g. pre/post-profile startup, etc). 696 // I (viettrungluu) am in the process of refactoring |BrowserMain()|. If you
697 // need to add something above this comment, read the documentation in
698 // browser_main.h. If you need to add something below, please do the
699 // following:
700 // - Figure out where you should add your code. Do NOT just pick a random
701 // location "which works".
702 // - Document the dependencies apart from compile-time-checkable ones. What
703 // must happen before your new code is executed? Does your new code need to
704 // run before something else? Are there performance reasons for executing
705 // your code at that point?
706 // - If you need to create a (persistent) object, heap allocate it and keep a
707 // |scoped_ptr| to it rather than allocating it on the stack. Otherwise
708 // I'll have to convert your code when I refactor.
709 // - Unless your new code is just a couple of lines, factor it out into a
710 // function with a well-defined purpose. Do NOT just add it inline in
711 // |BrowserMain()|.
712 // Thanks!
728 713
729 // TODO(viettrungluu): put the remainder into BrowserMainParts 714 // TODO(viettrungluu): put the remainder into BrowserMainParts
730 const CommandLine& parsed_command_line = parameters.command_line_; 715 const CommandLine& parsed_command_line = parameters.command_line_;
731 base::ScopedNSAutoreleasePool* pool = parameters.autorelease_pool_; 716 base::ScopedNSAutoreleasePool* pool = parameters.autorelease_pool_;
732 717
733 FilePath user_data_dir; 718 FilePath user_data_dir;
734 #if defined(OS_WIN) 719 #if defined(OS_WIN)
735 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); 720 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
736 #else 721 #else
737 // Getting the user data dir can fail if the directory isn't 722 // Getting the user data dir can fail if the directory isn't
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 1265
1281 metrics->Stop(); 1266 metrics->Stop();
1282 1267
1283 // browser_shutdown takes care of deleting browser_process, so we need to 1268 // browser_shutdown takes care of deleting browser_process, so we need to
1284 // release it. 1269 // release it.
1285 ignore_result(browser_process.release()); 1270 ignore_result(browser_process.release());
1286 browser_shutdown::Shutdown(); 1271 browser_shutdown::Shutdown();
1287 1272
1288 return result_code; 1273 return result_code;
1289 } 1274 }
OLDNEW
« no previous file with comments | « chrome/browser/browser_main.h ('k') | chrome/browser/browser_main_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698