OLD | NEW |
---|---|
1 // Copyright (c) 2012 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/service/cloud_print/cloud_print_url_fetcher.h" | 5 #include "chrome/service/cloud_print/cloud_print_url_fetcher.h" |
6 | 6 |
7 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/common/cloud_print/cloud_print_constants.h" | 9 #include "chrome/common/cloud_print/cloud_print_constants.h" |
10 #include "chrome/common/cloud_print/cloud_print_helpers.h" | 10 #include "chrome/common/cloud_print/cloud_print_helpers.h" |
11 #include "chrome/service/cloud_print/cloud_print_helpers.h" | 11 #include "chrome/service/cloud_print/cloud_print_helpers.h" |
12 #include "chrome/service/cloud_print/cloud_print_token_store.h" | 12 #include "chrome/service/cloud_print/cloud_print_token_store.h" |
13 #include "chrome/service/net/service_url_request_context.h" | 13 #include "chrome/service/net/service_url_request_context.h" |
14 #include "chrome/service/service_process.h" | 14 #include "chrome/service/service_process.h" |
15 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
16 #include "net/base/load_flags.h" | 16 #include "net/base/load_flags.h" |
17 #include "net/http/http_status_code.h" | 17 #include "net/http/http_status_code.h" |
18 #include "net/url_request/url_fetcher.h" | 18 #include "net/url_request/url_fetcher.h" |
19 #include "net/url_request/url_request_status.h" | 19 #include "net/url_request/url_request_status.h" |
20 | 20 |
21 namespace cloud_print { | 21 namespace cloud_print { |
22 | 22 |
23 static CloudPrintURLFetcherFactory* g_factory = NULL; | |
24 | |
25 // static | |
26 CloudPrintURLFetcher* CloudPrintURLFetcher::Create() { | |
27 CloudPrintURLFetcherFactory* factory = CloudPrintURLFetcher::factory(); | |
28 return factory ? factory->CreateCloudPrintURLFetcher() : | |
29 new CloudPrintURLFetcher; | |
30 } | |
31 | |
32 // static | |
33 CloudPrintURLFetcherFactory* CloudPrintURLFetcher::factory() { | |
34 return g_factory; | |
35 } | |
36 | |
37 // static | |
38 void CloudPrintURLFetcher::set_factory( | |
gene
2013/02/11 23:34:05
Does this fit on one line?
| |
39 CloudPrintURLFetcherFactory* factory) { | |
40 g_factory = factory; | |
41 } | |
42 | |
43 | |
44 CloudPrintURLFetcherFactory::CloudPrintURLFetcherFactory() { | |
gene
2013/02/11 23:34:05
Can we omit constructor/destructor here, and have
| |
45 CloudPrintURLFetcher::set_factory(this); | |
46 } | |
47 | |
48 CloudPrintURLFetcherFactory::~CloudPrintURLFetcherFactory() { | |
49 CloudPrintURLFetcher::set_factory(NULL); | |
50 } | |
51 | |
52 | |
23 CloudPrintURLFetcher::ResponseAction | 53 CloudPrintURLFetcher::ResponseAction |
24 CloudPrintURLFetcher::Delegate::HandleRawResponse( | 54 CloudPrintURLFetcher::Delegate::HandleRawResponse( |
25 const net::URLFetcher* source, | 55 const net::URLFetcher* source, |
26 const GURL& url, | 56 const GURL& url, |
27 const net::URLRequestStatus& status, | 57 const net::URLRequestStatus& status, |
28 int response_code, | 58 int response_code, |
29 const net::ResponseCookies& cookies, | 59 const net::ResponseCookies& cookies, |
30 const std::string& data) { | 60 const std::string& data) { |
31 return CONTINUE_PROCESSING; | 61 return CONTINUE_PROCESSING; |
32 } | 62 } |
(...skipping 13 matching lines...) Expand all Loading... | |
46 base::DictionaryValue* json_data, | 76 base::DictionaryValue* json_data, |
47 bool succeeded) { | 77 bool succeeded) { |
48 return CONTINUE_PROCESSING; | 78 return CONTINUE_PROCESSING; |
49 } | 79 } |
50 | 80 |
51 CloudPrintURLFetcher::CloudPrintURLFetcher() | 81 CloudPrintURLFetcher::CloudPrintURLFetcher() |
52 : delegate_(NULL), | 82 : delegate_(NULL), |
53 num_retries_(0) { | 83 num_retries_(0) { |
54 } | 84 } |
55 | 85 |
56 bool CloudPrintURLFetcher::IsSameRequest(const net::URLFetcher* source) { | 86 bool CloudPrintURLFetcher::IsSameRequest( |
gene
2013/02/11 23:34:05
This should fit on one line.
| |
87 const net::URLFetcher* source) { | |
57 return (request_.get() == source); | 88 return (request_.get() == source); |
58 } | 89 } |
59 | 90 |
60 void CloudPrintURLFetcher::StartGetRequest( | 91 void CloudPrintURLFetcher::StartGetRequest( |
61 const GURL& url, | 92 const GURL& url, |
62 Delegate* delegate, | 93 Delegate* delegate, |
63 int max_retries, | 94 int max_retries, |
64 const std::string& additional_headers) { | 95 const std::string& additional_headers) { |
65 StartRequestHelper(url, | 96 StartRequestHelper(url, |
66 net::URLFetcher::GET, | 97 net::URLFetcher::GET, |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
208 ServiceURLRequestContextGetter* getter = | 239 ServiceURLRequestContextGetter* getter = |
209 g_service_process->GetServiceURLRequestContextGetter(); | 240 g_service_process->GetServiceURLRequestContextGetter(); |
210 // Now set up the user agent for cloudprint. | 241 // Now set up the user agent for cloudprint. |
211 std::string user_agent = getter->user_agent(); | 242 std::string user_agent = getter->user_agent(); |
212 base::StringAppendF(&user_agent, " %s", kCloudPrintUserAgent); | 243 base::StringAppendF(&user_agent, " %s", kCloudPrintUserAgent); |
213 getter->set_user_agent(user_agent); | 244 getter->set_user_agent(user_agent); |
214 return getter; | 245 return getter; |
215 } | 246 } |
216 | 247 |
217 } // namespace cloud_print | 248 } // namespace cloud_print |
OLD | NEW |