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

Side by Side Diff: chrome/browser/extensions/api/identity/gaia_web_auth_flow.cc

Issue 2145103003: Request the Identity API's Uber Token without a Channel ID (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Only cleanup io_helper_ if it was actually created. Created 4 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 | « chrome/browser/extensions/api/identity/gaia_web_auth_flow.h ('k') | no next file » | 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/extensions/api/identity/gaia_web_auth_flow.h" 5 #include "chrome/browser/extensions/api/identity/gaia_web_auth_flow.h"
6 6
7 #include "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/string_split.h" 8 #include "base/strings/string_split.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "base/trace_event/trace_event.h" 11 #include "base/trace_event/trace_event.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/signin/chrome_signin_client_factory.h" 13 #include "chrome/browser/signin/chrome_signin_client_factory.h"
14 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 14 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
15 #include "chrome/browser/signin/signin_manager_factory.h" 15 #include "chrome/browser/signin/signin_manager_factory.h"
16 #include "components/signin/core/browser/profile_oauth2_token_service.h" 16 #include "components/signin/core/browser/profile_oauth2_token_service.h"
17 #include "components/signin/core/browser/signin_manager.h" 17 #include "components/signin/core/browser/signin_manager.h"
18 #include "content/public/browser/browser_thread.h"
18 #include "google_apis/gaia/gaia_constants.h" 19 #include "google_apis/gaia/gaia_constants.h"
19 #include "google_apis/gaia/gaia_urls.h" 20 #include "google_apis/gaia/gaia_urls.h"
20 #include "net/base/escape.h" 21 #include "net/base/escape.h"
22 #include "net/ssl/channel_id_service.h"
23 #include "net/url_request/url_request_context.h"
24 #include "net/url_request/url_request_context_getter.h"
21 25
22 namespace extensions { 26 namespace extensions {
23 27
24 GaiaWebAuthFlow::GaiaWebAuthFlow(Delegate* delegate, 28 GaiaWebAuthFlow::GaiaWebAuthFlow(Delegate* delegate,
25 Profile* profile, 29 Profile* profile,
26 const ExtensionTokenKey* token_key, 30 const ExtensionTokenKey* token_key,
27 const std::string& oauth2_client_id, 31 const std::string& oauth2_client_id,
28 const std::string& locale) 32 const std::string& locale)
29 : delegate_(delegate), 33 : delegate_(delegate),
30 profile_(profile), 34 profile_(profile),
31 account_id_(token_key->account_id) { 35 account_id_(token_key->account_id),
36 weak_ptr_factory_(this) {
32 TRACE_EVENT_ASYNC_BEGIN2("identity", 37 TRACE_EVENT_ASYNC_BEGIN2("identity",
33 "GaiaWebAuthFlow", 38 "GaiaWebAuthFlow",
34 this, 39 this,
35 "extension_id", 40 "extension_id",
36 token_key->extension_id, 41 token_key->extension_id,
37 "account_id", 42 "account_id",
38 token_key->account_id); 43 token_key->account_id);
39 44
40 const char kOAuth2RedirectPathFormat[] = "/%s#"; 45 const char kOAuth2RedirectPathFormat[] = "/%s#";
41 const char kOAuth2AuthorizeFormat[] = 46 const char kOAuth2AuthorizeFormat[] =
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 kOAuth2AuthorizeFormatDeviceIdAddendum, 84 kOAuth2AuthorizeFormatDeviceIdAddendum,
80 net::EscapeUrlEncodedData(signin_scoped_device_id, true).c_str()); 85 net::EscapeUrlEncodedData(signin_scoped_device_id, true).c_str());
81 } 86 }
82 auth_url_ = GaiaUrls::GetInstance()->oauth2_auth_url().Resolve( 87 auth_url_ = GaiaUrls::GetInstance()->oauth2_auth_url().Resolve(
83 oauth2_authorize_params); 88 oauth2_authorize_params);
84 } 89 }
85 90
86 GaiaWebAuthFlow::~GaiaWebAuthFlow() { 91 GaiaWebAuthFlow::~GaiaWebAuthFlow() {
87 TRACE_EVENT_ASYNC_END0("identity", "GaiaWebAuthFlow", this); 92 TRACE_EVENT_ASYNC_END0("identity", "GaiaWebAuthFlow", this);
88 93
94 if (io_helper_) {
95 content::BrowserThread::PostTask(
96 content::BrowserThread::IO,
97 FROM_HERE,
98 base::Bind(&GaiaWebAuthFlow::IOHelper::Cleanup,
99 base::Unretained(io_helper_.release())));
100 }
101
89 if (web_flow_) 102 if (web_flow_)
90 web_flow_.release()->DetachDelegateAndDelete(); 103 web_flow_.release()->DetachDelegateAndDelete();
91 } 104 }
92 105
93 void GaiaWebAuthFlow::Start() { 106 void GaiaWebAuthFlow::Start() {
107 io_helper_.reset(new IOHelper(weak_ptr_factory_.GetWeakPtr(),
108 profile_->GetRequestContext()));
109 content::BrowserThread::PostTask(
110 content::BrowserThread::IO,
111 FROM_HERE,
112 base::Bind(&GaiaWebAuthFlow::IOHelper::PrepareRequestContext,
113 base::Unretained(io_helper_.get())));
114 }
115
116 void GaiaWebAuthFlow::StartUberTokenFetch() {
94 ProfileOAuth2TokenService* token_service = 117 ProfileOAuth2TokenService* token_service =
95 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); 118 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
119 context_getter_ = new net::TrivialURLRequestContextGetter(
120 io_helper_->ubertoken_request_context(),
121 profile_->GetRequestContext()->GetNetworkTaskRunner());
96 ubertoken_fetcher_.reset(new UbertokenFetcher(token_service, 122 ubertoken_fetcher_.reset(new UbertokenFetcher(token_service,
97 this, 123 this,
98 GaiaConstants::kChromeSource, 124 GaiaConstants::kChromeSource,
99 profile_->GetRequestContext())); 125 context_getter_.get()));
100 ubertoken_fetcher_->StartFetchingToken(account_id_); 126 ubertoken_fetcher_->StartFetchingToken(account_id_);
101 } 127 }
102 128
103 void GaiaWebAuthFlow::OnUbertokenSuccess(const std::string& token) { 129 void GaiaWebAuthFlow::OnUbertokenSuccess(const std::string& token) {
104 TRACE_EVENT_ASYNC_STEP_PAST0( 130 TRACE_EVENT_ASYNC_STEP_PAST0(
105 "identity", "GaiaWebAuthFlow", this, "OnUbertokenSuccess"); 131 "identity", "GaiaWebAuthFlow", this, "OnUbertokenSuccess");
106 132
107 const char kMergeSessionQueryFormat[] = "?uberauth=%s&" 133 const char kMergeSessionQueryFormat[] = "?uberauth=%s&"
108 "continue=%s&" 134 "continue=%s&"
109 "source=appsv2"; 135 "source=appsv2";
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 if (url.is_valid()) 255 if (url.is_valid())
230 OnAuthFlowURLChange(url); 256 OnAuthFlowURLChange(url);
231 } 257 }
232 } 258 }
233 259
234 std::unique_ptr<WebAuthFlow> GaiaWebAuthFlow::CreateWebAuthFlow(GURL url) { 260 std::unique_ptr<WebAuthFlow> GaiaWebAuthFlow::CreateWebAuthFlow(GURL url) {
235 return std::unique_ptr<WebAuthFlow>( 261 return std::unique_ptr<WebAuthFlow>(
236 new WebAuthFlow(this, profile_, url, WebAuthFlow::INTERACTIVE)); 262 new WebAuthFlow(this, profile_, url, WebAuthFlow::INTERACTIVE));
237 } 263 }
238 264
265 GaiaWebAuthFlow::IOHelper::IOHelper(
266 base::WeakPtr<GaiaWebAuthFlow> gaia_web_auth_flow,
267 net::URLRequestContextGetter* main_context)
268 : gaia_web_auth_flow_(gaia_web_auth_flow),
269 main_context_(main_context) {}
270
271 GaiaWebAuthFlow::IOHelper::~IOHelper() {}
272
273 void GaiaWebAuthFlow::IOHelper::PrepareRequestContext() {
274 net::URLRequestContext* base_context = main_context_->GetURLRequestContext();
275 // Create a temporary request context for the Uber Token Fetch that doesn't
276 // have a Channel ID. This way, the Uber Token will not be channel bound and
277 // will be useable for the MergeSession call that will take place in the app's
278 // request context.
279 ubertoken_request_context_.reset(new net::URLRequestContext);
280
281 ubertoken_request_context_->CopyFrom(base_context);
282 ubertoken_request_context_->set_channel_id_service(nullptr);
283
284 // Merely setting the Channel ID Service isn't enough, we also have to build a
285 // new HttpNetworkSession.
286 app_backend_ = net::HttpCache::DefaultBackend::InMemory(0);
287 net::HttpNetworkSession::Params network_params =
288 *base_context->GetNetworkSessionParams();
289 network_params.channel_id_service = nullptr;
290 http_network_session_.reset(new net::HttpNetworkSession(network_params));
291 app_http_cache_.reset(new net::HttpCache(
292 http_network_session_.get(), std::move(app_backend_), true));
293
294 ubertoken_request_context_->set_http_transaction_factory(
295 app_http_cache_.get());
296
297 content::BrowserThread::PostTask(
298 content::BrowserThread::UI,
299 FROM_HERE,
300 base::Bind(&GaiaWebAuthFlow::StartUberTokenFetch,
301 gaia_web_auth_flow_));
302 }
303
304 void GaiaWebAuthFlow::IOHelper::Cleanup() {
305 delete this;
306 }
307
239 } // namespace extensions 308 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/identity/gaia_web_auth_flow.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698