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

Side by Side Diff: chrome/browser/policy/testing_policy_url_fetcher_factory.cc

Issue 8416020: Handle additional feedback from http://codereview.chromium.org/8395038/. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "googleurl/src/gurl.h" 9 #include "googleurl/src/gurl.h"
10 #include "googleurl/src/url_parse.h" 10 #include "googleurl/src/url_parse.h"
(...skipping 21 matching lines...) Expand all
32 } // namespace 32 } // namespace
33 33
34 namespace policy { 34 namespace policy {
35 35
36 // An URLFetcher that calls back to its factory to figure out what to respond. 36 // An URLFetcher that calls back to its factory to figure out what to respond.
37 class TestingPolicyURLFetcher : public TestURLFetcher { 37 class TestingPolicyURLFetcher : public TestURLFetcher {
38 public: 38 public:
39 TestingPolicyURLFetcher( 39 TestingPolicyURLFetcher(
40 const base::WeakPtr<TestingPolicyURLFetcherFactory>& parent, 40 const base::WeakPtr<TestingPolicyURLFetcherFactory>& parent,
41 const GURL& url, 41 const GURL& url,
42 content::URLFetcher::RequestType request_type,
43 content::URLFetcherDelegate* delegate); 42 content::URLFetcherDelegate* delegate);
44 43
45 virtual void Start() OVERRIDE; 44 virtual void Start() OVERRIDE;
46 void Respond(); 45 void Respond();
47 46
48 virtual int GetResponseCode() const OVERRIDE { 47 virtual int GetResponseCode() const OVERRIDE {
49 return response_.response_code; 48 return response_.response_code;
50 } 49 }
51 50
52 virtual bool GetResponseAsString( 51 virtual bool GetResponseAsString(
53 std::string* out_response_string) const OVERRIDE { 52 std::string* out_response_string) const OVERRIDE {
54 *out_response_string = response_.response_data; 53 *out_response_string = response_.response_data;
55 return true; 54 return true;
56 } 55 }
57 56
58 private: 57 private:
59 TestURLResponse response_; 58 TestURLResponse response_;
60 base::WeakPtr<TestingPolicyURLFetcherFactory> parent_; 59 base::WeakPtr<TestingPolicyURLFetcherFactory> parent_;
61 60
62 DISALLOW_COPY_AND_ASSIGN(TestingPolicyURLFetcher); 61 DISALLOW_COPY_AND_ASSIGN(TestingPolicyURLFetcher);
63 }; 62 };
64 63
65 TestingPolicyURLFetcher::TestingPolicyURLFetcher( 64 TestingPolicyURLFetcher::TestingPolicyURLFetcher(
66 const base::WeakPtr<TestingPolicyURLFetcherFactory>& parent, 65 const base::WeakPtr<TestingPolicyURLFetcherFactory>& parent,
67 const GURL& url, 66 const GURL& url,
68 content::URLFetcher::RequestType request_type,
69 content::URLFetcherDelegate* delegate) 67 content::URLFetcherDelegate* delegate)
70 : TestURLFetcher(0, url, request_type, delegate), 68 : TestURLFetcher(0, url, delegate),
71 parent_(parent) { 69 parent_(parent) {
72 set_url(url); 70 set_url(url);
73 set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0)); 71 set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0));
74 } 72 }
75 73
76 void TestingPolicyURLFetcher::Start() { 74 void TestingPolicyURLFetcher::Start() {
77 if (!parent_.get()) return; 75 if (!parent_.get()) return;
78 76
79 std::string auth_header; 77 std::string auth_header;
80 net::HttpRequestHeaders headers; 78 net::HttpRequestHeaders headers;
81 std::string request = GetRequestType(GetUrl()); 79 std::string request = GetRequestType(GetURL());
82 GetExtraRequestHeaders(&headers); 80 GetExtraRequestHeaders(&headers);
83 headers.GetHeader("Authorization", &auth_header); 81 headers.GetHeader("Authorization", &auth_header);
84 // The following method is mocked by the currently running test. 82 // The following method is mocked by the currently running test.
85 parent_->GetResponse(auth_header, request, &response_); 83 parent_->GetResponse(auth_header, request, &response_);
86 84
87 // We need to channel this through the central event logger, so that ordering 85 // We need to channel this through the central event logger, so that ordering
88 // with other logged tasks that have a delay is preserved. 86 // with other logged tasks that have a delay is preserved.
89 parent_->scheduler()->PostDelayedWork( 87 parent_->scheduler()->PostDelayedWork(
90 base::Bind(&TestingPolicyURLFetcher::Respond, base::Unretained(this)), 88 base::Bind(&TestingPolicyURLFetcher::Respond, base::Unretained(this)),
91 0); 89 0);
(...skipping 25 matching lines...) Expand all
117 logger_->RegisterEvent(); 115 logger_->RegisterEvent();
118 Intercept(auth_header, request, response); 116 Intercept(auth_header, request, response);
119 } 117 }
120 118
121 content::URLFetcher* TestingPolicyURLFetcherFactory::CreateURLFetcher( 119 content::URLFetcher* TestingPolicyURLFetcherFactory::CreateURLFetcher(
122 int id, 120 int id,
123 const GURL& url, 121 const GURL& url,
124 content::URLFetcher::RequestType request_type, 122 content::URLFetcher::RequestType request_type,
125 content::URLFetcherDelegate* delegate) { 123 content::URLFetcherDelegate* delegate) {
126 return new TestingPolicyURLFetcher( 124 return new TestingPolicyURLFetcher(
127 weak_ptr_factory_.GetWeakPtr(), url, request_type, delegate); 125 weak_ptr_factory_.GetWeakPtr(), url, delegate);
128 } 126 }
129 127
130 } // namespace policy 128 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698