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

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

Issue 879233003: Initial RemoteCommandService (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remote-commands
Patch Set: WIP Created 5 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 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 CHROME_BROWSER_POLICY_CLOUD_TEST_REQUEST_INTERCEPTOR_H_ 5 #ifndef CHROME_BROWSER_POLICY_CLOUD_TEST_REQUEST_INTERCEPTOR_H_
6 #define CHROME_BROWSER_POLICY_CLOUD_TEST_REQUEST_INTERCEPTOR_H_ 6 #define CHROME_BROWSER_POLICY_CLOUD_TEST_REQUEST_INTERCEPTOR_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "policy/proto/device_management_backend.pb.h" 13 #include "policy/proto/device_management_backend.pb.h"
14 14
15 namespace base { 15 namespace base {
16 class FilePath; 16 class FilePath;
17 class SequencedTaskRunner; 17 class SequencedTaskRunner;
18 } 18 }
19 19
20 namespace net { 20 namespace net {
21 class NetworkDelegate; 21 class NetworkDelegate;
22 class URLRequest; 22 class URLRequest;
23 class URLRequestJob; 23 class URLRequestJob;
24 } 24 }
25 25
26 namespace policy { 26 namespace policy {
27 27
28 class TestingRemoteCommandsServer;
29
28 // Intercepts all requests to the given hostname while in scope, and allows 30 // Intercepts all requests to the given hostname while in scope, and allows
29 // queuing callbacks to handle expected requests. Must be created and destroyed 31 // queuing callbacks to handle expected requests. Must be created and destroyed
30 // while the IO thread is valid. 32 // while the IO thread is valid.
31 class TestRequestInterceptor { 33 class TestRequestInterceptor {
32 public: 34 public:
33 // A callback that returns a new URLRequestJob given a URLRequest. 35 // A callback that returns a new URLRequestJob given a URLRequest.
34 // This is used to queue callbacks that will handle expected requests. 36 // This is used to queue callbacks that will handle expected requests.
37 // If a null URLRequestJob is returned by this callback, it indicates that
bartfab (slow) 2015/02/12 14:29:17 The grammar is a bit off in this comment, but that
binjin 2015/02/16 22:46:22 It's not for out of order packets. It's meant to i
bartfab (slow) 2015/02/17 18:13:52 If the order in which requests arrive is well-defi
binjin 2015/02/18 15:37:48 I don't want to handle certain request (policy req
38 // the request is legal but not expected be intercepted by current JobCallback
39 // , thus it will be ignored and BadRequestJob will be used instead for
40 // current request. In the other hand, the current JobCallback will continue
41 // to live in the queue to service future request job.
35 typedef base::Callback< 42 typedef base::Callback<
36 net::URLRequestJob*(net::URLRequest*, net::NetworkDelegate*)> JobCallback; 43 net::URLRequestJob*(net::URLRequest*, net::NetworkDelegate*)> JobCallback;
37 44
38 // Will intercept request to |hostname| made over HTTP. 45 // Will intercept request to |hostname| made over HTTP.
39 TestRequestInterceptor( 46 TestRequestInterceptor(
40 const std::string& hostname, 47 const std::string& hostname,
41 scoped_refptr<base::SequencedTaskRunner> io_task_runner); 48 scoped_refptr<base::SequencedTaskRunner> io_task_runner);
42 virtual ~TestRequestInterceptor(); 49 virtual ~TestRequestInterceptor();
43 50
44 // Returns the number of pending callback jobs that haven't been used yet. 51 // Returns the number of pending callback jobs that haven't been used yet.
(...skipping 19 matching lines...) Expand all
64 // |expected_type| is the expected type in the register request. 71 // |expected_type| is the expected type in the register request.
65 // If |expect_reregister| is true then the request must have the reregister 72 // If |expect_reregister| is true then the request must have the reregister
66 // flag set; otherwise the flag must be not set. 73 // flag set; otherwise the flag must be not set.
67 static JobCallback RegisterJob( 74 static JobCallback RegisterJob(
68 enterprise_management::DeviceRegisterRequest::Type expected_type, 75 enterprise_management::DeviceRegisterRequest::Type expected_type,
69 bool expect_reregister); 76 bool expect_reregister);
70 77
71 // Returns a JobCallback that will send the contents of |file_path|. 78 // Returns a JobCallback that will send the contents of |file_path|.
72 static JobCallback FileJob(const base::FilePath& file_path); 79 static JobCallback FileJob(const base::FilePath& file_path);
73 80
81 // XXX
82 static JobCallback FetchRemoteCommandsJob(TestingRemoteCommandsServer* server,
83 bool ignore_other_requests);
84
74 private: 85 private:
75 class Delegate; 86 class Delegate;
76 87
77 // Helper to execute a |task| on IO, and return only after it has completed. 88 // Helper to execute a |task| on IO, and return only after it has completed.
78 void PostToIOAndWait(const base::Closure& task); 89 void PostToIOAndWait(const base::Closure& task);
79 90
80 const std::string hostname_; 91 const std::string hostname_;
81 92
82 scoped_refptr<base::SequencedTaskRunner> io_task_runner_; 93 scoped_refptr<base::SequencedTaskRunner> io_task_runner_;
83 94
84 // Owned by URLRequestFilter. This handle is valid on IO and only while the 95 // Owned by URLRequestFilter. This handle is valid on IO and only while the
85 // interceptor is valid. 96 // interceptor is valid.
86 Delegate* delegate_; 97 Delegate* delegate_;
87 98
88 DISALLOW_COPY_AND_ASSIGN(TestRequestInterceptor); 99 DISALLOW_COPY_AND_ASSIGN(TestRequestInterceptor);
89 }; 100 };
90 101
91 } // namespace policy 102 } // namespace policy
92 103
93 #endif // CHROME_BROWSER_POLICY_CLOUD_TEST_REQUEST_INTERCEPTOR_H_ 104 #endif // CHROME_BROWSER_POLICY_CLOUD_TEST_REQUEST_INTERCEPTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698