| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/policy/testing_policy_url_fetcher_factory.h" | 5 #include "chrome/browser/policy/testing_policy_url_fetcher_factory.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "chrome/browser/policy/logging_work_scheduler.h" | 8 #include "chrome/browser/policy/logging_work_scheduler.h" |
| 9 #include "chrome/browser/policy/proto/device_management_backend.pb.h" | 9 #include "chrome/browser/policy/proto/device_management_backend.pb.h" |
| 10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
| 11 #include "googleurl/src/url_parse.h" | 11 #include "googleurl/src/url_parse.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 33 } // namespace | 33 } // namespace |
| 34 | 34 |
| 35 namespace policy { | 35 namespace policy { |
| 36 | 36 |
| 37 // An URLFetcher that calls back to its factory to figure out what to respond. | 37 // An URLFetcher that calls back to its factory to figure out what to respond. |
| 38 class TestingPolicyURLFetcher : public TestURLFetcher { | 38 class TestingPolicyURLFetcher : public TestURLFetcher { |
| 39 public: | 39 public: |
| 40 TestingPolicyURLFetcher( | 40 TestingPolicyURLFetcher( |
| 41 const base::WeakPtr<TestingPolicyURLFetcherFactory>& parent, | 41 const base::WeakPtr<TestingPolicyURLFetcherFactory>& parent, |
| 42 const GURL& url, | 42 const GURL& url, |
| 43 content::URLFetcherDelegate* delegate); | 43 net::URLFetcherDelegate* delegate); |
| 44 | 44 |
| 45 virtual void Start() OVERRIDE; | 45 virtual void Start() OVERRIDE; |
| 46 void Respond(); | 46 void Respond(); |
| 47 | 47 |
| 48 virtual int GetResponseCode() const OVERRIDE { | 48 virtual int GetResponseCode() const OVERRIDE { |
| 49 return response_.response_code; | 49 return response_.response_code; |
| 50 } | 50 } |
| 51 | 51 |
| 52 virtual bool GetResponseAsString( | 52 virtual bool GetResponseAsString( |
| 53 std::string* out_response_string) const OVERRIDE { | 53 std::string* out_response_string) const OVERRIDE { |
| 54 *out_response_string = response_.response_data; | 54 *out_response_string = response_.response_data; |
| 55 return true; | 55 return true; |
| 56 } | 56 } |
| 57 | 57 |
| 58 private: | 58 private: |
| 59 TestURLResponse response_; | 59 TestURLResponse response_; |
| 60 base::WeakPtr<TestingPolicyURLFetcherFactory> parent_; | 60 base::WeakPtr<TestingPolicyURLFetcherFactory> parent_; |
| 61 | 61 |
| 62 DISALLOW_COPY_AND_ASSIGN(TestingPolicyURLFetcher); | 62 DISALLOW_COPY_AND_ASSIGN(TestingPolicyURLFetcher); |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 TestingPolicyURLFetcher::TestingPolicyURLFetcher( | 65 TestingPolicyURLFetcher::TestingPolicyURLFetcher( |
| 66 const base::WeakPtr<TestingPolicyURLFetcherFactory>& parent, | 66 const base::WeakPtr<TestingPolicyURLFetcherFactory>& parent, |
| 67 const GURL& url, | 67 const GURL& url, |
| 68 content::URLFetcherDelegate* delegate) | 68 net::URLFetcherDelegate* delegate) |
| 69 : TestURLFetcher(0, url, delegate), | 69 : TestURLFetcher(0, url, delegate), |
| 70 parent_(parent) { | 70 parent_(parent) { |
| 71 set_url(url); | 71 set_url(url); |
| 72 set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0)); | 72 set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0)); |
| 73 } | 73 } |
| 74 | 74 |
| 75 void TestingPolicyURLFetcher::Start() { | 75 void TestingPolicyURLFetcher::Start() { |
| 76 if (!parent_.get()) return; | 76 if (!parent_.get()) return; |
| 77 | 77 |
| 78 std::string auth_header; | 78 std::string auth_header; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 const enterprise_management::DeviceManagementRequest& request, | 119 const enterprise_management::DeviceManagementRequest& request, |
| 120 TestURLResponse* response) { | 120 TestURLResponse* response) { |
| 121 logger_->RegisterEvent(); | 121 logger_->RegisterEvent(); |
| 122 Intercept(auth_header, request_type, request, response); | 122 Intercept(auth_header, request_type, request, response); |
| 123 } | 123 } |
| 124 | 124 |
| 125 content::URLFetcher* TestingPolicyURLFetcherFactory::CreateURLFetcher( | 125 content::URLFetcher* TestingPolicyURLFetcherFactory::CreateURLFetcher( |
| 126 int id, | 126 int id, |
| 127 const GURL& url, | 127 const GURL& url, |
| 128 content::URLFetcher::RequestType request_type, | 128 content::URLFetcher::RequestType request_type, |
| 129 content::URLFetcherDelegate* delegate) { | 129 net::URLFetcherDelegate* delegate) { |
| 130 return new TestingPolicyURLFetcher( | 130 return new TestingPolicyURLFetcher( |
| 131 weak_ptr_factory_.GetWeakPtr(), url, delegate); | 131 weak_ptr_factory_.GetWeakPtr(), url, delegate); |
| 132 } | 132 } |
| 133 | 133 |
| 134 } // namespace policy | 134 } // namespace policy |
| OLD | NEW |