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

Side by Side Diff: remoting/host/gaia_user_email_fetcher.cc

Issue 11273024: Remove GaiaOauthClient and GaiaUserEmailFetcher from remoting. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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
« no previous file with comments | « remoting/host/gaia_user_email_fetcher.h ('k') | remoting/host/remoting_me2me_host.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "remoting/host/gaia_user_email_fetcher.h"
6
7 #include "base/json/json_reader.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/values.h"
10 #include "googleurl/src/gurl.h"
11 #include "net/http/http_status_code.h"
12 #include "net/url_request/url_fetcher.h"
13 #include "net/url_request/url_fetcher_delegate.h"
14 #include "net/url_request/url_request_context_getter.h"
15
16 namespace {
17 const char kOAuth2UserInfoUrl[] =
18 "https://www.googleapis.com/oauth2/v1/userinfo";
19 } // namespace
20
21 namespace remoting {
22
23 class GaiaUserEmailFetcher::Core
24 : public base::RefCountedThreadSafe<GaiaUserEmailFetcher::Core>,
25 public net::URLFetcherDelegate {
26 public:
27 Core(net::URLRequestContextGetter* request_context_getter)
28 : request_context_getter_(request_context_getter),
29 delegate_(NULL) {
30 }
31
32 void GetUserEmail(const std::string& oauth_access_token, Delegate* delegate);
33
34 // net::URLFetcherDelegate interface
35 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
36
37 private:
38 friend class base::RefCountedThreadSafe<Core>;
39
40 virtual ~Core() {}
41
42 void FetchUserInfoAndInvokeCallback();
43 void OnUserInfoFetchComplete(const net::URLRequestStatus& status,
44 int response_code,
45 const std::string& response);
46
47 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
48 GaiaUserEmailFetcher::Delegate* delegate_;
49 scoped_ptr<net::URLFetcher> request_;
50 };
51
52 void GaiaUserEmailFetcher::Core::GetUserEmail(
53 const std::string& oauth_access_token, Delegate* delegate) {
54 DCHECK(!request_.get()) << "Tried to fetch two things at once!";
55
56 delegate_ = delegate;
57
58 request_.reset(net::URLFetcher::Create(
59 GURL(kOAuth2UserInfoUrl), net::URLFetcher::GET, this));
60 request_->SetRequestContext(request_context_getter_);
61 request_->AddExtraRequestHeader(
62 "Authorization: OAuth " + oauth_access_token);
63 request_->Start();
64 }
65
66 void GaiaUserEmailFetcher::Core::OnURLFetchComplete(
67 const net::URLFetcher* source) {
68 std::string response_string;
69 source->GetResponseAsString(&response_string);
70 OnUserInfoFetchComplete(source->GetStatus(),
71 source->GetResponseCode(),
72 response_string);
73 }
74
75 void GaiaUserEmailFetcher::Core::OnUserInfoFetchComplete(
76 const net::URLRequestStatus& status,
77 int response_code,
78 const std::string& response) {
79 request_.reset();
80 std::string email;
81 if (response_code == net::HTTP_OK) {
82 scoped_ptr<Value> response_value(base::JSONReader::Read(response));
83 if (response_value.get()) {
84 base::DictionaryValue* response_dict = NULL;
85 if (response_value->GetAsDictionary(&response_dict)) {
86 response_dict->GetString("email", &email);
87 }
88 }
89 }
90 if (email.empty()) {
91 delegate_->OnNetworkError(response_code);
92 } else {
93 delegate_->OnGetUserEmailResponse(email);
94 }
95 }
96
97 GaiaUserEmailFetcher::GaiaUserEmailFetcher(
98 net::URLRequestContextGetter* context_getter) {
99 core_ = new Core(context_getter);
100 }
101
102 GaiaUserEmailFetcher::~GaiaUserEmailFetcher() {
103 }
104
105 void GaiaUserEmailFetcher::GetUserEmail(
106 const std::string& oauth_access_token,
107 Delegate* delegate) {
108 return core_->GetUserEmail(oauth_access_token, delegate);
109 }
110
111 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/gaia_user_email_fetcher.h ('k') | remoting/host/remoting_me2me_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698