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

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

Issue 258008: Move initialization of ChromeURLRequestContexts to the IO thread. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync again, just in case Created 11 years, 2 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 | Annotate | Revision Log
OLDNEW
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_profile_impl.h" 5 #include "chrome/browser/automation/automation_profile_impl.h"
6 #include "chrome/browser/net/chrome_url_request_context.h" 6 #include "chrome/browser/net/chrome_url_request_context.h"
7 #include "chrome/test/automation/automation_messages.h" 7 #include "chrome/test/automation/automation_messages.h"
8 8
9 namespace {
10
9 // A special Request context for automation. Substitute a few things 11 // A special Request context for automation. Substitute a few things
10 // like cookie store, proxy settings etc to handle them differently 12 // like cookie store, proxy settings etc to handle them differently
11 // for automation. 13 // for automation.
12 class AutomationURLRequestContext : public ChromeURLRequestContext { 14 class AutomationURLRequestContext : public ChromeURLRequestContext {
13 public: 15 public:
14 AutomationURLRequestContext(URLRequestContext* original_context, 16 AutomationURLRequestContext(ChromeURLRequestContext* original_context,
15 net::CookieStore* automation_cookie_store) 17 net::CookieStore* automation_cookie_store)
16 // All URLRequestContexts in chrome extend from ChromeURLRequestContext 18 : ChromeURLRequestContext(original_context),
17 : ChromeURLRequestContext(static_cast<ChromeURLRequestContext*>( 19 // We must hold a reference to |original_context|, since many
18 original_context)) { 20 // of the dependencies that ChromeURLRequestContext(original_context)
21 // copied are scoped to |original_context|.
22 original_context_(original_context) {
19 cookie_store_ = automation_cookie_store; 23 cookie_store_ = automation_cookie_store;
20 } 24 }
21 25
22 ~AutomationURLRequestContext() { 26 virtual ~AutomationURLRequestContext() {
23 // Clear out members before calling base class dtor since we don't 27 // Clear out members before calling base class dtor since we don't
24 // own any of them. 28 // own any of them.
25 29
26 // Clear URLRequestContext members. 30 // Clear URLRequestContext members.
27 host_resolver_ = NULL; 31 host_resolver_ = NULL;
28 proxy_service_ = NULL; 32 proxy_service_ = NULL;
29 http_transaction_factory_ = NULL; 33 http_transaction_factory_ = NULL;
30 ftp_transaction_factory_ = NULL; 34 ftp_transaction_factory_ = NULL;
31 cookie_store_ = NULL; 35 cookie_store_ = NULL;
32 strict_transport_security_state_ = NULL; 36 strict_transport_security_state_ = NULL;
33 37
34 // Clear ChromeURLRequestContext members. 38 // Clear ChromeURLRequestContext members.
35 prefs_ = NULL;
36 blacklist_ = NULL; 39 blacklist_ = NULL;
37 } 40 }
38 41
39 private: 42 private:
43 scoped_refptr<ChromeURLRequestContext> original_context_;
40 DISALLOW_COPY_AND_ASSIGN(AutomationURLRequestContext); 44 DISALLOW_COPY_AND_ASSIGN(AutomationURLRequestContext);
41 }; 45 };
42 46
43 // CookieStore specialization to have automation specific 47 // CookieStore specialization to have automation specific
44 // behavior for cookies. 48 // behavior for cookies.
45 class AutomationCookieStore : public net::CookieStore { 49 class AutomationCookieStore : public net::CookieStore {
46 public: 50 public:
47 AutomationCookieStore(AutomationProfileImpl* profile, 51 AutomationCookieStore(AutomationProfileImpl* profile,
48 net::CookieStore* original_cookie_store, 52 net::CookieStore* original_cookie_store,
49 IPC::Message::Sender* automation_client) 53 IPC::Message::Sender* automation_client)
50 : profile_(profile), 54 : profile_(profile),
51 original_cookie_store_(original_cookie_store), 55 original_cookie_store_(original_cookie_store),
52 automation_client_(automation_client) { 56 automation_client_(automation_client) {
53 } 57 }
54 58
55 // CookieStore implementation. 59 // CookieStore implementation.
56 virtual bool SetCookie(const GURL& url, const std::string& cookie_line) { 60 virtual bool SetCookie(const GURL& url, const std::string& cookie_line) {
57 bool cookie_set = original_cookie_store_->SetCookie(url, cookie_line); 61 bool cookie_set = original_cookie_store_->SetCookie(url, cookie_line);
58 if (cookie_set) { 62 if (cookie_set) {
63 // TODO(eroman): Should NOT be accessing the profile from here, as this
64 // is running on the IO thread.
59 automation_client_->Send(new AutomationMsg_SetCookieAsync(0, 65 automation_client_->Send(new AutomationMsg_SetCookieAsync(0,
60 profile_->tab_handle(), url, cookie_line)); 66 profile_->tab_handle(), url, cookie_line));
61 } 67 }
62 return cookie_set; 68 return cookie_set;
63 } 69 }
64 virtual bool SetCookieWithOptions(const GURL& url, 70 virtual bool SetCookieWithOptions(const GURL& url,
65 const std::string& cookie_line, 71 const std::string& cookie_line,
66 const net::CookieOptions& options) { 72 const net::CookieOptions& options) {
67 return original_cookie_store_->SetCookieWithOptions(url, cookie_line, 73 return original_cookie_store_->SetCookieWithOptions(url, cookie_line,
68 options); 74 options);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 106
101 protected: 107 protected:
102 AutomationProfileImpl* profile_; 108 AutomationProfileImpl* profile_;
103 net::CookieStore* original_cookie_store_; 109 net::CookieStore* original_cookie_store_;
104 IPC::Message::Sender* automation_client_; 110 IPC::Message::Sender* automation_client_;
105 111
106 private: 112 private:
107 DISALLOW_COPY_AND_ASSIGN(AutomationCookieStore); 113 DISALLOW_COPY_AND_ASSIGN(AutomationCookieStore);
108 }; 114 };
109 115
116 class Factory : public ChromeURLRequestContextFactory {
117 public:
118 Factory(ChromeURLRequestContextGetter* original_context_getter,
119 AutomationProfileImpl* profile,
120 IPC::Message::Sender* automation_client)
121 : ChromeURLRequestContextFactory(profile),
122 original_context_getter_(original_context_getter),
123 profile_(profile),
124 automation_client_(automation_client) {
125 }
126
127 virtual ChromeURLRequestContext* Create() {
128 ChromeURLRequestContext* original_context =
129 original_context_getter_->GetIOContext();
130
131 // Create an automation cookie store.
132 scoped_refptr<net::CookieStore> automation_cookie_store =
133 new AutomationCookieStore(profile_,
134 original_context->cookie_store(),
135 automation_client_);
136
137 return new AutomationURLRequestContext(original_context,
138 automation_cookie_store);
139 }
140
141 private:
142 scoped_refptr<ChromeURLRequestContextGetter> original_context_getter_;
143 AutomationProfileImpl* profile_;
144 IPC::Message::Sender* automation_client_;
145 };
146
147 // TODO(eroman): This duplicates CleanupRequestContext() from profile.cc.
148 void CleanupRequestContext(ChromeURLRequestContextGetter* context) {
149 context->CleanupOnUIThread();
150
151 // Clean up request context on IO thread.
152 g_browser_process->io_thread()->message_loop()->ReleaseSoon(FROM_HERE,
153 context);
154 }
155
156 } // namespace
157
158 AutomationProfileImpl::~AutomationProfileImpl() {
159 CleanupRequestContext(alternate_request_context_);
160 }
161
110 void AutomationProfileImpl::Initialize(Profile* original_profile, 162 void AutomationProfileImpl::Initialize(Profile* original_profile,
111 IPC::Message::Sender* automation_client) { 163 IPC::Message::Sender* automation_client) {
112 DCHECK(original_profile); 164 DCHECK(original_profile);
113 original_profile_ = original_profile; 165 original_profile_ = original_profile;
114 166
115 URLRequestContext* original_context = original_profile_->GetRequestContext(); 167 ChromeURLRequestContextGetter* original_context =
116 scoped_refptr<net::CookieStore> original_cookie_store = 168 static_cast<ChromeURLRequestContextGetter*>(
117 original_context->cookie_store(); 169 original_profile_->GetRequestContext());
118 alternate_cookie_store_ = new AutomationCookieStore(this, 170 alternate_request_context_ = new ChromeURLRequestContextGetter(
119 original_cookie_store, 171 NULL, // Don't register an observer on PrefService.
120 automation_client); 172 new Factory(original_context, this, automation_client));
121 alternate_reqeust_context_ = new AutomationURLRequestContext( 173 alternate_request_context_->AddRef(); // Balananced in the destructor.
122 original_context, alternate_cookie_store_.get());
123 } 174 }
124 175
OLDNEW
« no previous file with comments | « chrome/browser/automation/automation_profile_impl.h ('k') | chrome/browser/automation/automation_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698