browser_main.h revision c407dc5cd9bdc5668497f21b26b09d988ab439de
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 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_BROWSER_MAIN_H_ 6#define CHROME_BROWSER_BROWSER_MAIN_H_ 7 8#include "base/basictypes.h" 9#include "base/field_trial.h" 10#include "base/tracked_objects.h" 11 12class CommandLine; 13struct MainFunctionParams; 14class MetricsService; 15 16// BrowserMainParts: 17// This class contains different "stages" to be executed in |BrowserMain()|, 18// mostly initialization. This is made into a class rather than just functions 19// so each stage can create and maintain state. Each part is represented by a 20// single method (e.g., "EarlyInitialization()"), which does the following: 21// - calls a method (e.g., "PreEarlyInitialization()") which individual 22// platforms can override to provide platform-specific code which is to be 23// executed before the common code; 24// - calls various methods for things common to all platforms (for that given 25// stage); and 26// - calls a method (e.g., "PostEarlyInitialization()") for platform-specific 27// code to be called after the common code. 28// As indicated above, platforms should override the default "Pre...()" and 29// "Post...()" methods when necessary; they need not call the superclass's 30// implementation (which is empty). 31// 32// Parts: 33// - EarlyInitialization: things which should be done as soon as possible on 34// program start (such as setting up signal handlers) and things to be done 35// at some generic time before the start of the main message loop. 36// - (more to come) 37class BrowserMainParts { 38 public: 39 // This static method is to be implemented by each platform and should 40 // instantiate the appropriate subclass. 41 static BrowserMainParts* CreateBrowserMainParts( 42 const MainFunctionParams& parameters); 43 44 // Parts to be called by |BrowserMain()|. 45 void EarlyInitialization(); 46 47 // TODO(viettrungluu): This currently contains (POSIX) initialization done 48 // later than "EarlyInitialization()" but dependent on it. Once the 49 // refactoring includes that later stage, this should be put in some more 50 // generic platform-dependent method. 51 virtual void TemporaryPosix_1() {} 52 53 protected: 54 explicit BrowserMainParts(const MainFunctionParams& parameters); 55 56 // Accessors for data members (below) ---------------------------------------- 57 const MainFunctionParams& parameters() const { 58 return parameters_; 59 } 60 const CommandLine& parsed_command_line() const { 61 return parsed_command_line_; 62 } 63 64 private: 65 // Methods to be overridden to provide platform-specific code; these 66 // correspond to the "parts" above. 67 virtual void PreEarlyInitialization() {} 68 virtual void PostEarlyInitialization() {} 69 70 // Methods for |EarlyInitialization()| --------------------------------------- 71 72 // A/B test for the maximum number of persistent connections per host. 73 void ConnectionFieldTrial(); 74 75 // A/B test for determining a value for unused socket timeout. 76 void SocketTimeoutFieldTrial(); 77 78 // A/B test for spdy when --use-spdy not set. 79 void SpdyFieldTrial(); 80 81 // Used to initialize NSPR where appropriate. 82 void InitializeSSL(); 83 84 // Members initialized on construction --------------------------------------- 85 86 const MainFunctionParams& parameters_; 87 const CommandLine& parsed_command_line_; 88 89#if defined(TRACK_ALL_TASK_OBJECTS) 90 // Creating this object starts tracking the creation and deletion of Task 91 // instance. This MUST be done before main_message_loop, so that it is 92 // destroyed after the main_message_loop. 93 tracked_objects::AutoTracking tracking_objects_; 94#endif 95 96 // Statistical testing infrastructure for the entire browser. 97 FieldTrialList field_trial_; 98 99 DISALLOW_COPY_AND_ASSIGN(BrowserMainParts); 100}; 101 102 103// Perform platform-specific work that needs to be done before the main 104// message loop is created, initialized, and entered. 105void WillInitializeMainMessageLoop(const MainFunctionParams& parameters); 106 107// Perform platform-specific work that needs to be done after the main event 108// loop has ended. 109void DidEndMainMessageLoop(); 110 111// Records the conditions that can prevent Breakpad from generating and 112// sending crash reports. The presence of a Breakpad handler (after 113// attempting to initialize crash reporting) and the presence of a debugger 114// are registered with the UMA metrics service. 115void RecordBreakpadStatusUMA(MetricsService* metrics); 116 117// Displays a warning message if some minimum level of OS support is not 118// present on the current platform. 119void WarnAboutMinimumSystemRequirements(); 120 121#endif // CHROME_BROWSER_BROWSER_MAIN_H_ 122