OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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/automation_resource_message_filter.h" | 5 #include "chrome/browser/automation/automation_resource_message_filter.h" |
6 | 6 |
7 #include "base/histogram.h" | 7 #include "base/histogram.h" |
8 #include "base/message_loop.h" | |
9 #include "base/path_service.h" | 8 #include "base/path_service.h" |
10 #include "chrome/browser/automation/url_request_automation_job.h" | 9 #include "chrome/browser/automation/url_request_automation_job.h" |
11 #include "chrome/browser/net/url_request_failed_dns_job.h" | 10 #include "chrome/browser/net/url_request_failed_dns_job.h" |
12 #include "chrome/browser/net/url_request_mock_http_job.h" | 11 #include "chrome/browser/net/url_request_mock_http_job.h" |
13 #include "chrome/browser/net/url_request_mock_util.h" | 12 #include "chrome/browser/net/url_request_mock_util.h" |
14 #include "chrome/browser/net/url_request_slow_download_job.h" | 13 #include "chrome/browser/net/url_request_slow_download_job.h" |
15 #include "chrome/browser/net/url_request_slow_http_job.h" | 14 #include "chrome/browser/net/url_request_slow_http_job.h" |
16 #include "chrome/common/chrome_paths.h" | 15 #include "chrome/common/chrome_paths.h" |
| 16 #include "chrome/browser/chrome_thread.h" |
17 #include "chrome/test/automation/automation_messages.h" | 17 #include "chrome/test/automation/automation_messages.h" |
18 #include "net/url_request/url_request_filter.h" | 18 #include "net/url_request/url_request_filter.h" |
19 | 19 |
20 | 20 |
21 MessageLoop* AutomationResourceMessageFilter::io_loop_ = NULL; | |
22 AutomationResourceMessageFilter::RenderViewMap | 21 AutomationResourceMessageFilter::RenderViewMap |
23 AutomationResourceMessageFilter::filtered_render_views_; | 22 AutomationResourceMessageFilter::filtered_render_views_; |
24 int AutomationResourceMessageFilter::unique_request_id_ = 1; | 23 int AutomationResourceMessageFilter::unique_request_id_ = 1; |
25 | 24 |
26 AutomationResourceMessageFilter::AutomationResourceMessageFilter() | 25 AutomationResourceMessageFilter::AutomationResourceMessageFilter() |
27 : channel_(NULL) { | 26 : channel_(NULL) { |
28 URLRequestAutomationJob::InitializeInterceptor(); | 27 URLRequestAutomationJob::InitializeInterceptor(); |
29 } | 28 } |
30 | 29 |
31 AutomationResourceMessageFilter::~AutomationResourceMessageFilter() { | 30 AutomationResourceMessageFilter::~AutomationResourceMessageFilter() { |
32 } | 31 } |
33 | 32 |
34 // Called on the IPC thread: | 33 // Called on the IPC thread: |
35 void AutomationResourceMessageFilter::OnFilterAdded(IPC::Channel* channel) { | 34 void AutomationResourceMessageFilter::OnFilterAdded(IPC::Channel* channel) { |
36 DCHECK(channel_ == NULL); | 35 DCHECK(channel_ == NULL); |
37 channel_ = channel; | 36 channel_ = channel; |
38 io_loop_ = MessageLoop::current(); | |
39 } | 37 } |
40 | 38 |
41 // Called on the IPC thread: | 39 // Called on the IPC thread: |
42 void AutomationResourceMessageFilter::OnChannelConnected(int32 peer_pid) { | 40 void AutomationResourceMessageFilter::OnChannelConnected(int32 peer_pid) { |
43 } | 41 } |
44 | 42 |
45 // Called on the IPC thread: | 43 // Called on the IPC thread: |
46 void AutomationResourceMessageFilter::OnChannelClosing() { | 44 void AutomationResourceMessageFilter::OnChannelClosing() { |
47 channel_ = NULL; | 45 channel_ = NULL; |
48 request_map_.clear(); | 46 request_map_.clear(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 | 85 |
88 IPC_MESSAGE_UNHANDLED(handled = false) | 86 IPC_MESSAGE_UNHANDLED(handled = false) |
89 IPC_END_MESSAGE_MAP() | 87 IPC_END_MESSAGE_MAP() |
90 | 88 |
91 return handled; | 89 return handled; |
92 } | 90 } |
93 | 91 |
94 // Called on the IPC thread: | 92 // Called on the IPC thread: |
95 bool AutomationResourceMessageFilter::Send(IPC::Message* message) { | 93 bool AutomationResourceMessageFilter::Send(IPC::Message* message) { |
96 // This has to be called on the IO thread. | 94 // This has to be called on the IO thread. |
97 DCHECK_EQ(io_loop_, MessageLoop::current()); | 95 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
98 if (!channel_) { | 96 if (!channel_) { |
99 delete message; | 97 delete message; |
100 return false; | 98 return false; |
101 } | 99 } |
102 | 100 |
103 return channel_->Send(message); | 101 return channel_->Send(message); |
104 } | 102 } |
105 | 103 |
106 bool AutomationResourceMessageFilter::RegisterRequest( | 104 bool AutomationResourceMessageFilter::RegisterRequest( |
107 URLRequestAutomationJob* job) { | 105 URLRequestAutomationJob* job) { |
108 if (!job) { | 106 if (!job) { |
109 NOTREACHED(); | 107 NOTREACHED(); |
110 return false; | 108 return false; |
111 } | 109 } |
112 | 110 |
113 DCHECK_EQ(io_loop_, MessageLoop::current()); | 111 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
114 DCHECK(request_map_.end() == request_map_.find(job->id())); | 112 DCHECK(request_map_.end() == request_map_.find(job->id())); |
115 request_map_[job->id()] = job; | 113 request_map_[job->id()] = job; |
116 return true; | 114 return true; |
117 } | 115 } |
118 | 116 |
119 void AutomationResourceMessageFilter::UnRegisterRequest( | 117 void AutomationResourceMessageFilter::UnRegisterRequest( |
120 URLRequestAutomationJob* job) { | 118 URLRequestAutomationJob* job) { |
121 DCHECK_EQ(io_loop_, MessageLoop::current()); | 119 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
122 DCHECK(request_map_.find(job->id()) != request_map_.end()); | 120 DCHECK(request_map_.find(job->id()) != request_map_.end()); |
123 request_map_.erase(job->id()); | 121 request_map_.erase(job->id()); |
124 } | 122 } |
125 | 123 |
126 bool AutomationResourceMessageFilter::RegisterRenderView( | 124 bool AutomationResourceMessageFilter::RegisterRenderView( |
127 int renderer_pid, int renderer_id, int tab_handle, | 125 int renderer_pid, int renderer_id, int tab_handle, |
128 AutomationResourceMessageFilter* filter) { | 126 AutomationResourceMessageFilter* filter) { |
129 if (!renderer_pid || !renderer_id || !tab_handle) { | 127 if (!renderer_pid || !renderer_id || !tab_handle) { |
130 NOTREACHED(); | 128 NOTREACHED(); |
131 return false; | 129 return false; |
132 } | 130 } |
133 | 131 |
134 DCHECK(io_loop_); | 132 ChromeThread::PostTask( |
135 io_loop_->PostTask(FROM_HERE, NewRunnableFunction( | 133 ChromeThread::IO, FROM_HERE, |
136 AutomationResourceMessageFilter::RegisterRenderViewInIOThread, | 134 NewRunnableFunction( |
137 renderer_pid, renderer_id, tab_handle, filter)); | 135 AutomationResourceMessageFilter::RegisterRenderViewInIOThread, |
| 136 renderer_pid, renderer_id, tab_handle, filter)); |
138 return true; | 137 return true; |
139 } | 138 } |
140 | 139 |
141 void AutomationResourceMessageFilter::UnRegisterRenderView( | 140 void AutomationResourceMessageFilter::UnRegisterRenderView( |
142 int renderer_pid, int renderer_id) { | 141 int renderer_pid, int renderer_id) { |
143 DCHECK(io_loop_); | 142 ChromeThread::PostTask( |
144 io_loop_->PostTask(FROM_HERE, NewRunnableFunction( | 143 ChromeThread::IO, FROM_HERE, |
145 AutomationResourceMessageFilter::UnRegisterRenderViewInIOThread, | 144 NewRunnableFunction( |
146 renderer_pid, renderer_id)); | 145 AutomationResourceMessageFilter::UnRegisterRenderViewInIOThread, |
| 146 renderer_pid, renderer_id)); |
147 } | 147 } |
148 | 148 |
149 void AutomationResourceMessageFilter::RegisterRenderViewInIOThread( | 149 void AutomationResourceMessageFilter::RegisterRenderViewInIOThread( |
150 int renderer_pid, int renderer_id, | 150 int renderer_pid, int renderer_id, |
151 int tab_handle, AutomationResourceMessageFilter* filter) { | 151 int tab_handle, AutomationResourceMessageFilter* filter) { |
152 RenderViewMap::iterator automation_details_iter( | 152 RenderViewMap::iterator automation_details_iter( |
153 filtered_render_views_.find(RendererId(renderer_pid, renderer_id))); | 153 filtered_render_views_.find(RendererId(renderer_pid, renderer_id))); |
154 if (automation_details_iter != filtered_render_views_.end()) { | 154 if (automation_details_iter != filtered_render_views_.end()) { |
155 DCHECK(automation_details_iter->second.ref_count > 0); | 155 DCHECK(automation_details_iter->second.ref_count > 0); |
156 automation_details_iter->second.ref_count++; | 156 automation_details_iter->second.ref_count++; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 *hit_count = URLRequestFilter::GetInstance()->hit_count(); | 200 *hit_count = URLRequestFilter::GetInstance()->hit_count(); |
201 } | 201 } |
202 | 202 |
203 void AutomationResourceMessageFilter::OnRecordHistograms( | 203 void AutomationResourceMessageFilter::OnRecordHistograms( |
204 const std::vector<std::string>& histogram_list) { | 204 const std::vector<std::string>& histogram_list) { |
205 for (size_t index = 0; index < histogram_list.size(); ++index) { | 205 for (size_t index = 0; index < histogram_list.size(); ++index) { |
206 Histogram::DeserializeHistogramInfo(histogram_list[index]); | 206 Histogram::DeserializeHistogramInfo(histogram_list[index]); |
207 } | 207 } |
208 } | 208 } |
209 | 209 |
OLD | NEW |