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

Side by Side Diff: chrome/browser/browser_main_mac.mm

Issue 2931007: BrowserMain() refactoring, part 2. (Closed)
Patch Set: Updated per brettw and merged ToT. 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_gtk.cc ('k') | chrome/browser/browser_main_posix.h » ('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_posix.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include "app/app_switches.h" 9 #include "app/app_switches.h"
10 #include "app/l10n_util_mac.h" 10 #include "app/l10n_util_mac.h"
11 #include "app/resource_bundle.h" 11 #include "app/resource_bundle.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/debug_util.h" 13 #include "base/debug_util.h"
14 #include "base/file_path.h" 14 #include "base/file_path.h"
15 #include "base/mac_util.h" 15 #include "base/mac_util.h"
16 #include "base/path_service.h" 16 #include "base/path_service.h"
17 #include "base/scoped_nsobject.h" 17 #include "base/scoped_nsobject.h"
18 #include "chrome/app/breakpad_mac.h" 18 #include "chrome/app/breakpad_mac.h"
19 #import "chrome/browser/app_controller_mac.h" 19 #import "chrome/browser/app_controller_mac.h"
20 #include "chrome/browser/browser_main_win.h" 20 #include "chrome/browser/browser_main_win.h"
21 #import "chrome/browser/chrome_browser_application_mac.h" 21 #import "chrome/browser/chrome_browser_application_mac.h"
22 #import "chrome/browser/cocoa/keystone_glue.h" 22 #import "chrome/browser/cocoa/keystone_glue.h"
23 #include "chrome/browser/metrics/metrics_service.h" 23 #include "chrome/browser/metrics/metrics_service.h"
24 #include "chrome/common/chrome_paths.h" 24 #include "chrome/common/chrome_paths.h"
25 #include "chrome/common/main_function_params.h" 25 #include "chrome/common/main_function_params.h"
26 #include "chrome/common/notification_service.h" 26 #include "chrome/common/notification_service.h"
27 #include "chrome/common/result_codes.h" 27 #include "chrome/common/result_codes.h"
28 28
29 // Tell Cooca to finish its initalization, which we want to do manually
30 // instead of calling NSApplicationMain(). The primary reason is that NSAM()
31 // never returns, which would leave all the objects currently on the stack
32 // in scoped_ptrs hanging and never cleaned up. We then load the main nib
33 // directly. The main event loop is run from common code using the
34 // MessageLoop API, which works out ok for us because it's a wrapper around
35 // CFRunLoop.
36 void WillInitializeMainMessageLoop(const MainFunctionParams& parameters) {
37 // Initialize NSApplication using the custom subclass.
38 [BrowserCrApplication sharedApplication];
39
40 // If ui_task is not NULL, the app is actually a browser_test, so startup is
41 // handled outside of BrowserMain (which is what called this).
42 if (!parameters.ui_task) {
43 // The browser process only wants to support the language Cocoa will use, so
44 // force the app locale to be overriden with that value.
45 l10n_util::OverrideLocaleWithCocoaLocale();
46
47 // Before we load the nib, we need to start up the resource bundle so we
48 // have the strings avaiable for localization.
49 std::wstring pref_locale;
50 // TODO(markusheintz): Read preference pref::kApplicationLocale in order to
51 // enforce the application locale.
52 ResourceBundle::InitSharedInstance(pref_locale);
53
54 FilePath resources_pack_path;
55 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
56 ResourceBundle::AddDataPackToSharedInstance(resources_pack_path);
57 }
58
59 // Now load the nib (from the right bundle).
60 scoped_nsobject<NSNib>
61 nib([[NSNib alloc] initWithNibNamed:@"MainMenu"
62 bundle:mac_util::MainAppBundle()]);
63 [nib instantiateNibWithOwner:NSApp topLevelObjects:nil];
64 // Make sure the app controller has been created.
65 DCHECK([NSApp delegate]);
66
67 // This is a no-op if the KeystoneRegistration framework is not present.
68 // The framework is only distributed with branded Google Chrome builds.
69 [[KeystoneGlue defaultKeystoneGlue] registerWithKeystone];
70
71 // Prevent Cocoa from turning command-line arguments into
72 // |-application:openFiles:|, since we already handle them directly.
73 [[NSUserDefaults standardUserDefaults]
74 setObject:@"NO" forKey:@"NSTreatUnknownArgumentsAsOpen"];
75 }
76
77 void DidEndMainMessageLoop() { 29 void DidEndMainMessageLoop() {
78 AppController* appController = [NSApp delegate]; 30 AppController* appController = [NSApp delegate];
79 [appController didEndMainMessageLoop]; 31 [appController didEndMainMessageLoop];
80 } 32 }
81 33
82 void RecordBreakpadStatusUMA(MetricsService* metrics) { 34 void RecordBreakpadStatusUMA(MetricsService* metrics) {
83 metrics->RecordBreakpadRegistration(IsCrashReporterEnabled()); 35 metrics->RecordBreakpadRegistration(IsCrashReporterEnabled());
84 metrics->RecordBreakpadHasDebugger(DebugUtil::BeingDebugged()); 36 metrics->RecordBreakpadHasDebugger(DebugUtil::BeingDebugged());
85 } 37 }
86 38
(...skipping 10 matching lines...) Expand all
97 int HandleIconsCommands(const CommandLine& parsed_command_line) { 49 int HandleIconsCommands(const CommandLine& parsed_command_line) {
98 return 0; 50 return 0;
99 } 51 }
100 52
101 bool CheckMachineLevelInstall() { 53 bool CheckMachineLevelInstall() {
102 return false; 54 return false;
103 } 55 }
104 56
105 void PrepareRestartOnCrashEnviroment(const CommandLine& parsed_command_line) { 57 void PrepareRestartOnCrashEnviroment(const CommandLine& parsed_command_line) {
106 } 58 }
59
60 // BrowserMainPartsMac ---------------------------------------------------------
61
62 class BrowserMainPartsMac : public BrowserMainPartsPosix {
63 public:
64 explicit BrowserMainPartsMac(const MainFunctionParams& parameters)
65 : BrowserMainPartsPosix(parameters) {}
66
67 protected:
68 virtual void PreMainMessageLoopStart() {
69 BrowserMainPartsPosix::PreMainMessageLoopStart();
70
71 // Tell Cooca to finish its initalization, which we want to do manually
72 // instead of calling NSApplicationMain(). The primary reason is that NSAM()
73 // never returns, which would leave all the objects currently on the stack
74 // in scoped_ptrs hanging and never cleaned up. We then load the main nib
75 // directly. The main event loop is run from common code using the
76 // MessageLoop API, which works out ok for us because it's a wrapper around
77 // CFRunLoop.
78
79 // Initialize NSApplication using the custom subclass.
80 [BrowserCrApplication sharedApplication];
81
82 // If ui_task is not NULL, the app is actually a browser_test, so startup is
83 // handled outside of BrowserMain (which is what called this).
84 if (!parameters().ui_task) {
85 // The browser process only wants to support the language Cocoa will use,
86 // so force the app locale to be overriden with that value.
87 l10n_util::OverrideLocaleWithCocoaLocale();
88
89 // Before we load the nib, we need to start up the resource bundle so we
90 // have the strings avaiable for localization.
91 std::wstring pref_locale;
92 // TODO(markusheintz): Read preference pref::kApplicationLocale in order
93 // to enforce the application locale.
94 ResourceBundle::InitSharedInstance(pref_locale);
95
96 FilePath resources_pack_path;
97 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
98 ResourceBundle::AddDataPackToSharedInstance(resources_pack_path);
99 }
100
101 // Now load the nib (from the right bundle).
102 scoped_nsobject<NSNib>
103 nib([[NSNib alloc] initWithNibNamed:@"MainMenu"
104 bundle:mac_util::MainAppBundle()]);
105 [nib instantiateNibWithOwner:NSApp topLevelObjects:nil];
106 // Make sure the app controller has been created.
107 DCHECK([NSApp delegate]);
108
109 // This is a no-op if the KeystoneRegistration framework is not present.
110 // The framework is only distributed with branded Google Chrome builds.
111 [[KeystoneGlue defaultKeystoneGlue] registerWithKeystone];
112
113 // Prevent Cocoa from turning command-line arguments into
114 // |-application:openFiles:|, since we already handle them directly.
115 [[NSUserDefaults standardUserDefaults]
116 setObject:@"NO" forKey:@"NSTreatUnknownArgumentsAsOpen"];
117 }
118 };
119
120 // static
121 BrowserMainParts* BrowserMainParts::CreateBrowserMainParts(
122 const MainFunctionParams& parameters) {
123 return new BrowserMainPartsMac(parameters);
124 }
OLDNEW
« no previous file with comments | « chrome/browser/browser_main_gtk.cc ('k') | chrome/browser/browser_main_posix.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698