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

Unified 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, 5 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/browser_main_mac.mm
diff --git a/chrome/browser/browser_main_mac.mm b/chrome/browser/browser_main_mac.mm
index 34cca50a4f4d18fd4df96cc7c2d95fac8b7cb981..0fd8fb9dec2af4d71105edfa03f4e9992d98fa65 100644
--- a/chrome/browser/browser_main_mac.mm
+++ b/chrome/browser/browser_main_mac.mm
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/browser_main.h"
+#include "chrome/browser/browser_main_posix.h"
#import <Cocoa/Cocoa.h>
@@ -26,54 +26,6 @@
#include "chrome/common/notification_service.h"
#include "chrome/common/result_codes.h"
-// Tell Cooca to finish its initalization, which we want to do manually
-// instead of calling NSApplicationMain(). The primary reason is that NSAM()
-// never returns, which would leave all the objects currently on the stack
-// in scoped_ptrs hanging and never cleaned up. We then load the main nib
-// directly. The main event loop is run from common code using the
-// MessageLoop API, which works out ok for us because it's a wrapper around
-// CFRunLoop.
-void WillInitializeMainMessageLoop(const MainFunctionParams& parameters) {
- // Initialize NSApplication using the custom subclass.
- [BrowserCrApplication sharedApplication];
-
- // If ui_task is not NULL, the app is actually a browser_test, so startup is
- // handled outside of BrowserMain (which is what called this).
- if (!parameters.ui_task) {
- // The browser process only wants to support the language Cocoa will use, so
- // force the app locale to be overriden with that value.
- l10n_util::OverrideLocaleWithCocoaLocale();
-
- // Before we load the nib, we need to start up the resource bundle so we
- // have the strings avaiable for localization.
- std::wstring pref_locale;
- // TODO(markusheintz): Read preference pref::kApplicationLocale in order to
- // enforce the application locale.
- ResourceBundle::InitSharedInstance(pref_locale);
-
- FilePath resources_pack_path;
- PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
- ResourceBundle::AddDataPackToSharedInstance(resources_pack_path);
- }
-
- // Now load the nib (from the right bundle).
- scoped_nsobject<NSNib>
- nib([[NSNib alloc] initWithNibNamed:@"MainMenu"
- bundle:mac_util::MainAppBundle()]);
- [nib instantiateNibWithOwner:NSApp topLevelObjects:nil];
- // Make sure the app controller has been created.
- DCHECK([NSApp delegate]);
-
- // This is a no-op if the KeystoneRegistration framework is not present.
- // The framework is only distributed with branded Google Chrome builds.
- [[KeystoneGlue defaultKeystoneGlue] registerWithKeystone];
-
- // Prevent Cocoa from turning command-line arguments into
- // |-application:openFiles:|, since we already handle them directly.
- [[NSUserDefaults standardUserDefaults]
- setObject:@"NO" forKey:@"NSTreatUnknownArgumentsAsOpen"];
-}
-
void DidEndMainMessageLoop() {
AppController* appController = [NSApp delegate];
[appController didEndMainMessageLoop];
@@ -104,3 +56,69 @@ bool CheckMachineLevelInstall() {
void PrepareRestartOnCrashEnviroment(const CommandLine& parsed_command_line) {
}
+
+// BrowserMainPartsMac ---------------------------------------------------------
+
+class BrowserMainPartsMac : public BrowserMainPartsPosix {
+ public:
+ explicit BrowserMainPartsMac(const MainFunctionParams& parameters)
+ : BrowserMainPartsPosix(parameters) {}
+
+ protected:
+ virtual void PreMainMessageLoopStart() {
+ BrowserMainPartsPosix::PreMainMessageLoopStart();
+
+ // Tell Cooca to finish its initalization, which we want to do manually
+ // instead of calling NSApplicationMain(). The primary reason is that NSAM()
+ // never returns, which would leave all the objects currently on the stack
+ // in scoped_ptrs hanging and never cleaned up. We then load the main nib
+ // directly. The main event loop is run from common code using the
+ // MessageLoop API, which works out ok for us because it's a wrapper around
+ // CFRunLoop.
+
+ // Initialize NSApplication using the custom subclass.
+ [BrowserCrApplication sharedApplication];
+
+ // If ui_task is not NULL, the app is actually a browser_test, so startup is
+ // handled outside of BrowserMain (which is what called this).
+ if (!parameters().ui_task) {
+ // The browser process only wants to support the language Cocoa will use,
+ // so force the app locale to be overriden with that value.
+ l10n_util::OverrideLocaleWithCocoaLocale();
+
+ // Before we load the nib, we need to start up the resource bundle so we
+ // have the strings avaiable for localization.
+ std::wstring pref_locale;
+ // TODO(markusheintz): Read preference pref::kApplicationLocale in order
+ // to enforce the application locale.
+ ResourceBundle::InitSharedInstance(pref_locale);
+
+ FilePath resources_pack_path;
+ PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
+ ResourceBundle::AddDataPackToSharedInstance(resources_pack_path);
+ }
+
+ // Now load the nib (from the right bundle).
+ scoped_nsobject<NSNib>
+ nib([[NSNib alloc] initWithNibNamed:@"MainMenu"
+ bundle:mac_util::MainAppBundle()]);
+ [nib instantiateNibWithOwner:NSApp topLevelObjects:nil];
+ // Make sure the app controller has been created.
+ DCHECK([NSApp delegate]);
+
+ // This is a no-op if the KeystoneRegistration framework is not present.
+ // The framework is only distributed with branded Google Chrome builds.
+ [[KeystoneGlue defaultKeystoneGlue] registerWithKeystone];
+
+ // Prevent Cocoa from turning command-line arguments into
+ // |-application:openFiles:|, since we already handle them directly.
+ [[NSUserDefaults standardUserDefaults]
+ setObject:@"NO" forKey:@"NSTreatUnknownArgumentsAsOpen"];
+ }
+};
+
+// static
+BrowserMainParts* BrowserMainParts::CreateBrowserMainParts(
+ const MainFunctionParams& parameters) {
+ return new BrowserMainPartsMac(parameters);
+}
« 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