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
3 // found in the LICENSE file.
5 #ifndef SYNC_TEST_FAKE_SERVER_FAKE_SERVER_HTTP_POST_PROVIDER_H_
6 #define SYNC_TEST_FAKE_SERVER_FAKE_SERVER_HTTP_POST_PROVIDER_H_
10 #include "base/memory/ref_counted.h"
11 #include "base/sequenced_task_runner.h"
12 #include "base/synchronization/waitable_event.h"
13 #include "sync/internal_api/public/http_post_provider_factory.h"
14 #include "sync/internal_api/public/http_post_provider_interface.h"
16 namespace fake_server
{
20 class FakeServerHttpPostProvider
21 : public syncer::HttpPostProviderInterface
,
22 public base::RefCountedThreadSafe
<FakeServerHttpPostProvider
> {
24 FakeServerHttpPostProvider(
25 FakeServer
* fake_server
,
26 scoped_refptr
<base::SequencedTaskRunner
> task_runner
);
28 // HttpPostProviderInterface implementation.
29 void SetExtraRequestHeaders(const char* headers
) override
;
30 void SetURL(const char* url
, int port
) override
;
31 void SetPostPayload(const char* content_type
,
33 const char* content
) override
;
34 bool MakeSynchronousPost(int* error_code
, int* response_code
) override
;
35 void Abort() override
;
36 int GetResponseContentLength() const override
;
37 const char* GetResponseContent() const override
;
38 const std::string
GetResponseHeaderValue(
39 const std::string
& name
) const override
;
42 friend class base::RefCountedThreadSafe
<FakeServerHttpPostProvider
>;
43 ~FakeServerHttpPostProvider() override
;
46 void OnPostComplete(int error_code
,
48 const std::string
& response
);
50 FakeServer
* const fake_server_
;
51 scoped_refptr
<base::SequencedTaskRunner
> task_runner_
;
53 std::string response_
;
54 std::string request_url_
;
56 std::string request_content_
;
57 std::string request_content_type_
;
58 std::string extra_request_headers_
;
60 int post_response_code_
;
61 base::WaitableEvent post_complete_
;
63 DISALLOW_COPY_AND_ASSIGN(FakeServerHttpPostProvider
);
66 class FakeServerHttpPostProviderFactory
67 : public syncer::HttpPostProviderFactory
{
69 FakeServerHttpPostProviderFactory(
70 FakeServer
* fake_server
,
71 scoped_refptr
<base::SequencedTaskRunner
> task_runner
);
72 ~FakeServerHttpPostProviderFactory() override
;
74 // HttpPostProviderFactory:
75 void Init(const std::string
& user_agent
) override
;
76 syncer::HttpPostProviderInterface
* Create() override
;
77 void Destroy(syncer::HttpPostProviderInterface
* http
) override
;
80 FakeServer
* const fake_server_
;
81 scoped_refptr
<base::SequencedTaskRunner
> task_runner_
;
83 DISALLOW_COPY_AND_ASSIGN(FakeServerHttpPostProviderFactory
);
86 } // namespace fake_server
88 #endif // SYNC_TEST_FAKE_SERVER_FAKE_SERVER_HTTP_POST_PROVIDER_H_