Chromium Code Reviews| 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 "base/command_line.h" | |
| 8 #include "base/string_number_conversions.h" | |
| 6 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 7 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 8 #include "chrome/browser/profiles/profile_manager.h" | 11 #include "chrome/browser/profiles/profile_manager.h" |
| 9 #include "chrome/common/automation_messages.h" | 12 #include "chrome/common/automation_messages.h" |
| 13 #include "chrome/common/chrome_switches.h" | |
| 10 #include "ipc/ipc_message.h" | 14 #include "ipc/ipc_message.h" |
| 11 #include "ipc/ipc_channel.h" | 15 #include "ipc/ipc_channel.h" |
| 12 | 16 |
| 17 const int kMaxChromeShutdownDelaySeconds = 60*60; | |
| 18 | |
| 13 ChromeFrameAutomationProvider::ChromeFrameAutomationProvider(Profile* profile) | 19 ChromeFrameAutomationProvider::ChromeFrameAutomationProvider(Profile* profile) |
| 14 : AutomationProvider(profile) { | 20 : AutomationProvider(profile) { |
| 15 DCHECK(g_browser_process); | 21 DCHECK(g_browser_process); |
| 16 if (g_browser_process) | 22 if (g_browser_process) |
| 17 g_browser_process->AddRefModule(); | 23 g_browser_process->AddRefModule(); |
| 18 } | 24 } |
| 19 | 25 |
| 20 ChromeFrameAutomationProvider::~ChromeFrameAutomationProvider() { | 26 ChromeFrameAutomationProvider::~ChromeFrameAutomationProvider() { |
| 21 DCHECK(g_browser_process); | 27 DCHECK(g_browser_process); |
| 22 if (g_browser_process) | 28 if (g_browser_process) { |
| 23 g_browser_process->ReleaseModule(); | 29 CommandLine& cmd_line = *CommandLine::ForCurrentProcess(); |
| 30 | |
| 31 CommandLine::StringType shutdown_delay( | |
| 32 cmd_line.GetSwitchValueNative(switches::kChromeFrameShutdownDelay)); | |
| 33 if (!shutdown_delay.empty()) { | |
| 34 VLOG(1) << "ChromeFrameAutomationProvider: " | |
|
slightlyoff
2012/03/05 12:35:53
this is going to use streamio which, IIRC, once ha
robertshield
2012/03/05 13:33:25
We use this pattern to log all throughout the code
| |
| 35 "Scheduling ReleaseBrowserProcess."; | |
| 36 | |
| 37 // Grab the specified shutdown delay. | |
| 38 int shutdown_delay_seconds = 0; | |
| 39 base::StringToInt(shutdown_delay, &shutdown_delay_seconds); | |
| 40 | |
| 41 // Clamp to reasonable values. | |
| 42 if (shutdown_delay_seconds < 0) | |
| 43 shutdown_delay_seconds = 0; | |
| 44 else if (shutdown_delay_seconds > kMaxChromeShutdownDelaySeconds) | |
| 45 shutdown_delay_seconds = kMaxChromeShutdownDelaySeconds; | |
|
slightlyoff
2012/03/05 12:35:53
Are there min/max functions somewhere for this?
robertshield
2012/03/05 13:33:25
Done.
| |
| 46 | |
| 47 // We have Chrome Frame defer Chrome shutdown for a time to improve | |
| 48 // intra-page load times. | |
|
slightlyoff
2012/03/05 12:35:53
Add a bug # for tracking perf here?
robertshield
2012/03/05 13:33:25
Good idea, I'll track it under the original bug nu
| |
| 49 MessageLoop::current()->PostDelayedTask( | |
| 50 FROM_HERE, | |
| 51 base::Bind(&ChromeFrameAutomationProvider::ReleaseBrowserProcess), | |
| 52 base::TimeDelta::FromSeconds(shutdown_delay_seconds)); | |
| 53 } else { | |
| 54 VLOG(1) << "ChromeFrameAutomationProvider: " | |
| 55 "Releasing browser module with no delay."; | |
| 56 g_browser_process->ReleaseModule(); | |
| 57 } | |
| 58 } | |
| 24 } | 59 } |
| 25 | 60 |
| 26 bool ChromeFrameAutomationProvider::OnMessageReceived( | 61 bool ChromeFrameAutomationProvider::OnMessageReceived( |
| 27 const IPC::Message& message) { | 62 const IPC::Message& message) { |
| 28 if (IsValidMessage(message.type())) | 63 if (IsValidMessage(message.type())) |
| 29 return AutomationProvider::OnMessageReceived(message); | 64 return AutomationProvider::OnMessageReceived(message); |
| 30 | 65 |
| 31 OnUnhandledMessage(message); | 66 OnUnhandledMessage(message); |
| 32 return false; | 67 return false; |
| 33 } | 68 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 is_valid_message = true; | 114 is_valid_message = true; |
| 80 break; | 115 break; |
| 81 } | 116 } |
| 82 | 117 |
| 83 default: | 118 default: |
| 84 break; | 119 break; |
| 85 } | 120 } |
| 86 | 121 |
| 87 return is_valid_message; | 122 return is_valid_message; |
| 88 } | 123 } |
| 124 | |
| 125 // static | |
| 126 void ChromeFrameAutomationProvider::ReleaseBrowserProcess() { | |
| 127 if (g_browser_process) { | |
| 128 VLOG(1) << "ChromeFrameAutomationProvider: " | |
| 129 "Releasing browser process."; | |
| 130 g_browser_process->ReleaseModule(); | |
| 131 } | |
| 132 } | |
| OLD | NEW |