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 18 matching lines...) Expand all Loading... |
29 #include "net/base/load_flags.h" | 29 #include "net/base/load_flags.h" |
30 #include "net/http/http_request_headers.h" | 30 #include "net/http/http_request_headers.h" |
31 #include "net/http/http_status_code.h" | 31 #include "net/http/http_status_code.h" |
32 #include "net/url_request/url_fetcher.h" | 32 #include "net/url_request/url_fetcher.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 net::URLFetcher; | 37 using net::URLFetcher; |
38 | 38 |
| 39 namespace extensions { |
| 40 |
39 namespace { | 41 namespace { |
40 | 42 |
41 static const char kChannelSetupAuthError[] = "unauthorized"; | 43 static const char kChannelSetupAuthError[] = "unauthorized"; |
42 static const char kChannelSetupInternalError[] = "internal_error"; | 44 static const char kChannelSetupInternalError[] = "internal_error"; |
43 static const char kChannelSetupCanceledByUser[] = "canceled_by_user"; | 45 static const char kChannelSetupCanceledByUser[] = "canceled_by_user"; |
44 static const char kAuthorizationHeaderFormat[] = | 46 static const char kAuthorizationHeaderFormat[] = |
45 "Authorization: Bearer %s"; | 47 "Authorization: Bearer %s"; |
46 static const char kOAuth2IssueTokenURL[] = | 48 static const char kOAuth2IssueTokenURL[] = |
47 "https://www.googleapis.com/oauth2/v2/IssueToken"; | 49 "https://www.googleapis.com/oauth2/v2/IssueToken"; |
48 static const char kOAuth2IssueTokenBodyFormat[] = | 50 static const char kOAuth2IssueTokenBodyFormat[] = |
49 "force=true" | 51 "force=true" |
50 "&response_type=token" | 52 "&response_type=token" |
51 "&scope=%s" | 53 "&scope=%s" |
52 "&client_id=%s" | 54 "&client_id=%s" |
53 "&origin=%s"; | 55 "&origin=%s"; |
54 static const char kOAuth2IssueTokenScope[] = | 56 static const char kOAuth2IssueTokenScope[] = |
55 "https://www.googleapis.com/auth/chromewebstore.notification"; | 57 "https://www.googleapis.com/auth/chromewebstore.notification"; |
56 static const char kCWSChannelServiceURL[] = | 58 static const char kCWSChannelServiceURL[] = |
57 "https://www.googleapis.com/chromewebstore/v1.1/channels/id"; | 59 "https://www.googleapis.com/chromewebstore/v1.1/channels/id"; |
58 | 60 |
59 static AppNotifyChannelSetup::InterceptorForTests* g_interceptor_for_tests = | 61 static AppNotifyChannelSetup::InterceptorForTests* |
60 NULL; | 62 g_interceptor_for_tests = NULL; |
61 | 63 |
62 } // namespace. | 64 } // namespace. |
63 | 65 |
64 // static | 66 // static |
65 void AppNotifyChannelSetup::SetInterceptorForTests( | 67 void AppNotifyChannelSetup::SetInterceptorForTests( |
66 AppNotifyChannelSetup::InterceptorForTests* interceptor) { | 68 AppNotifyChannelSetup::InterceptorForTests* interceptor) { |
67 // Only one interceptor at a time, please. | 69 // Only one interceptor at a time, please. |
68 CHECK(g_interceptor_for_tests == NULL); | 70 CHECK(g_interceptor_for_tests == NULL); |
69 g_interceptor_for_tests = interceptor; | 71 g_interceptor_for_tests = interceptor; |
70 } | 72 } |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 // static | 405 // static |
404 bool AppNotifyChannelSetup::ParseCWSChannelServiceResponse( | 406 bool AppNotifyChannelSetup::ParseCWSChannelServiceResponse( |
405 const std::string& data, std::string* result) { | 407 const std::string& data, std::string* result) { |
406 scoped_ptr<base::Value> value(base::JSONReader::Read(data)); | 408 scoped_ptr<base::Value> value(base::JSONReader::Read(data)); |
407 if (!value.get() || value->GetType() != base::Value::TYPE_DICTIONARY) | 409 if (!value.get() || value->GetType() != base::Value::TYPE_DICTIONARY) |
408 return false; | 410 return false; |
409 | 411 |
410 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); | 412 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); |
411 return dict->GetString("id", result); | 413 return dict->GetString("id", result); |
412 } | 414 } |
| 415 |
| 416 } // namespace extensions |
OLD | NEW |