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

Side by Side Diff: components/sync/test/fake_server/fake_server_http_post_provider.cc

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 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 "sync/test/fake_server/fake_server_http_post_provider.h" 5 #include "components/sync/test/fake_server/fake_server_http_post_provider.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/sequenced_task_runner.h" 13 #include "base/sequenced_task_runner.h"
14 #include "base/synchronization/waitable_event.h" 14 #include "base/synchronization/waitable_event.h"
15 #include "sync/test/fake_server/fake_server.h" 15 #include "components/sync/test/fake_server/fake_server.h"
16 16
17 using syncer::HttpPostProviderInterface; 17 using syncer::HttpPostProviderInterface;
18 18
19 namespace fake_server { 19 namespace fake_server {
20 20
21 FakeServerHttpPostProviderFactory::FakeServerHttpPostProviderFactory( 21 FakeServerHttpPostProviderFactory::FakeServerHttpPostProviderFactory(
22 const base::WeakPtr<FakeServer>& fake_server, 22 const base::WeakPtr<FakeServer>& fake_server,
23 scoped_refptr<base::SequencedTaskRunner> fake_server_task_runner) 23 scoped_refptr<base::SequencedTaskRunner> fake_server_task_runner)
24 : fake_server_(fake_server), 24 : fake_server_(fake_server),
25 fake_server_task_runner_(fake_server_task_runner) { } 25 fake_server_task_runner_(fake_server_task_runner) {}
26 26
27 FakeServerHttpPostProviderFactory::~FakeServerHttpPostProviderFactory() { } 27 FakeServerHttpPostProviderFactory::~FakeServerHttpPostProviderFactory() {}
28 28
29 void FakeServerHttpPostProviderFactory::Init( 29 void FakeServerHttpPostProviderFactory::Init(
30 const std::string& user_agent, 30 const std::string& user_agent,
31 const syncer::BindToTrackerCallback& bind_to_tracker_callback) {} 31 const syncer::BindToTrackerCallback& bind_to_tracker_callback) {}
32 32
33 HttpPostProviderInterface* FakeServerHttpPostProviderFactory::Create() { 33 HttpPostProviderInterface* FakeServerHttpPostProviderFactory::Create() {
34 FakeServerHttpPostProvider* http = 34 FakeServerHttpPostProvider* http =
35 new FakeServerHttpPostProvider(fake_server_, fake_server_task_runner_); 35 new FakeServerHttpPostProvider(fake_server_, fake_server_task_runner_);
36 http->AddRef(); 36 http->AddRef();
37 return http; 37 return http;
38 } 38 }
39 39
40 void FakeServerHttpPostProviderFactory::Destroy( 40 void FakeServerHttpPostProviderFactory::Destroy(
41 HttpPostProviderInterface* http) { 41 HttpPostProviderInterface* http) {
42 static_cast<FakeServerHttpPostProvider*>(http)->Release(); 42 static_cast<FakeServerHttpPostProvider*>(http)->Release();
43 } 43 }
44 44
45 FakeServerHttpPostProvider::FakeServerHttpPostProvider( 45 FakeServerHttpPostProvider::FakeServerHttpPostProvider(
46 const base::WeakPtr<FakeServer>& fake_server, 46 const base::WeakPtr<FakeServer>& fake_server,
47 scoped_refptr<base::SequencedTaskRunner> fake_server_task_runner) 47 scoped_refptr<base::SequencedTaskRunner> fake_server_task_runner)
48 : fake_server_(fake_server), 48 : fake_server_(fake_server),
49 fake_server_task_runner_(fake_server_task_runner) { } 49 fake_server_task_runner_(fake_server_task_runner) {}
50 50
51 FakeServerHttpPostProvider::~FakeServerHttpPostProvider() { } 51 FakeServerHttpPostProvider::~FakeServerHttpPostProvider() {}
52 52
53 void FakeServerHttpPostProvider::SetExtraRequestHeaders(const char* headers) { 53 void FakeServerHttpPostProvider::SetExtraRequestHeaders(const char* headers) {
54 // TODO(pvalenzuela): Add assertions on this value. 54 // TODO(pvalenzuela): Add assertions on this value.
55 extra_request_headers_.assign(headers); 55 extra_request_headers_.assign(headers);
56 } 56 }
57 57
58 void FakeServerHttpPostProvider::SetURL(const char* url, int port) { 58 void FakeServerHttpPostProvider::SetURL(const char* url, int port) {
59 // TODO(pvalenzuela): Add assertions on these values. 59 // TODO(pvalenzuela): Add assertions on these values.
60 request_url_.assign(url); 60 request_url_.assign(url);
61 request_port_ = port; 61 request_port_ = port;
(...skipping 13 matching lines...) Expand all
75 int post_response_code = -1; 75 int post_response_code = -1;
76 std::string post_response; 76 std::string post_response;
77 77
78 base::WaitableEvent post_complete( 78 base::WaitableEvent post_complete(
79 base::WaitableEvent::ResetPolicy::AUTOMATIC, 79 base::WaitableEvent::ResetPolicy::AUTOMATIC,
80 base::WaitableEvent::InitialState::NOT_SIGNALED); 80 base::WaitableEvent::InitialState::NOT_SIGNALED);
81 base::Closure signal_closure = base::Bind(&base::WaitableEvent::Signal, 81 base::Closure signal_closure = base::Bind(&base::WaitableEvent::Signal,
82 base::Unretained(&post_complete)); 82 base::Unretained(&post_complete));
83 83
84 bool result = fake_server_task_runner_->PostTask( 84 bool result = fake_server_task_runner_->PostTask(
85 FROM_HERE, 85 FROM_HERE, base::Bind(&FakeServer::HandleCommand, fake_server_,
86 base::Bind(&FakeServer::HandleCommand, 86 base::ConstRef(request_content_),
87 fake_server_, 87 base::ConstRef(signal_closure), &post_error_code,
88 base::ConstRef(request_content_), 88 &post_response_code, &post_response));
89 base::ConstRef(signal_closure),
90 &post_error_code,
91 &post_response_code,
92 &post_response));
93 89
94 if (!result) 90 if (!result)
95 return false; 91 return false;
96 92
97 post_complete.Wait(); 93 post_complete.Wait();
98 post_error_code_ = post_error_code; 94 post_error_code_ = post_error_code;
99 post_response_code_ = post_response_code; 95 post_response_code_ = post_response_code;
100 response_ = post_response; 96 response_ = post_response;
101 97
102 *error_code = post_error_code_; 98 *error_code = post_error_code_;
103 *response_code = post_response_code_; 99 *response_code = post_response_code_;
104 return *error_code == 0; 100 return *error_code == 0;
105 } 101 }
106 102
107 int FakeServerHttpPostProvider::GetResponseContentLength() const { 103 int FakeServerHttpPostProvider::GetResponseContentLength() const {
108 return response_.length(); 104 return response_.length();
109 } 105 }
110 106
111 const char* FakeServerHttpPostProvider::GetResponseContent() const { 107 const char* FakeServerHttpPostProvider::GetResponseContent() const {
112 return response_.c_str(); 108 return response_.c_str();
113 } 109 }
114 110
115 const std::string FakeServerHttpPostProvider::GetResponseHeaderValue( 111 const std::string FakeServerHttpPostProvider::GetResponseHeaderValue(
116 const std::string& name) const { 112 const std::string& name) const {
117 return std::string(); 113 return std::string();
118 } 114 }
119 115
120 void FakeServerHttpPostProvider::Abort() { 116 void FakeServerHttpPostProvider::Abort() {}
121 }
122 117
123 } // namespace fake_server 118 } // namespace fake_server
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698