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

Side by Side Diff: sync/internal_api/syncapi_server_connection_manager.cc

Issue 15421011: Use OAuth2 token for sync (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 7 years, 6 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 (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 "sync/internal_api/syncapi_server_connection_manager.h" 5 #include "sync/internal_api/syncapi_server_connection_manager.h"
6 6
7 #include "net/base/net_errors.h" 7 #include "net/base/net_errors.h"
8 #include "net/http/http_status_code.h" 8 #include "net/http/http_status_code.h"
9 #include "sync/internal_api/public/http_post_provider_factory.h" 9 #include "sync/internal_api/public/http_post_provider_factory.h"
10 #include "sync/internal_api/public/http_post_provider_interface.h" 10 #include "sync/internal_api/public/http_post_provider_interface.h"
(...skipping 13 matching lines...) Expand all
24 post_provider_ = NULL; 24 post_provider_ = NULL;
25 } 25 }
26 26
27 bool SyncAPIBridgedConnection::Init(const char* path, 27 bool SyncAPIBridgedConnection::Init(const char* path,
28 const std::string& auth_token, 28 const std::string& auth_token,
29 const std::string& payload, 29 const std::string& payload,
30 HttpResponse* response) { 30 HttpResponse* response) {
31 std::string sync_server; 31 std::string sync_server;
32 int sync_server_port = 0; 32 int sync_server_port = 0;
33 bool use_ssl = false; 33 bool use_ssl = false;
34 GetServerParams(&sync_server, &sync_server_port, &use_ssl); 34 bool use_oauth2_token = false;
35 GetServerParams(&sync_server, &sync_server_port, &use_ssl, &use_oauth2_token);
35 std::string connection_url = MakeConnectionURL(sync_server, path, use_ssl); 36 std::string connection_url = MakeConnectionURL(sync_server, path, use_ssl);
36 37
37 HttpPostProviderInterface* http = post_provider_; 38 HttpPostProviderInterface* http = post_provider_;
38 http->SetURL(connection_url.c_str(), sync_server_port); 39 http->SetURL(connection_url.c_str(), sync_server_port);
39 40
40 if (!auth_token.empty()) { 41 if (!auth_token.empty()) {
41 const std::string& headers = 42 std::string headers;
42 "Authorization: GoogleLogin auth=" + auth_token; 43 if (use_oauth2_token)
44 headers = "Authorization: Bearer " + auth_token;
45 else
46 headers = "Authorization: GoogleLogin auth=" + auth_token;
43 http->SetExtraRequestHeaders(headers.c_str()); 47 http->SetExtraRequestHeaders(headers.c_str());
44 } 48 }
45 49
46 // Must be octet-stream, or the payload may be parsed for a cookie. 50 // Must be octet-stream, or the payload may be parsed for a cookie.
47 http->SetPostPayload("application/octet-stream", payload.length(), 51 http->SetPostPayload("application/octet-stream", payload.length(),
48 payload.data()); 52 payload.data());
49 53
50 // Issue the POST, blocking until it finishes. 54 // Issue the POST, blocking until it finishes.
51 int error_code = 0; 55 int error_code = 0;
52 int response_code = 0; 56 int response_code = 0;
(...skipping 27 matching lines...) Expand all
80 84
81 void SyncAPIBridgedConnection::Abort() { 85 void SyncAPIBridgedConnection::Abort() {
82 DCHECK(post_provider_); 86 DCHECK(post_provider_);
83 post_provider_->Abort(); 87 post_provider_->Abort();
84 } 88 }
85 89
86 SyncAPIServerConnectionManager::SyncAPIServerConnectionManager( 90 SyncAPIServerConnectionManager::SyncAPIServerConnectionManager(
87 const std::string& server, 91 const std::string& server,
88 int port, 92 int port,
89 bool use_ssl, 93 bool use_ssl,
94 bool use_oauth2_token,
90 HttpPostProviderFactory* factory) 95 HttpPostProviderFactory* factory)
91 : ServerConnectionManager(server, port, use_ssl), 96 : ServerConnectionManager(server, port, use_ssl, use_oauth2_token),
92 post_provider_factory_(factory) { 97 post_provider_factory_(factory) {
93 DCHECK(post_provider_factory_.get()); 98 DCHECK(post_provider_factory_.get());
94 } 99 }
95 100
96 SyncAPIServerConnectionManager::~SyncAPIServerConnectionManager() {} 101 SyncAPIServerConnectionManager::~SyncAPIServerConnectionManager() {}
97 102
98 ServerConnectionManager::Connection* 103 ServerConnectionManager::Connection*
99 SyncAPIServerConnectionManager::MakeConnection() { 104 SyncAPIServerConnectionManager::MakeConnection() {
100 return new SyncAPIBridgedConnection(this, post_provider_factory_.get()); 105 return new SyncAPIBridgedConnection(this, post_provider_factory_.get());
101 } 106 }
102 107
103 } // namespace syncer 108 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/internal_api/syncapi_server_connection_manager.h ('k') | sync/internal_api/syncapi_server_connection_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698