OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/automation/chrome_frame_automation_provider.h" | 5 #include "chrome/browser/automation/chrome_frame_automation_provider.h" |
| 6 |
| 7 #include <algorithm> |
| 8 |
| 9 #include "base/command_line.h" |
| 10 #include "base/string_number_conversions.h" |
6 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
7 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
8 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
9 #include "chrome/common/automation_messages.h" | 14 #include "chrome/common/automation_messages.h" |
| 15 #include "chrome/common/chrome_switches.h" |
10 #include "ipc/ipc_message.h" | 16 #include "ipc/ipc_message.h" |
11 #include "ipc/ipc_channel.h" | 17 #include "ipc/ipc_channel.h" |
12 | 18 |
| 19 const int kMaxChromeShutdownDelaySeconds = 60*60; |
| 20 |
13 ChromeFrameAutomationProvider::ChromeFrameAutomationProvider(Profile* profile) | 21 ChromeFrameAutomationProvider::ChromeFrameAutomationProvider(Profile* profile) |
14 : AutomationProvider(profile) { | 22 : AutomationProvider(profile) { |
15 DCHECK(g_browser_process); | 23 DCHECK(g_browser_process); |
16 if (g_browser_process) | 24 if (g_browser_process) |
17 g_browser_process->AddRefModule(); | 25 g_browser_process->AddRefModule(); |
18 } | 26 } |
19 | 27 |
20 ChromeFrameAutomationProvider::~ChromeFrameAutomationProvider() { | 28 ChromeFrameAutomationProvider::~ChromeFrameAutomationProvider() { |
21 DCHECK(g_browser_process); | 29 DCHECK(g_browser_process); |
22 if (g_browser_process) | 30 if (g_browser_process) { |
23 g_browser_process->ReleaseModule(); | 31 CommandLine& cmd_line = *CommandLine::ForCurrentProcess(); |
| 32 |
| 33 CommandLine::StringType shutdown_delay( |
| 34 cmd_line.GetSwitchValueNative(switches::kChromeFrameShutdownDelay)); |
| 35 if (!shutdown_delay.empty()) { |
| 36 VLOG(1) << "ChromeFrameAutomationProvider: " |
| 37 "Scheduling ReleaseBrowserProcess."; |
| 38 |
| 39 // Grab the specified shutdown delay. |
| 40 int shutdown_delay_seconds = 0; |
| 41 base::StringToInt(shutdown_delay, &shutdown_delay_seconds); |
| 42 |
| 43 // Clamp to reasonable values. |
| 44 shutdown_delay_seconds = std::max(0, shutdown_delay_seconds); |
| 45 shutdown_delay_seconds = std::min(shutdown_delay_seconds, |
| 46 kMaxChromeShutdownDelaySeconds); |
| 47 |
| 48 // We have Chrome Frame defer Chrome shutdown for a time to improve |
| 49 // intra-page load times. |
| 50 // Note that we are tracking the perf impact of this under |
| 51 // http://crbug.com/98506 |
| 52 MessageLoop::current()->PostDelayedTask( |
| 53 FROM_HERE, |
| 54 base::Bind(&ChromeFrameAutomationProvider::ReleaseBrowserProcess), |
| 55 base::TimeDelta::FromSeconds(shutdown_delay_seconds)); |
| 56 } else { |
| 57 VLOG(1) << "ChromeFrameAutomationProvider: " |
| 58 "Releasing browser module with no delay."; |
| 59 g_browser_process->ReleaseModule(); |
| 60 } |
| 61 } |
24 } | 62 } |
25 | 63 |
26 bool ChromeFrameAutomationProvider::OnMessageReceived( | 64 bool ChromeFrameAutomationProvider::OnMessageReceived( |
27 const IPC::Message& message) { | 65 const IPC::Message& message) { |
28 if (IsValidMessage(message.type())) | 66 if (IsValidMessage(message.type())) |
29 return AutomationProvider::OnMessageReceived(message); | 67 return AutomationProvider::OnMessageReceived(message); |
30 | 68 |
31 OnUnhandledMessage(message); | 69 OnUnhandledMessage(message); |
32 return false; | 70 return false; |
33 } | 71 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 is_valid_message = true; | 117 is_valid_message = true; |
80 break; | 118 break; |
81 } | 119 } |
82 | 120 |
83 default: | 121 default: |
84 break; | 122 break; |
85 } | 123 } |
86 | 124 |
87 return is_valid_message; | 125 return is_valid_message; |
88 } | 126 } |
| 127 |
| 128 // static |
| 129 void ChromeFrameAutomationProvider::ReleaseBrowserProcess() { |
| 130 if (g_browser_process) { |
| 131 VLOG(1) << "ChromeFrameAutomationProvider: " |
| 132 "Releasing browser process."; |
| 133 g_browser_process->ReleaseModule(); |
| 134 } |
| 135 } |
OLD | NEW |