OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/sync/engine/net/syncapi_server_connection_manager.h" | 5 #include "chrome/browser/sync/engine/net/syncapi_server_connection_manager.h" |
6 | 6 |
| 7 #include "base/command_line.h" |
7 #include "chrome/browser/sync/engine/http_post_provider_factory.h" | 8 #include "chrome/browser/sync/engine/http_post_provider_factory.h" |
8 #include "chrome/browser/sync/engine/http_post_provider_interface.h" | 9 #include "chrome/browser/sync/engine/http_post_provider_interface.h" |
9 #include "chrome/browser/sync/engine/syncapi.h" | 10 #include "chrome/browser/sync/engine/syncapi.h" |
| 11 #include "chrome/common/chrome_switches.h" |
10 #include "chrome/common/net/http_return.h" | 12 #include "chrome/common/net/http_return.h" |
11 | 13 |
12 using browser_sync::HttpResponse; | 14 using browser_sync::HttpResponse; |
13 | 15 |
14 namespace sync_api { | 16 namespace sync_api { |
15 | 17 |
16 SyncAPIBridgedPost::SyncAPIBridgedPost( | 18 SyncAPIBridgedPost::SyncAPIBridgedPost( |
17 browser_sync::ServerConnectionManager* scm, | 19 browser_sync::ServerConnectionManager* scm, |
18 HttpPostProviderFactory* factory) | 20 HttpPostProviderFactory* factory) |
19 : Post(scm), factory_(factory) { | 21 : Post(scm), factory_(factory) { |
20 } | 22 } |
21 | 23 |
22 SyncAPIBridgedPost::~SyncAPIBridgedPost() {} | 24 SyncAPIBridgedPost::~SyncAPIBridgedPost() {} |
23 | 25 |
24 bool SyncAPIBridgedPost::Init(const char* path, | 26 bool SyncAPIBridgedPost::Init(const char* path, |
25 const std::string& auth_token, | 27 const std::string& auth_token, |
26 const std::string& payload, | 28 const std::string& payload, |
27 HttpResponse* response) { | 29 HttpResponse* response) { |
28 std::string sync_server; | 30 std::string sync_server; |
29 int sync_server_port = 0; | 31 int sync_server_port = 0; |
30 bool use_ssl = false; | 32 bool use_ssl = false; |
31 GetServerParams(&sync_server, &sync_server_port, &use_ssl); | 33 GetServerParams(&sync_server, &sync_server_port, &use_ssl); |
32 std::string connection_url = MakeConnectionURL(sync_server, path, use_ssl); | 34 std::string connection_url = MakeConnectionURL(sync_server, path, use_ssl); |
33 | 35 |
34 HttpPostProviderInterface* http = factory_->Create(); | 36 HttpPostProviderInterface* http = factory_->Create(); |
35 http->SetUserAgent(scm_->user_agent().c_str()); | 37 http->SetUserAgent(scm_->user_agent().c_str()); |
36 http->SetURL(connection_url.c_str(), sync_server_port); | 38 http->SetURL(connection_url.c_str(), sync_server_port); |
37 | 39 |
38 if (!auth_token.empty()) { | 40 if (!auth_token.empty()) { |
39 std::string headers = "Authorization: GoogleLogin auth=" + auth_token; | 41 std::string headers; |
| 42 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 43 switches::kEnableSyncOAuth)) { |
| 44 headers = "Authorization: OAuth " + auth_token; |
| 45 } else { |
| 46 headers = "Authorization: GoogleLogin auth=" + auth_token; |
| 47 } |
40 http->SetExtraRequestHeaders(headers.c_str()); | 48 http->SetExtraRequestHeaders(headers.c_str()); |
41 } | 49 } |
42 | 50 |
43 // Must be octet-stream, or the payload may be parsed for a cookie. | 51 // Must be octet-stream, or the payload may be parsed for a cookie. |
44 http->SetPostPayload("application/octet-stream", payload.length(), | 52 http->SetPostPayload("application/octet-stream", payload.length(), |
45 payload.data()); | 53 payload.data()); |
46 | 54 |
47 // Issue the POST, blocking until it finishes. | 55 // Issue the POST, blocking until it finishes. |
48 int os_error_code = 0; | 56 int os_error_code = 0; |
49 int response_code = 0; | 57 int response_code = 0; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 } | 98 } |
91 | 99 |
92 SyncAPIServerConnectionManager::~SyncAPIServerConnectionManager() {} | 100 SyncAPIServerConnectionManager::~SyncAPIServerConnectionManager() {} |
93 | 101 |
94 browser_sync::ServerConnectionManager::Post* | 102 browser_sync::ServerConnectionManager::Post* |
95 SyncAPIServerConnectionManager::MakePost() { | 103 SyncAPIServerConnectionManager::MakePost() { |
96 return new SyncAPIBridgedPost(this, post_provider_factory_.get()); | 104 return new SyncAPIBridgedPost(this, post_provider_factory_.get()); |
97 } | 105 } |
98 | 106 |
99 } // namespace sync_api | 107 } // namespace sync_api |
OLD | NEW |