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

Side by Side Diff: chrome/browser/policy/test_request_interceptor.h

Issue 12209070: Fix cloud policy duplicate registrations issue. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed comments Created 7 years, 10 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 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.
4
5 #ifndef CHROME_BROWSER_POLICY_TEST_REQUEST_INTERCEPTOR_H_
6 #define CHROME_BROWSER_POLICY_TEST_REQUEST_INTERCEPTOR_H_
7
8 #include <string>
9
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12
13 namespace net {
14 class NetworkDelegate;
15 class URLRequest;
16 class URLRequestJob;
17 }
18
19 namespace policy {
20
21 // Intercepts all requests to the given hostname while in scope, and allows
22 // queuing callbacks to handle expected requests. Must be created and destroyed
23 // while the IO thread is valid.
24 class TestRequestInterceptor {
25 public:
26 // A callback that returns a new URLRequestJob given a URLRequest.
27 // This is used to queue callbacks that will handle expected requests.
28 typedef base::Callback<
29 net::URLRequestJob*(net::URLRequest*, net::NetworkDelegate*)> JobCallback;
30
31 // Will intercept request to |hostname| made over HTTP.
32 explicit TestRequestInterceptor(const std::string& hostname);
33 virtual ~TestRequestInterceptor();
34
35 // Returns the number of pending callback jobs that haven't been used yet.
36 size_t GetPendingSize() const;
37
38 // Queues |callback| to handle a request to |hostname_|. Each callback is
39 // used only once, and in the order that they're pushed.
40 void PushJobCallback(const JobCallback& callback);
41
42 // Returns a JobCallback that will fail with the given network |error|.
43 static JobCallback ErrorJob(int error);
44
45 // Returns a JobCallback that will fail with HTTP 400 Bad Request.
46 static JobCallback BadRequestJob();
47
48 // Returns a JobCallback that will process a policy register request that
49 // should succeed. The request parameters are validated, and an appropriate
50 // response is sent back.
51 // If |expect_reregister| is true then the request must have the reregister
52 // flag set; otherwise the flag must be not set.
53 static JobCallback RegisterJob(bool expect_reregister);
54
55 private:
56 class Delegate;
57
58 const std::string hostname_;
59
60 // Owned by URLRequestFilter. This handle is valid on IO and only while the
61 // interceptor is valid.
62 Delegate* delegate_;
63
64 DISALLOW_COPY_AND_ASSIGN(TestRequestInterceptor);
65 };
66
67 } // namespace policy
68
69 #endif // CHROME_BROWSER_POLICY_TEST_REQUEST_INTERCEPTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698