OLD | NEW |
1 // Copyright (c) 2012 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 "extensions/browser/api/declarative/declarative_api.h" | 5 #include "extensions/browser/api/declarative/declarative_api.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/single_thread_task_runner.h" |
10 #include "base/task_runner_util.h" | 11 #include "base/task_runner_util.h" |
11 #include "base/values.h" | 12 #include "base/values.h" |
12 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
13 #include "content/public/browser/render_process_host.h" | 14 #include "content/public/browser/render_process_host.h" |
14 #include "content/public/browser/render_view_host.h" | 15 #include "content/public/browser/render_view_host.h" |
15 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
16 #include "extensions/browser/api/declarative/rules_registry_service.h" | 17 #include "extensions/browser/api/declarative/rules_registry_service.h" |
17 #include "extensions/browser/api/extensions_api_client.h" | 18 #include "extensions/browser/api/extensions_api_client.h" |
18 #include "extensions/browser/extension_system.h" | 19 #include "extensions/browser/extension_system.h" |
19 #include "extensions/browser/guest_view/web_view/web_view_constants.h" | 20 #include "extensions/browser/guest_view/web_view/web_view_constants.h" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 GetRulesRegistry(rules_registry_id, event_name); | 146 GetRulesRegistry(rules_registry_id, event_name); |
146 DCHECK(rules_registry_.get()); | 147 DCHECK(rules_registry_.get()); |
147 // Raw access to this function is not available to extensions, therefore | 148 // Raw access to this function is not available to extensions, therefore |
148 // there should never be a request for a nonexisting rules registry. | 149 // there should never be a request for a nonexisting rules registry. |
149 EXTENSION_FUNCTION_VALIDATE(rules_registry_.get()); | 150 EXTENSION_FUNCTION_VALIDATE(rules_registry_.get()); |
150 | 151 |
151 if (content::BrowserThread::CurrentlyOn(rules_registry_->owner_thread())) { | 152 if (content::BrowserThread::CurrentlyOn(rules_registry_->owner_thread())) { |
152 bool success = RunAsyncOnCorrectThread(); | 153 bool success = RunAsyncOnCorrectThread(); |
153 SendResponse(success); | 154 SendResponse(success); |
154 } else { | 155 } else { |
155 scoped_refptr<base::MessageLoopProxy> message_loop_proxy = | 156 scoped_refptr<base::SingleThreadTaskRunner> thread_task_runner = |
156 content::BrowserThread::GetMessageLoopProxyForThread( | 157 content::BrowserThread::GetMessageLoopProxyForThread( |
157 rules_registry_->owner_thread()); | 158 rules_registry_->owner_thread()); |
158 base::PostTaskAndReplyWithResult( | 159 base::PostTaskAndReplyWithResult( |
159 message_loop_proxy.get(), | 160 thread_task_runner.get(), FROM_HERE, |
160 FROM_HERE, | |
161 base::Bind(&RulesFunction::RunAsyncOnCorrectThread, this), | 161 base::Bind(&RulesFunction::RunAsyncOnCorrectThread, this), |
162 base::Bind(&RulesFunction::SendResponse, this)); | 162 base::Bind(&RulesFunction::SendResponse, this)); |
163 } | 163 } |
164 | 164 |
165 return true; | 165 return true; |
166 } | 166 } |
167 | 167 |
168 bool EventsEventAddRulesFunction::RunAsyncOnCorrectThread() { | 168 bool EventsEventAddRulesFunction::RunAsyncOnCorrectThread() { |
169 ConvertBinaryListElementsToBase64(args_.get()); | 169 ConvertBinaryListElementsToBase64(args_.get()); |
170 scoped_ptr<AddRules::Params> params(AddRules::Params::Create(*args_)); | 170 scoped_ptr<AddRules::Params> params(AddRules::Params::Create(*args_)); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 } else { | 203 } else { |
204 rules_registry_->GetAllRules(extension_id(), &rules); | 204 rules_registry_->GetAllRules(extension_id(), &rules); |
205 } | 205 } |
206 | 206 |
207 results_ = GetRules::Results::Create(rules); | 207 results_ = GetRules::Results::Create(rules); |
208 | 208 |
209 return true; | 209 return true; |
210 } | 210 } |
211 | 211 |
212 } // namespace extensions | 212 } // namespace extensions |
OLD | NEW |