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/memory/weak_ptr.h"
12 #include "base/sequenced_task_runner.h"
13 #include "base/synchronization/waitable_event.h"
14 #include "sync/internal_api/public/http_post_provider_factory.h"
15 #include "sync/internal_api/public/http_post_provider_interface.h"
17 namespace fake_server
{
21 class FakeServerHttpPostProvider
22 : public syncer::HttpPostProviderInterface
,
23 public base::RefCountedThreadSafe
<FakeServerHttpPostProvider
> {
25 FakeServerHttpPostProvider(
26 const base::WeakPtr
<FakeServer
>& fake_server
,
27 scoped_refptr
<base::SequencedTaskRunner
> fake_server_task_runner
);
29 // HttpPostProviderInterface implementation.
30 void SetExtraRequestHeaders(const char* headers
) override
;
31 void SetURL(const char* url
, int port
) override
;
32 void SetPostPayload(const char* content_type
,
34 const char* content
) override
;
35 bool MakeSynchronousPost(int* error_code
, int* response_code
) override
;
36 void Abort() override
;
37 int GetResponseContentLength() const override
;
38 const char* GetResponseContent() const override
;
39 const std::string
GetResponseHeaderValue(
40 const std::string
& name
) const override
;
43 friend class base::RefCountedThreadSafe
<FakeServerHttpPostProvider
>;
44 ~FakeServerHttpPostProvider() override
;
47 // |fake_server_| should only be dereferenced on the same thread as
48 // |fake_server_task_runner_| runs on.
49 base::WeakPtr
<FakeServer
> fake_server_
;
50 scoped_refptr
<base::SequencedTaskRunner
> fake_server_task_runner_
;
52 std::string response_
;
53 std::string request_url_
;
55 std::string request_content_
;
56 std::string request_content_type_
;
57 std::string extra_request_headers_
;
59 int post_response_code_
;
61 DISALLOW_COPY_AND_ASSIGN(FakeServerHttpPostProvider
);
64 class FakeServerHttpPostProviderFactory
65 : public syncer::HttpPostProviderFactory
{
67 FakeServerHttpPostProviderFactory(
68 const base::WeakPtr
<FakeServer
>& fake_server
,
69 scoped_refptr
<base::SequencedTaskRunner
> fake_server_task_runner
);
70 ~FakeServerHttpPostProviderFactory() override
;
72 // HttpPostProviderFactory:
73 void Init(const std::string
& user_agent
) override
;
74 syncer::HttpPostProviderInterface
* Create() override
;
75 void Destroy(syncer::HttpPostProviderInterface
* http
) override
;
78 // |fake_server_| should only be dereferenced on the same thread as
79 // |fake_server_task_runner_| runs on.
80 base::WeakPtr
<FakeServer
> fake_server_
;
81 scoped_refptr
<base::SequencedTaskRunner
> fake_server_task_runner_
;
83 DISALLOW_COPY_AND_ASSIGN(FakeServerHttpPostProviderFactory
);
86 } // namespace fake_server
88 #endif // SYNC_TEST_FAKE_SERVER_FAKE_SERVER_HTTP_POST_PROVIDER_H_