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

Side by Side Diff: chrome/browser/printing/cloud_print/gcd_api_flow_impl.cc

Issue 1553333002: Move cloud print specific files out of local_discovery (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@moveprn
Patch Set: Created 4 years, 11 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/local_discovery/gcd_api_flow_impl.h" 5 #include "chrome/browser/printing/cloud_print/gcd_api_flow_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/local_discovery/gcd_constants.h" 14 #include "chrome/browser/printing/cloud_print/gcd_constants.h"
15 #include "chrome/common/cloud_print/cloud_print_constants.h" 15 #include "chrome/common/cloud_print/cloud_print_constants.h"
16 #include "components/cloud_devices/common/cloud_devices_urls.h" 16 #include "components/cloud_devices/common/cloud_devices_urls.h"
17 #include "google_apis/gaia/google_service_auth_error.h" 17 #include "google_apis/gaia/google_service_auth_error.h"
18 #include "net/base/load_flags.h" 18 #include "net/base/load_flags.h"
19 #include "net/base/url_util.h" 19 #include "net/base/url_util.h"
20 #include "net/http/http_status_code.h" 20 #include "net/http/http_status_code.h"
21 #include "net/url_request/url_request_status.h" 21 #include "net/url_request/url_request_status.h"
22 22
23 namespace local_discovery { 23 namespace cloud_print {
24 24
25 GCDApiFlowImpl::GCDApiFlowImpl(net::URLRequestContextGetter* request_context, 25 GCDApiFlowImpl::GCDApiFlowImpl(net::URLRequestContextGetter* request_context,
26 OAuth2TokenService* token_service, 26 OAuth2TokenService* token_service,
27 const std::string& account_id) 27 const std::string& account_id)
28 : OAuth2TokenService::Consumer("cloud_print"), 28 : OAuth2TokenService::Consumer("cloud_print"),
29 request_context_(request_context), 29 request_context_(request_context),
30 token_service_(token_service), 30 token_service_(token_service),
31 account_id_(account_id) { 31 account_id_(account_id) {
32 } 32 }
33 33
(...skipping 19 matching lines...) Expand all
53 53
54 url_fetcher_->AddExtraRequestHeader(authorization_header); 54 url_fetcher_->AddExtraRequestHeader(authorization_header);
55 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | 55 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES |
56 net::LOAD_DO_NOT_SEND_COOKIES); 56 net::LOAD_DO_NOT_SEND_COOKIES);
57 url_fetcher_->Start(); 57 url_fetcher_->Start();
58 } 58 }
59 59
60 void GCDApiFlowImpl::OnGetTokenFailure( 60 void GCDApiFlowImpl::OnGetTokenFailure(
61 const OAuth2TokenService::Request* request, 61 const OAuth2TokenService::Request* request,
62 const GoogleServiceAuthError& error) { 62 const GoogleServiceAuthError& error) {
63 request_->OnGCDAPIFlowError(ERROR_TOKEN); 63 request_->OnGCDApiFlowError(ERROR_TOKEN);
64 } 64 }
65 65
66 void GCDApiFlowImpl::CreateRequest(const GURL& url) { 66 void GCDApiFlowImpl::CreateRequest(const GURL& url) {
67 net::URLFetcher::RequestType request_type = request_->GetRequestType(); 67 net::URLFetcher::RequestType request_type = request_->GetRequestType();
68 68
69 url_fetcher_ = net::URLFetcher::Create(url, request_type, this); 69 url_fetcher_ = net::URLFetcher::Create(url, request_type, this);
70 70
71 if (request_type != net::URLFetcher::GET) { 71 if (request_type != net::URLFetcher::GET) {
72 std::string upload_type; 72 std::string upload_type;
73 std::string upload_data; 73 std::string upload_data;
(...skipping 10 matching lines...) Expand all
84 84
85 void GCDApiFlowImpl::OnURLFetchComplete(const net::URLFetcher* source) { 85 void GCDApiFlowImpl::OnURLFetchComplete(const net::URLFetcher* source) {
86 // TODO(noamsml): Error logging. 86 // TODO(noamsml): Error logging.
87 87
88 // TODO(noamsml): Extract this and PrivetURLFetcher::OnURLFetchComplete into 88 // TODO(noamsml): Extract this and PrivetURLFetcher::OnURLFetchComplete into
89 // one helper method. 89 // one helper method.
90 std::string response_str; 90 std::string response_str;
91 91
92 if (source->GetStatus().status() != net::URLRequestStatus::SUCCESS || 92 if (source->GetStatus().status() != net::URLRequestStatus::SUCCESS ||
93 !source->GetResponseAsString(&response_str)) { 93 !source->GetResponseAsString(&response_str)) {
94 request_->OnGCDAPIFlowError(ERROR_NETWORK); 94 request_->OnGCDApiFlowError(ERROR_NETWORK);
95 return; 95 return;
96 } 96 }
97 97
98 if (source->GetResponseCode() != net::HTTP_OK) { 98 if (source->GetResponseCode() != net::HTTP_OK) {
99 request_->OnGCDAPIFlowError(ERROR_HTTP_CODE); 99 request_->OnGCDApiFlowError(ERROR_HTTP_CODE);
100 return; 100 return;
101 } 101 }
102 102
103 base::JSONReader reader; 103 base::JSONReader reader;
104 scoped_ptr<const base::Value> value(reader.Read(response_str)); 104 scoped_ptr<const base::Value> value(reader.Read(response_str));
105 const base::DictionaryValue* dictionary_value = NULL; 105 const base::DictionaryValue* dictionary_value = NULL;
106 106
107 if (!value || !value->GetAsDictionary(&dictionary_value)) { 107 if (!value || !value->GetAsDictionary(&dictionary_value)) {
108 request_->OnGCDAPIFlowError(ERROR_MALFORMED_RESPONSE); 108 request_->OnGCDApiFlowError(ERROR_MALFORMED_RESPONSE);
109 return; 109 return;
110 } 110 }
111 111
112 request_->OnGCDAPIFlowComplete(*dictionary_value); 112 request_->OnGCDApiFlowComplete(*dictionary_value);
113 } 113 }
114 114
115 } // namespace local_discovery 115 } // namespace cloud_print
OLDNEW
« no previous file with comments | « chrome/browser/printing/cloud_print/gcd_api_flow_impl.h ('k') | chrome/browser/printing/cloud_print/gcd_api_flow_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698