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

Side by Side Diff: chrome/browser/extensions/app_notify_channel_setup.cc

Issue 10386063: Move URLFetcherDelegate to net/ and split URLFetcher between net/ and content/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync to head, fix win component build Created 8 years, 7 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) 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 "chrome/browser/extensions/app_notify_channel_setup.h" 5 #include "chrome/browser/extensions/app_notify_channel_setup.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/json/json_reader.h"
13 #include "base/message_loop.h" 14 #include "base/message_loop.h"
14 #include "base/json/json_reader.h"
15 #include "base/metrics/histogram.h" 15 #include "base/metrics/histogram.h"
16 #include "base/stringprintf.h" 16 #include "base/stringprintf.h"
17 #include "chrome/browser/prefs/pref_service.h" 17 #include "chrome/browser/prefs/pref_service.h"
18 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/signin/signin_manager.h" 19 #include "chrome/browser/signin/signin_manager.h"
20 #include "chrome/browser/signin/signin_manager_factory.h" 20 #include "chrome/browser/signin/signin_manager_factory.h"
21 #include "chrome/browser/signin/token_service.h" 21 #include "chrome/browser/signin/token_service.h"
22 #include "chrome/browser/signin/token_service_factory.h" 22 #include "chrome/browser/signin/token_service_factory.h"
23 #include "chrome/common/chrome_switches.h" 23 #include "chrome/common/chrome_switches.h"
24 #include "chrome/common/net/gaia/gaia_constants.h" 24 #include "chrome/common/net/gaia/gaia_constants.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 } 119 }
120 void AppNotifyChannelSetup::OnGetTokenFailure( 120 void AppNotifyChannelSetup::OnGetTokenFailure(
121 const GoogleServiceAuthError& error) { 121 const GoogleServiceAuthError& error) {
122 EndGetAccessToken(false); 122 EndGetAccessToken(false);
123 } 123 }
124 124
125 void AppNotifyChannelSetup::OnSyncSetupResult(bool enabled) { 125 void AppNotifyChannelSetup::OnSyncSetupResult(bool enabled) {
126 EndLogin(enabled); 126 EndLogin(enabled);
127 } 127 }
128 128
129 void AppNotifyChannelSetup::OnURLFetchComplete(const URLFetcher* source) { 129 void AppNotifyChannelSetup::OnURLFetchComplete(const net::URLFetcher* source) {
130 CHECK(source); 130 CHECK(source);
131 switch (state_) { 131 switch (state_) {
132 case RECORD_GRANT_STARTED: 132 case RECORD_GRANT_STARTED:
133 EndRecordGrant(source); 133 EndRecordGrant(source);
134 break; 134 break;
135 case CHANNEL_ID_SETUP_STARTED: 135 case CHANNEL_ID_SETUP_STARTED:
136 EndGetChannelId(source); 136 EndGetChannelId(source);
137 break; 137 break;
138 default: 138 default:
139 CHECK(false) << "Wrong state: " << state_; 139 CHECK(false) << "Wrong state: " << state_;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 CHECK_EQ(FETCH_ACCESS_TOKEN_DONE, state_); 262 CHECK_EQ(FETCH_ACCESS_TOKEN_DONE, state_);
263 state_ = RECORD_GRANT_STARTED; 263 state_ = RECORD_GRANT_STARTED;
264 264
265 GURL url = GetOAuth2IssueTokenURL(); 265 GURL url = GetOAuth2IssueTokenURL();
266 std::string body = MakeOAuth2IssueTokenBody(client_id_, extension_id_); 266 std::string body = MakeOAuth2IssueTokenBody(client_id_, extension_id_);
267 267
268 url_fetcher_.reset(CreateURLFetcher(url, body, oauth2_access_token_)); 268 url_fetcher_.reset(CreateURLFetcher(url, body, oauth2_access_token_));
269 url_fetcher_->Start(); 269 url_fetcher_->Start();
270 } 270 }
271 271
272 void AppNotifyChannelSetup::EndRecordGrant(const URLFetcher* source) { 272 void AppNotifyChannelSetup::EndRecordGrant(const net::URLFetcher* source) {
273 CHECK_EQ(RECORD_GRANT_STARTED, state_); 273 CHECK_EQ(RECORD_GRANT_STARTED, state_);
274 274
275 net::URLRequestStatus status = source->GetStatus(); 275 net::URLRequestStatus status = source->GetStatus();
276 276
277 if (status.status() == net::URLRequestStatus::SUCCESS) { 277 if (status.status() == net::URLRequestStatus::SUCCESS) {
278 if (source->GetResponseCode() == net::HTTP_OK) { 278 if (source->GetResponseCode() == net::HTTP_OK) {
279 state_ = RECORD_GRANT_DONE; 279 state_ = RECORD_GRANT_DONE;
280 BeginGetChannelId(); 280 BeginGetChannelId();
281 } else { 281 } else {
282 // Successfully done with HTTP request, but got an explicit error. 282 // Successfully done with HTTP request, but got an explicit error.
(...skipping 10 matching lines...) Expand all
293 void AppNotifyChannelSetup::BeginGetChannelId() { 293 void AppNotifyChannelSetup::BeginGetChannelId() {
294 CHECK_EQ(RECORD_GRANT_DONE, state_); 294 CHECK_EQ(RECORD_GRANT_DONE, state_);
295 state_ = CHANNEL_ID_SETUP_STARTED; 295 state_ = CHANNEL_ID_SETUP_STARTED;
296 296
297 GURL url = GetCWSChannelServiceURL(); 297 GURL url = GetCWSChannelServiceURL();
298 298
299 url_fetcher_.reset(CreateURLFetcher(url, "", oauth2_access_token_)); 299 url_fetcher_.reset(CreateURLFetcher(url, "", oauth2_access_token_));
300 url_fetcher_->Start(); 300 url_fetcher_->Start();
301 } 301 }
302 302
303 void AppNotifyChannelSetup::EndGetChannelId(const URLFetcher* source) { 303 void AppNotifyChannelSetup::EndGetChannelId(const net::URLFetcher* source) {
304 CHECK_EQ(CHANNEL_ID_SETUP_STARTED, state_); 304 CHECK_EQ(CHANNEL_ID_SETUP_STARTED, state_);
305 net::URLRequestStatus status = source->GetStatus(); 305 net::URLRequestStatus status = source->GetStatus();
306 306
307 if (status.status() == net::URLRequestStatus::SUCCESS) { 307 if (status.status() == net::URLRequestStatus::SUCCESS) {
308 if (source->GetResponseCode() == net::HTTP_OK) { 308 if (source->GetResponseCode() == net::HTTP_OK) {
309 std::string data; 309 std::string data;
310 source->GetResponseAsString(&data); 310 source->GetResponseAsString(&data);
311 std::string channel_id; 311 std::string channel_id;
312 bool result = ParseCWSChannelServiceResponse(data, &channel_id); 312 bool result = ParseCWSChannelServiceResponse(data, &channel_id);
313 if (result) { 313 if (result) {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); 410 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get());
411 if (!dict->Get("id", &channel_id_value)) 411 if (!dict->Get("id", &channel_id_value))
412 return false; 412 return false;
413 if (channel_id_value->GetType() != base::Value::TYPE_STRING) 413 if (channel_id_value->GetType() != base::Value::TYPE_STRING)
414 return false; 414 return false;
415 415
416 StringValue* channel_id = static_cast<StringValue*>(channel_id_value); 416 StringValue* channel_id = static_cast<StringValue*>(channel_id_value);
417 channel_id->GetAsString(result); 417 channel_id->GetAsString(result);
418 return true; 418 return true;
419 } 419 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/app_notify_channel_setup.h ('k') | chrome/browser/extensions/apps_promo.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698