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

Side by Side Diff: chrome/app/chrome_exe_main_win.cc

Issue 14617003: Make chrome.exe rendezvous with existing chrome process earlier. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/chrome_process_finder_win.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <windows.h> 5 #include <windows.h>
6 #include <tchar.h> 6 #include <tchar.h>
7 7
8 #include <string>
9
8 #include "base/at_exit.h" 10 #include "base/at_exit.h"
9 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/files/file_path.h"
10 #include "chrome/app/breakpad_win.h" 13 #include "chrome/app/breakpad_win.h"
11 #include "chrome/app/client_util.h" 14 #include "chrome/app/client_util.h"
12 #include "chrome/app/metro_driver_win.h" 15 #include "chrome/app/metro_driver_win.h"
16 #include "chrome/browser/chrome_process_finder_win.h"
17 #include "chrome/browser/policy/policy_path_parser.h"
18 #include "chrome/common/chrome_paths_internal.h"
19 #include "chrome/common/chrome_switches.h"
13 #include "content/public/app/startup_helper_win.h" 20 #include "content/public/app/startup_helper_win.h"
14 #include "content/public/common/result_codes.h" 21 #include "content/public/common/result_codes.h"
15 #include "sandbox/win/src/sandbox_factory.h" 22 #include "sandbox/win/src/sandbox_factory.h"
16 23
24 namespace {
25
17 int RunChrome(HINSTANCE instance) { 26 int RunChrome(HINSTANCE instance) {
18 bool exit_now = true; 27 bool exit_now = true;
19 // We restarted because of a previous crash. Ask user if we should relaunch. 28 // We restarted because of a previous crash. Ask user if we should relaunch.
20 if (ShowRestartDialogIfCrashed(&exit_now)) { 29 if (ShowRestartDialogIfCrashed(&exit_now)) {
21 if (exit_now) 30 if (exit_now)
22 return content::RESULT_CODE_NORMAL_EXIT; 31 return content::RESULT_CODE_NORMAL_EXIT;
23 } 32 }
24 33
25 // Initialize the sandbox services. 34 // Initialize the sandbox services.
26 sandbox::SandboxInterfaceInfo sandbox_info = {0}; 35 sandbox::SandboxInterfaceInfo sandbox_info = {0};
27 content::InitializeSandboxInfo(&sandbox_info); 36 content::InitializeSandboxInfo(&sandbox_info);
28 37
29 // Load and launch the chrome dll. *Everything* happens inside. 38 // Load and launch the chrome dll. *Everything* happens inside.
30 MainDllLoader* loader = MakeMainDllLoader(); 39 MainDllLoader* loader = MakeMainDllLoader();
31 int rc = loader->Launch(instance, &sandbox_info); 40 int rc = loader->Launch(instance, &sandbox_info);
32 loader->RelaunchChromeBrowserWithNewCommandLineIfNeeded(); 41 loader->RelaunchChromeBrowserWithNewCommandLineIfNeeded();
33 delete loader; 42 delete loader;
34 return rc; 43 return rc;
35 } 44 }
36 45
46 // List of switches that it's safe to rendezvous early with. Fast start should
47 // not be done if a command line contains a switch not in this set.
48 // Note this is currently stored as a list of two because it's probably faster
49 // to iterate over this small array than building a map for constant time
50 // lookups.
51 const char* const kFastStartSwitches[] = {
52 switches::kProfileDirectory,
53 switches::kShowAppList,
54 };
55
56 bool IsFastStartSwitch(const std::string& command_line_switch) {
57 for (size_t i = 0; i < arraysize(kFastStartSwitches); ++i) {
58 if (command_line_switch == kFastStartSwitches[i])
59 return true;
60 }
61 return false;
62 }
63
64 bool ContainsNonFastStartFlag(const CommandLine& command_line) {
65 const CommandLine::SwitchMap& switches = command_line.GetSwitches();
66 if (switches.size() > arraysize(kFastStartSwitches))
67 return true;
68 for (CommandLine::SwitchMap::const_iterator it = switches.begin();
69 it != switches.end(); ++it) {
70 if (!IsFastStartSwitch(it->first))
71 return true;
72 }
73 return false;
74 }
75
76 bool AttemptFastNotify(const CommandLine& command_line) {
77 if (ContainsNonFastStartFlag(command_line))
78 return false;
79
80 base::FilePath user_data_dir;
81 if (!chrome::GetDefaultUserDataDirectory(&user_data_dir))
82 return false;
83 policy::path_parser::CheckUserDataDirPolicy(&user_data_dir);
84
85 HWND chrome = chrome::FindRunningChromeWindow(user_data_dir);
86 return chrome &&
87 chrome::AttemptToNotifyRunningChrome(chrome) == chrome::NOTIFY_SUCCESS;
88 }
89
90 } // namespace
91
37 int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev, wchar_t*, int) { 92 int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev, wchar_t*, int) {
38 // Initialize the commandline singleton from the environment. 93 // Initialize the commandline singleton from the environment.
39 CommandLine::Init(0, NULL); 94 CommandLine::Init(0, NULL);
40 // The exit manager is in charge of calling the dtors of singletons. 95 // The exit manager is in charge of calling the dtors of singletons.
41 base::AtExitManager exit_manager; 96 base::AtExitManager exit_manager;
42 97
98 if (AttemptFastNotify(*CommandLine::ForCurrentProcess()))
99 return 0;
100
43 MetroDriver metro_driver; 101 MetroDriver metro_driver;
44 if (metro_driver.in_metro_mode()) 102 if (metro_driver.in_metro_mode())
45 return metro_driver.RunInMetro(instance, &RunChrome); 103 return metro_driver.RunInMetro(instance, &RunChrome);
46 // Not in metro mode, proceed as normal. 104 // Not in metro mode, proceed as normal.
47 return RunChrome(instance); 105 return RunChrome(instance);
48 } 106 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chrome_process_finder_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698