OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/api/gcd_private/privet_v3_session.h" | 5 #include "chrome/browser/extensions/api/gcd_private/privet_v3_session.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 return false; | 79 return false; |
80 | 80 |
81 for (const base::Value* value : *list_of_string) { | 81 for (const base::Value* value : *list_of_string) { |
82 std::string string_value; | 82 std::string string_value; |
83 if (value->GetAsString(&string_value) && string_value == expected_value) | 83 if (value->GetAsString(&string_value) && string_value == expected_value) |
84 return true; | 84 return true; |
85 } | 85 } |
86 return false; | 86 return false; |
87 } | 87 } |
88 | 88 |
89 scoped_ptr<base::DictionaryValue> GetJson(const net::URLFetcher* source) { | 89 std::unique_ptr<base::DictionaryValue> GetJson(const net::URLFetcher* source) { |
90 if (!source->GetStatus().is_success()) | 90 if (!source->GetStatus().is_success()) |
91 return nullptr; | 91 return nullptr; |
92 | 92 |
93 const net::HttpResponseHeaders* headers = source->GetResponseHeaders(); | 93 const net::HttpResponseHeaders* headers = source->GetResponseHeaders(); |
94 if (!headers) | 94 if (!headers) |
95 return nullptr; | 95 return nullptr; |
96 | 96 |
97 std::string content_type; | 97 std::string content_type; |
98 if (!headers->GetMimeType(&content_type)) | 98 if (!headers->GetMimeType(&content_type)) |
99 return nullptr; | 99 return nullptr; |
(...skipping 21 matching lines...) Expand all Loading... |
121 void OnURLFetchComplete(const net::URLFetcher* source) override; | 121 void OnURLFetchComplete(const net::URLFetcher* source) override; |
122 | 122 |
123 net::URLFetcher* CreateURLFetcher(const GURL& url, | 123 net::URLFetcher* CreateURLFetcher(const GURL& url, |
124 net::URLFetcher::RequestType request_type, | 124 net::URLFetcher::RequestType request_type, |
125 bool orphaned); | 125 bool orphaned); |
126 | 126 |
127 private: | 127 private: |
128 void ReplyAndDestroyItself(Result result, const base::DictionaryValue& value); | 128 void ReplyAndDestroyItself(Result result, const base::DictionaryValue& value); |
129 void OnTimeout(); | 129 void OnTimeout(); |
130 | 130 |
131 scoped_ptr<net::URLFetcher> url_fetcher_; | 131 std::unique_ptr<net::URLFetcher> url_fetcher_; |
132 base::WeakPtr<PrivetV3Session> session_; | 132 base::WeakPtr<PrivetV3Session> session_; |
133 MessageCallback callback_; | 133 MessageCallback callback_; |
134 | 134 |
135 base::WeakPtrFactory<FetcherDelegate> weak_ptr_factory_; | 135 base::WeakPtrFactory<FetcherDelegate> weak_ptr_factory_; |
136 DISALLOW_COPY_AND_ASSIGN(FetcherDelegate); | 136 DISALLOW_COPY_AND_ASSIGN(FetcherDelegate); |
137 }; | 137 }; |
138 | 138 |
139 PrivetV3Session::FetcherDelegate::FetcherDelegate( | 139 PrivetV3Session::FetcherDelegate::FetcherDelegate( |
140 const base::WeakPtr<PrivetV3Session>& session, | 140 const base::WeakPtr<PrivetV3Session>& session, |
141 const PrivetV3Session::MessageCallback& callback) | 141 const PrivetV3Session::MessageCallback& callback) |
142 : session_(session), | 142 : session_(session), |
143 callback_(callback), | 143 callback_(callback), |
144 weak_ptr_factory_(this) {} | 144 weak_ptr_factory_(this) {} |
145 | 145 |
146 PrivetV3Session::FetcherDelegate::~FetcherDelegate() {} | 146 PrivetV3Session::FetcherDelegate::~FetcherDelegate() {} |
147 | 147 |
148 void PrivetV3Session::FetcherDelegate::OnURLFetchComplete( | 148 void PrivetV3Session::FetcherDelegate::OnURLFetchComplete( |
149 const net::URLFetcher* source) { | 149 const net::URLFetcher* source) { |
150 VLOG(1) << "PrivetURLFetcher url: " << source->GetURL() | 150 VLOG(1) << "PrivetURLFetcher url: " << source->GetURL() |
151 << ", status: " << source->GetStatus().status() | 151 << ", status: " << source->GetStatus().status() |
152 << ", error: " << source->GetStatus().error() | 152 << ", error: " << source->GetStatus().error() |
153 << ", response code: " << source->GetResponseCode(); | 153 << ", response code: " << source->GetResponseCode(); |
154 | 154 |
155 scoped_ptr<base::DictionaryValue> value = GetJson(source); | 155 std::unique_ptr<base::DictionaryValue> value = GetJson(source); |
156 if (!value) { | 156 if (!value) { |
157 return ReplyAndDestroyItself(Result::STATUS_CONNECTIONERROR, | 157 return ReplyAndDestroyItself(Result::STATUS_CONNECTIONERROR, |
158 base::DictionaryValue()); | 158 base::DictionaryValue()); |
159 } | 159 } |
160 | 160 |
161 bool has_error = value->HasKey(kPrivetV3KeyError); | 161 bool has_error = value->HasKey(kPrivetV3KeyError); |
162 LOG_IF(ERROR, has_error) << "Response: " << value.get(); | 162 LOG_IF(ERROR, has_error) << "Response: " << value.get(); |
163 ReplyAndDestroyItself( | 163 ReplyAndDestroyItself( |
164 has_error ? Result::STATUS_DEVICEERROR : Result::STATUS_SUCCESS, *value); | 164 has_error ? Result::STATUS_DEVICEERROR : Result::STATUS_SUCCESS, *value); |
165 } | 165 } |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 // Only session with pairing in process needs to be canceled. Paired sessions | 507 // Only session with pairing in process needs to be canceled. Paired sessions |
508 // (in https mode) does not need to be canceled. | 508 // (in https mode) does not need to be canceled. |
509 if (session_id_.empty() || use_https_) | 509 if (session_id_.empty() || use_https_) |
510 return; | 510 return; |
511 base::DictionaryValue input; | 511 base::DictionaryValue input; |
512 input.SetString(kPrivetV3KeySessionId, session_id_); | 512 input.SetString(kPrivetV3KeySessionId, session_id_); |
513 StartPostRequest(kPrivetV3PairingCancelPath, input, MessageCallback()); | 513 StartPostRequest(kPrivetV3PairingCancelPath, input, MessageCallback()); |
514 } | 514 } |
515 | 515 |
516 } // namespace extensions | 516 } // namespace extensions |
OLD | NEW |