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

Side by Side Diff: ios/web/public/test/http_server.h

Issue 2128533002: Convert ScopedVector<T> to std::vector<std::unique_ptr<T>>. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
« no previous file with comments | « ios/web/browser_state_web_view_partition_inttest.mm ('k') | ios/web/public/test/http_server.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 IOS_WEB_PUBLIC_TEST_HTTP_SERVER_H_ 5 #ifndef IOS_WEB_PUBLIC_TEST_HTTP_SERVER_H_
6 #define IOS_WEB_PUBLIC_TEST_HTTP_SERVER_H_ 6 #define IOS_WEB_PUBLIC_TEST_HTTP_SERVER_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <vector> 9 #include <vector>
10 10
11 #import "base/mac/scoped_nsobject.h" 11 #import "base/mac/scoped_nsobject.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_vector.h"
15 #include "base/synchronization/lock.h" 14 #include "base/synchronization/lock.h"
16 #include "ios/web/public/test/response_providers/response_provider.h" 15 #include "ios/web/public/test/response_providers/response_provider.h"
17 16
18 @class GCDWebServer; 17 @class GCDWebServer;
19 18
20 namespace web { 19 namespace web {
21 namespace test { 20 namespace test {
22 21
23 // A convience class for wrapping a ResponseProvider so that it can be used 22 // A convience class for wrapping a ResponseProvider so that it can be used
24 // inside data structures that operate on ref counted objects. This class is a 23 // inside data structures that operate on ref counted objects. This class is a
25 // ref counted container for a ResponseProvider. 24 // ref counted container for a ResponseProvider.
26 // This object exists for legacy reasons since a large part of the code base 25 // This object exists for legacy reasons since a large part of the code base
27 // still uses ResponseProviders that are not ref counted. 26 // still uses ResponseProviders that are not ref counted.
28 class RefCountedResponseProviderWrapper : 27 class RefCountedResponseProviderWrapper :
29 public base::RefCounted<RefCountedResponseProviderWrapper> { 28 public base::RefCounted<RefCountedResponseProviderWrapper> {
30 public: 29 public:
31 // Main constructor. 30 // Main constructor.
32 explicit RefCountedResponseProviderWrapper( 31 explicit RefCountedResponseProviderWrapper(
33 ResponseProvider* response_provider); 32 std::unique_ptr<ResponseProvider> response_provider);
34 // Returns the ResponseProvider that backs this object. 33 // Returns the ResponseProvider that backs this object.
35 ResponseProvider* GetResponseProvider() { return response_provider_.get(); } 34 ResponseProvider* GetResponseProvider() { return response_provider_.get(); }
36 private: 35 private:
37 friend class base::RefCounted<RefCountedResponseProviderWrapper>; 36 friend class base::RefCounted<RefCountedResponseProviderWrapper>;
38 // The ResponseProvider that backs this object. 37 // The ResponseProvider that backs this object.
39 std::unique_ptr<ResponseProvider> response_provider_; 38 std::unique_ptr<ResponseProvider> response_provider_;
40 virtual ~RefCountedResponseProviderWrapper(); 39 virtual ~RefCountedResponseProviderWrapper();
41 }; 40 };
42 41
43 // The HttpServer is an in-process web server that is used to service requests. 42 // The HttpServer is an in-process web server that is used to service requests.
44 // It is a singleton and backed by a GCDWebServer. 43 // It is a singleton and backed by a GCDWebServer.
45 // HttpServer can be configured to serve requests by registering 44 // HttpServer can be configured to serve requests by registering
46 // web::ResponseProviders. 45 // web::ResponseProviders.
47 // This class is not thread safe on the whole and only certain methods are 46 // This class is not thread safe on the whole and only certain methods are
48 // thread safe. 47 // thread safe.
49 class HttpServer { 48 class HttpServer {
50 public: 49 public:
51 typedef ScopedVector<ResponseProvider> ProviderList; 50 typedef std::vector<std::unique_ptr<ResponseProvider>> ProviderList;
52 51
53 // Returns the shared HttpServer instance. Thread safe. 52 // Returns the shared HttpServer instance. Thread safe.
54 static HttpServer& GetSharedInstance(); 53 static HttpServer& GetSharedInstance();
55 // Returns the shared HttpServer instance and registers the response providers 54 // Returns the shared HttpServer instance and registers the response providers
56 // as well. Takes ownership of the response providers. Must be called from the 55 // as well. Takes ownership of the response providers. Must be called from the
57 // main thread. 56 // main thread.
58 static HttpServer& GetSharedInstanceWithResponseProviders( 57 static HttpServer& GetSharedInstanceWithResponseProviders(
59 const ProviderList& response_providers); 58 ProviderList response_providers);
60 59
61 // A convenience method for the longer form of 60 // A convenience method for the longer form of
62 // |web::test::HttpServer::GetSharedInstance().MakeUrlForHttpServer| 61 // |web::test::HttpServer::GetSharedInstance().MakeUrlForHttpServer|
63 static GURL MakeUrl(const std::string& url); 62 static GURL MakeUrl(const std::string& url);
64 63
65 // Starts the server on the default port 8080. CHECKs if the server can not be 64 // Starts the server on the default port 8080. CHECKs if the server can not be
66 // started. 65 // started.
67 // Must be called from the main thread. 66 // Must be called from the main thread.
68 void StartOrDie(); 67 void StartOrDie();
69 // Starts the server on |port|. Returns true on success, false otherwise. 68 // Starts the server on |port|. Returns true on success, false otherwise.
70 // Must be called from the main thread. 69 // Must be called from the main thread.
71 bool StartOnPort(NSUInteger port); 70 bool StartOnPort(NSUInteger port);
72 // Stops the server and prevents it from accepting new requests. 71 // Stops the server and prevents it from accepting new requests.
73 // Must be called from the main thread. 72 // Must be called from the main thread.
74 void Stop(); 73 void Stop();
75 // Returns true if the server is running. 74 // Returns true if the server is running.
76 // Must be called from the main thread. 75 // Must be called from the main thread.
77 bool IsRunning() const; 76 bool IsRunning() const;
78 77
79 // Adds a ResponseProvider. Takes ownership of the ResponseProvider. 78 // Adds a ResponseProvider. Takes ownership of the ResponseProvider.
80 // Note for using URLs inside of the |response_provider|: 79 // Note for using URLs inside of the |response_provider|:
81 // The HttpServer cannot run on default HTTP port 80, so URLs used in 80 // The HttpServer cannot run on default HTTP port 80, so URLs used in
82 // ResponseProviders must be converted at runtime after the HttpServer's port 81 // ResponseProviders must be converted at runtime after the HttpServer's port
83 // is determined. Please use |MakeUrl| to handle converting URLs. 82 // is determined. Please use |MakeUrl| to handle converting URLs.
84 // Must be called from the main thread. 83 // Must be called from the main thread.
85 void AddResponseProvider(ResponseProvider* response_provider); 84 void AddResponseProvider(std::unique_ptr<ResponseProvider> response_provider);
86 // Removes the |response_provider|. Must be called from the main thread. 85 // Removes the |response_provider|. Must be called from the main thread.
87 void RemoveResponseProvider(ResponseProvider* response_provider); 86 void RemoveResponseProvider(ResponseProvider* response_provider);
88 // Removes all the response providers. Must be called from the main thread. 87 // Removes all the response providers. Must be called from the main thread.
89 void RemoveAllResponseProviders(); 88 void RemoveAllResponseProviders();
90 89
91 private: 90 private:
92 // Initializes the server by registering for a GCDWebServer servlet. Must be 91 // Initializes the server by registering for a GCDWebServer servlet. Must be
93 // called from the main thread. 92 // called from the main thread.
94 void InitHttpServer(); 93 void InitHttpServer();
95 HttpServer(); 94 HttpServer();
(...skipping 29 matching lines...) Expand all
125 // The list of providers to service a request. 124 // The list of providers to service a request.
126 std::vector<scoped_refptr<RefCountedResponseProviderWrapper>> providers_; 125 std::vector<scoped_refptr<RefCountedResponseProviderWrapper>> providers_;
127 DISALLOW_COPY_AND_ASSIGN(HttpServer); 126 DISALLOW_COPY_AND_ASSIGN(HttpServer);
128 }; 127 };
129 128
130 } // namespace test 129 } // namespace test
131 } // namspace web 130 } // namspace web
132 131
133 #endif // IOS_WEB_PUBLIC_TEST_HTTP_SERVER_H_ 132 #endif // IOS_WEB_PUBLIC_TEST_HTTP_SERVER_H_
134 133
OLDNEW
« no previous file with comments | « ios/web/browser_state_web_view_partition_inttest.mm ('k') | ios/web/public/test/http_server.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698