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

Side by Side Diff: chrome/browser/automation/automation_provider.cc

Issue 2845031: Reland r50296 which removes some uses of CookieMonster on the UI thread. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Get rid of spurious whitespace. Created 10 years, 5 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
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_cookies_api.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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_provider.h" 5 #include "chrome/browser/automation/automation_provider.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "app/message_box_flags.h" 10 #include "app/message_box_flags.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/file_path.h" 12 #include "base/file_path.h"
13 #include "base/file_version_info.h" 13 #include "base/file_version_info.h"
14 #include "base/json/json_reader.h" 14 #include "base/json/json_reader.h"
15 #include "base/json/json_writer.h" 15 #include "base/json/json_writer.h"
16 #include "base/keyboard_codes.h" 16 #include "base/keyboard_codes.h"
17 #include "base/message_loop.h" 17 #include "base/message_loop.h"
18 #include "base/path_service.h" 18 #include "base/path_service.h"
19 #include "base/process_util.h" 19 #include "base/process_util.h"
20 #include "base/stl_util-inl.h" 20 #include "base/stl_util-inl.h"
21 #include "base/string_util.h" 21 #include "base/string_util.h"
22 #include "base/task.h"
22 #include "base/thread.h" 23 #include "base/thread.h"
23 #include "base/utf_string_conversions.h" 24 #include "base/utf_string_conversions.h"
24 #include "base/values.h" 25 #include "base/values.h"
26 #include "base/waitable_event.h"
25 #include "chrome/app/chrome_dll_resource.h" 27 #include "chrome/app/chrome_dll_resource.h"
26 #include "chrome/app/chrome_version_info.h" 28 #include "chrome/app/chrome_version_info.h"
27 #include "chrome/browser/app_modal_dialog.h" 29 #include "chrome/browser/app_modal_dialog.h"
28 #include "chrome/browser/app_modal_dialog_queue.h" 30 #include "chrome/browser/app_modal_dialog_queue.h"
29 #include "chrome/browser/automation/automation_extension_tracker.h" 31 #include "chrome/browser/automation/automation_extension_tracker.h"
30 #include "chrome/browser/automation/automation_provider_list.h" 32 #include "chrome/browser/automation/automation_provider_list.h"
31 #include "chrome/browser/automation/automation_provider_observers.h" 33 #include "chrome/browser/automation/automation_provider_observers.h"
32 #include "chrome/browser/automation/extension_port_container.h" 34 #include "chrome/browser/automation/extension_port_container.h"
33 #include "chrome/browser/blocked_popup_container.h" 35 #include "chrome/browser/blocked_popup_container.h"
34 #include "chrome/browser/bookmarks/bookmark_model.h" 36 #include "chrome/browser/bookmarks/bookmark_model.h"
(...skipping 1076 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 Browser* AutomationProvider::FindAndActivateTab( 1113 Browser* AutomationProvider::FindAndActivateTab(
1112 NavigationController* controller) { 1114 NavigationController* controller) {
1113 int tab_index; 1115 int tab_index;
1114 Browser* browser = Browser::GetBrowserForController(controller, &tab_index); 1116 Browser* browser = Browser::GetBrowserForController(controller, &tab_index);
1115 if (browser) 1117 if (browser)
1116 browser->SelectTabContentsAt(tab_index, true); 1118 browser->SelectTabContentsAt(tab_index, true);
1117 1119
1118 return browser; 1120 return browser;
1119 } 1121 }
1120 1122
1123 namespace {
1124
1125 class GetCookiesTask : public Task {
1126 public:
1127 GetCookiesTask(const GURL& url,
1128 URLRequestContextGetter* context_getter,
1129 base::WaitableEvent* event,
1130 std::string* cookies)
1131 : url_(url),
1132 context_getter_(context_getter),
1133 event_(event),
1134 cookies_(cookies) {}
1135
1136 virtual void Run() {
1137 *cookies_ = context_getter_->GetCookieStore()->GetCookies(url_);
1138 event_->Signal();
1139 }
1140
1141 private:
1142 const GURL& url_;
1143 URLRequestContextGetter* const context_getter_;
1144 base::WaitableEvent* const event_;
1145 std::string* const cookies_;
1146
1147 DISALLOW_COPY_AND_ASSIGN(GetCookiesTask);
1148 };
1149
1150 std::string GetCookiesForURL(
1151 const GURL& url,
1152 URLRequestContextGetter* context_getter) {
1153 std::string cookies;
1154 base::WaitableEvent event(true /* manual reset */,
1155 false /* not initially signaled */);
1156 CHECK(ChromeThread::PostTask(
1157 ChromeThread::IO, FROM_HERE,
1158 new GetCookiesTask(url, context_getter, &event, &cookies)));
1159 event.Wait();
1160 return cookies;
1161 }
1162
1163 class SetCookieTask : public Task {
1164 public:
1165 SetCookieTask(const GURL& url,
1166 const std::string& value,
1167 URLRequestContextGetter* context_getter,
1168 base::WaitableEvent* event,
1169 bool* rv)
1170 : url_(url),
1171 value_(value),
1172 context_getter_(context_getter),
1173 event_(event),
1174 rv_(rv) {}
1175
1176 virtual void Run() {
1177 *rv_ = context_getter_->GetCookieStore()->SetCookie(url_, value_);
1178 event_->Signal();
1179 }
1180
1181 private:
1182 const GURL& url_;
1183 const std::string& value_;
1184 URLRequestContextGetter* const context_getter_;
1185 base::WaitableEvent* const event_;
1186 bool* const rv_;
1187
1188 DISALLOW_COPY_AND_ASSIGN(SetCookieTask);
1189 };
1190
1191 bool SetCookieForURL(
1192 const GURL& url,
1193 const std::string& value,
1194 URLRequestContextGetter* context_getter) {
1195 base::WaitableEvent event(true /* manual reset */,
1196 false /* not initially signaled */);
1197 bool rv = false;
1198 CHECK(ChromeThread::PostTask(
1199 ChromeThread::IO, FROM_HERE,
1200 new SetCookieTask(url, value, context_getter, &event, &rv)));
1201 event.Wait();
1202 return rv;
1203 }
1204
1205 class DeleteCookieTask : public Task {
1206 public:
1207 DeleteCookieTask(const GURL& url,
1208 const std::string& name,
1209 const scoped_refptr<URLRequestContextGetter>& context_getter)
1210 : url_(url),
1211 name_(name),
1212 context_getter_(context_getter) {}
1213
1214 virtual void Run() {
1215 net::CookieStore* cookie_store = context_getter_->GetCookieStore();
1216 cookie_store->DeleteCookie(url_, name_);
1217 }
1218
1219 private:
1220 const GURL url_;
1221 const std::string name_;
1222 const scoped_refptr<URLRequestContextGetter> context_getter_;
1223
1224 DISALLOW_COPY_AND_ASSIGN(DeleteCookieTask);
1225 };
1226
1227 } // namespace
1228
1121 void AutomationProvider::GetCookies(const GURL& url, int handle, 1229 void AutomationProvider::GetCookies(const GURL& url, int handle,
1122 int* value_size, 1230 int* value_size,
1123 std::string* value) { 1231 std::string* value) {
1124 *value_size = -1; 1232 *value_size = -1;
1125 if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) { 1233 if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) {
1126 NavigationController* tab = tab_tracker_->GetResource(handle); 1234 NavigationController* tab = tab_tracker_->GetResource(handle);
1127 1235
1128 // Since we are running on the UI thread don't call GetURLRequestContext(). 1236 // Since we are running on the UI thread don't call GetURLRequestContext().
1129 scoped_refptr<URLRequestContextGetter> request_context = 1237 scoped_refptr<URLRequestContextGetter> request_context =
1130 tab->tab_contents()->request_context(); 1238 tab->tab_contents()->request_context();
1131 if (!request_context.get()) 1239 if (!request_context.get())
1132 request_context = tab->profile()->GetRequestContext(); 1240 request_context = tab->profile()->GetRequestContext();
1133 1241
1134 net::CookieStore* cookie_store = request_context->GetCookieStore(); 1242 *value = GetCookiesForURL(url, request_context.get());
1135
1136 *value = cookie_store->GetCookies(url);
1137 *value_size = static_cast<int>(value->size()); 1243 *value_size = static_cast<int>(value->size());
1138 } 1244 }
1139 } 1245 }
1140 1246
1141 void AutomationProvider::SetCookie(const GURL& url, 1247 void AutomationProvider::SetCookie(const GURL& url,
1142 const std::string value, 1248 const std::string value,
1143 int handle, 1249 int handle,
1144 int* response_value) { 1250 int* response_value) {
1145 *response_value = -1; 1251 *response_value = -1;
1146 1252
1147 if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) { 1253 if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) {
1148 NavigationController* tab = tab_tracker_->GetResource(handle); 1254 NavigationController* tab = tab_tracker_->GetResource(handle);
1149 1255
1150 scoped_refptr<URLRequestContextGetter> request_context = 1256 scoped_refptr<URLRequestContextGetter> request_context =
1151 tab->tab_contents()->request_context(); 1257 tab->tab_contents()->request_context();
1152 if (!request_context.get()) 1258 if (!request_context.get())
1153 request_context = tab->profile()->GetRequestContext(); 1259 request_context = tab->profile()->GetRequestContext();
1154 1260
1155 // Since we are running on the UI thread don't call GetURLRequestContext(). 1261 if (SetCookieForURL(url, value, request_context.get()))
1156 scoped_refptr<net::CookieStore> cookie_store =
1157 request_context->GetCookieStore();
1158
1159 if (cookie_store->SetCookie(url, value))
1160 *response_value = 1; 1262 *response_value = 1;
1161 } 1263 }
1162 } 1264 }
1163 1265
1164 void AutomationProvider::DeleteCookie(const GURL& url, 1266 void AutomationProvider::DeleteCookie(const GURL& url,
1165 const std::string& cookie_name, 1267 const std::string& cookie_name,
1166 int handle, bool* success) { 1268 int handle, bool* success) {
1167 *success = false; 1269 *success = false;
1168 if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) { 1270 if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) {
1169 NavigationController* tab = tab_tracker_->GetResource(handle); 1271 NavigationController* tab = tab_tracker_->GetResource(handle);
1170 net::CookieStore* cookie_store = 1272 ChromeThread::PostTask(
1171 tab->profile()->GetRequestContext()->GetCookieStore(); 1273 ChromeThread::IO, FROM_HERE,
1172 cookie_store->DeleteCookie(url, cookie_name); 1274 new DeleteCookieTask(url, cookie_name,
1275 tab->profile()->GetRequestContext()));
1173 *success = true; 1276 *success = true;
1174 } 1277 }
1175 } 1278 }
1176 1279
1177 void AutomationProvider::GetTabURL(int handle, bool* success, GURL* url) { 1280 void AutomationProvider::GetTabURL(int handle, bool* success, GURL* url) {
1178 *success = false; 1281 *success = false;
1179 if (tab_tracker_->ContainsHandle(handle)) { 1282 if (tab_tracker_->ContainsHandle(handle)) {
1180 NavigationController* tab = tab_tracker_->GetResource(handle); 1283 NavigationController* tab = tab_tracker_->GetResource(handle);
1181 // Return what the user would see in the location bar. 1284 // Return what the user would see in the location bar.
1182 *url = tab->GetActiveEntry()->virtual_url(); 1285 *url = tab->GetActiveEntry()->virtual_url();
(...skipping 2326 matching lines...) Expand 10 before | Expand all | Expand 10 after
3509 } 3612 }
3510 3613
3511 void AutomationProvider::WaitForPopupMenuToOpen(IPC::Message* reply_message) { 3614 void AutomationProvider::WaitForPopupMenuToOpen(IPC::Message* reply_message) {
3512 NOTIMPLEMENTED(); 3615 NOTIMPLEMENTED();
3513 } 3616 }
3514 #endif // !defined(TOOLKIT_VIEWS) 3617 #endif // !defined(TOOLKIT_VIEWS)
3515 3618
3516 void AutomationProvider::ResetToDefaultTheme() { 3619 void AutomationProvider::ResetToDefaultTheme() {
3517 profile_->ClearTheme(); 3620 profile_->ClearTheme();
3518 } 3621 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_cookies_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698