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

Side by Side Diff: sync/test/fake_server/fake_server_http_post_provider.h

Issue 267723012: Use FakeServer-based invalidations for Sync tests (try #2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 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 #ifndef SYNC_TEST_FAKE_SERVER_FAKE_SERVER_HTTP_POST_PROVIDER_H_ 5 #ifndef SYNC_TEST_FAKE_SERVER_FAKE_SERVER_HTTP_POST_PROVIDER_H_
6 #define SYNC_TEST_FAKE_SERVER_FAKE_SERVER_HTTP_POST_PROVIDER_H_ 6 #define SYNC_TEST_FAKE_SERVER_FAKE_SERVER_HTTP_POST_PROVIDER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/sequenced_task_runner.h"
12 #include "base/synchronization/waitable_event.h"
11 #include "sync/internal_api/public/http_post_provider_factory.h" 13 #include "sync/internal_api/public/http_post_provider_factory.h"
12 #include "sync/internal_api/public/http_post_provider_interface.h" 14 #include "sync/internal_api/public/http_post_provider_interface.h"
13 15
14 namespace fake_server { 16 namespace fake_server {
15 17
16 class FakeServer; 18 class FakeServer;
17 19
18 class FakeServerHttpPostProvider 20 class FakeServerHttpPostProvider
19 : public syncer::HttpPostProviderInterface, 21 : public syncer::HttpPostProviderInterface,
20 public base::RefCountedThreadSafe<FakeServerHttpPostProvider> { 22 public base::RefCountedThreadSafe<FakeServerHttpPostProvider> {
21 public: 23 public:
22 explicit FakeServerHttpPostProvider(FakeServer* fake_server); 24 explicit FakeServerHttpPostProvider(
25 FakeServer* fake_server,
26 scoped_refptr<base::SequencedTaskRunner> task_runner);
23 27
24 // HttpPostProviderInterface implementation. 28 // HttpPostProviderInterface implementation.
25 virtual void SetExtraRequestHeaders(const char* headers) OVERRIDE; 29 virtual void SetExtraRequestHeaders(const char* headers) OVERRIDE;
26 virtual void SetURL(const char* url, int port) OVERRIDE; 30 virtual void SetURL(const char* url, int port) OVERRIDE;
27 virtual void SetPostPayload(const char* content_type, int content_length, 31 virtual void SetPostPayload(const char* content_type, int content_length,
28 const char* content) OVERRIDE; 32 const char* content) OVERRIDE;
29 virtual bool MakeSynchronousPost(int* error_code, 33 virtual bool MakeSynchronousPost(int* error_code,
30 int* response_code) OVERRIDE; 34 int* response_code) OVERRIDE;
31 virtual void Abort() OVERRIDE; 35 virtual void Abort() OVERRIDE;
32 virtual int GetResponseContentLength() const OVERRIDE; 36 virtual int GetResponseContentLength() const OVERRIDE;
33 virtual const char* GetResponseContent() const OVERRIDE; 37 virtual const char* GetResponseContent() const OVERRIDE;
34 virtual const std::string GetResponseHeaderValue( 38 virtual const std::string GetResponseHeaderValue(
35 const std::string& name) const OVERRIDE; 39 const std::string& name) const OVERRIDE;
36 40
37 protected: 41 protected:
38 friend class base::RefCountedThreadSafe<FakeServerHttpPostProvider>; 42 friend class base::RefCountedThreadSafe<FakeServerHttpPostProvider>;
39 virtual ~FakeServerHttpPostProvider(); 43 virtual ~FakeServerHttpPostProvider();
40 44
41 private: 45 private:
46 void OnPostComplete(int error_code,
47 int response_code,
48 const std::string& response);
49
42 FakeServer* const fake_server_; 50 FakeServer* const fake_server_;
51 scoped_refptr<base::SequencedTaskRunner> task_runner_;
52
43 std::string response_; 53 std::string response_;
44 std::string request_url_; 54 std::string request_url_;
45 int request_port_; 55 int request_port_;
46 std::string request_content_; 56 std::string request_content_;
47 std::string request_content_type_; 57 std::string request_content_type_;
48 std::string extra_request_headers_; 58 std::string extra_request_headers_;
59 int post_error_code_;
60 int post_response_code_;
61 base::WaitableEvent post_complete_;
49 62
50 DISALLOW_COPY_AND_ASSIGN(FakeServerHttpPostProvider); 63 DISALLOW_COPY_AND_ASSIGN(FakeServerHttpPostProvider);
51 }; 64 };
52 65
53 class FakeServerHttpPostProviderFactory 66 class FakeServerHttpPostProviderFactory
54 : public syncer::HttpPostProviderFactory { 67 : public syncer::HttpPostProviderFactory {
55 public: 68 public:
56 explicit FakeServerHttpPostProviderFactory(FakeServer* fake_server); 69 explicit FakeServerHttpPostProviderFactory(
70 FakeServer* fake_server,
71 scoped_refptr<base::SequencedTaskRunner> task_runner);
57 virtual ~FakeServerHttpPostProviderFactory(); 72 virtual ~FakeServerHttpPostProviderFactory();
58 73
59 // HttpPostProviderFactory: 74 // HttpPostProviderFactory:
60 virtual void Init(const std::string& user_agent) OVERRIDE; 75 virtual void Init(const std::string& user_agent) OVERRIDE;
61 virtual syncer::HttpPostProviderInterface* Create() OVERRIDE; 76 virtual syncer::HttpPostProviderInterface* Create() OVERRIDE;
62 virtual void Destroy(syncer::HttpPostProviderInterface* http) OVERRIDE; 77 virtual void Destroy(syncer::HttpPostProviderInterface* http) OVERRIDE;
63 78
64 private: 79 private:
65 FakeServer* const fake_server_; 80 FakeServer* const fake_server_;
81 scoped_refptr<base::SequencedTaskRunner> task_runner_;
66 82
67 DISALLOW_COPY_AND_ASSIGN(FakeServerHttpPostProviderFactory); 83 DISALLOW_COPY_AND_ASSIGN(FakeServerHttpPostProviderFactory);
68 }; 84 };
69 85
70 } // namespace fake_server 86 } // namespace fake_server
71 87
72 #endif // SYNC_TEST_FAKE_SERVER_FAKE_SERVER_HTTP_POST_PROVIDER_H_ 88 #endif // SYNC_TEST_FAKE_SERVER_FAKE_SERVER_HTTP_POST_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698