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/browser/extensions/app_notify_channel_setup.h" | 5 #include "chrome/browser/extensions/app_notify_channel_setup.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
28 #include "content/public/common/url_fetcher.h" | 28 #include "content/public/common/url_fetcher.h" |
29 #include "net/base/escape.h" | 29 #include "net/base/escape.h" |
30 #include "net/base/load_flags.h" | 30 #include "net/base/load_flags.h" |
31 #include "net/http/http_request_headers.h" | 31 #include "net/http/http_request_headers.h" |
32 #include "net/http/http_status_code.h" | 32 #include "net/http/http_status_code.h" |
33 #include "net/url_request/url_request_status.h" | 33 #include "net/url_request/url_request_status.h" |
34 | 34 |
35 using base::StringPrintf; | 35 using base::StringPrintf; |
36 using content::BrowserThread; | 36 using content::BrowserThread; |
37 using content::URLFetcher; | 37 using net::URLFetcher; |
38 | 38 |
39 namespace { | 39 namespace { |
40 | 40 |
41 static const char kChannelSetupAuthError[] = "unauthorized"; | 41 static const char kChannelSetupAuthError[] = "unauthorized"; |
42 static const char kChannelSetupInternalError[] = "internal_error"; | 42 static const char kChannelSetupInternalError[] = "internal_error"; |
43 static const char kChannelSetupCanceledByUser[] = "canceled_by_user"; | 43 static const char kChannelSetupCanceledByUser[] = "canceled_by_user"; |
44 static const char kAuthorizationHeaderFormat[] = | 44 static const char kAuthorizationHeaderFormat[] = |
45 "Authorization: Bearer %s"; | 45 "Authorization: Bearer %s"; |
46 static const char kOAuth2IssueTokenURL[] = | 46 static const char kOAuth2IssueTokenURL[] = |
47 "https://www.googleapis.com/oauth2/v2/IssueToken"; | 47 "https://www.googleapis.com/oauth2/v2/IssueToken"; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 break; | 140 break; |
141 } | 141 } |
142 } | 142 } |
143 | 143 |
144 // The contents of |body| should be URL-encoded as appropriate. | 144 // The contents of |body| should be URL-encoded as appropriate. |
145 URLFetcher* AppNotifyChannelSetup::CreateURLFetcher( | 145 URLFetcher* AppNotifyChannelSetup::CreateURLFetcher( |
146 const GURL& url, const std::string& body, const std::string& auth_token) { | 146 const GURL& url, const std::string& body, const std::string& auth_token) { |
147 CHECK(url.is_valid()); | 147 CHECK(url.is_valid()); |
148 URLFetcher::RequestType type = | 148 URLFetcher::RequestType type = |
149 body.empty() ? URLFetcher::GET : URLFetcher::POST; | 149 body.empty() ? URLFetcher::GET : URLFetcher::POST; |
150 URLFetcher* fetcher = URLFetcher::Create(0, url, type, this); | 150 URLFetcher* fetcher = content::URLFetcher::Create(0, url, type, this); |
151 fetcher->SetRequestContext(profile_->GetRequestContext()); | 151 fetcher->SetRequestContext(profile_->GetRequestContext()); |
152 // Always set flags to neither send nor save cookies. | 152 // Always set flags to neither send nor save cookies. |
153 fetcher->SetLoadFlags( | 153 fetcher->SetLoadFlags( |
154 net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES); | 154 net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES); |
155 fetcher->SetExtraRequestHeaders(MakeAuthorizationHeader(auth_token)); | 155 fetcher->SetExtraRequestHeaders(MakeAuthorizationHeader(auth_token)); |
156 if (!body.empty()) { | 156 if (!body.empty()) { |
157 fetcher->SetUploadData("application/x-www-form-urlencoded", body); | 157 fetcher->SetUploadData("application/x-www-form-urlencoded", body); |
158 } | 158 } |
159 return fetcher; | 159 return fetcher; |
160 } | 160 } |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); | 410 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); |
411 if (!dict->Get("id", &channel_id_value)) | 411 if (!dict->Get("id", &channel_id_value)) |
412 return false; | 412 return false; |
413 if (channel_id_value->GetType() != base::Value::TYPE_STRING) | 413 if (channel_id_value->GetType() != base::Value::TYPE_STRING) |
414 return false; | 414 return false; |
415 | 415 |
416 StringValue* channel_id = static_cast<StringValue*>(channel_id_value); | 416 StringValue* channel_id = static_cast<StringValue*>(channel_id_value); |
417 channel_id->GetAsString(result); | 417 channel_id->GetAsString(result); |
418 return true; | 418 return true; |
419 } | 419 } |
OLD | NEW |